Skip to content

Commit

Permalink
[Discover] Update data view naming for locator (elastic#138423)
Browse files Browse the repository at this point in the history
* [Discover] update data view naming for locator

* [Discover] leave deprecated param

* [Discover] add legacy param test

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
2 people authored and Mpdreamz committed Sep 6, 2022
1 parent 461ac13 commit 062624b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/plugins/discover/public/locator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ describe('Discover url generator', () => {

test('can specify specific data view', async () => {
const { locator } = await setup();
const { path } = await locator.getLocation({
indexPatternId: dataViewId,
});
const { path } = await locator.getLocation({ dataViewId });
const { _a, _g } = getStatesFromKbnUrl(path, ['_a', '_g']);

expect(_a).toEqual({
Expand Down Expand Up @@ -224,13 +222,19 @@ describe('Discover url generator', () => {
);
});

test('should use legacy locator params', async () => {
const { locator } = await setup();
const { path } = await locator.getLocation({ dataViewId });
const { path: legacyParamsPath } = await locator.getLocation({ indexPatternId: dataViewId });

expect(path).toEqual(legacyParamsPath);
});

describe('useHash property', () => {
describe('when default useHash is set to false', () => {
test('when using default, sets data view ID in the generated URL', async () => {
const { locator } = await setup();
const { path } = await locator.getLocation({
indexPatternId: dataViewId,
});
const { path } = await locator.getLocation({ dataViewId });

expect(path.indexOf(dataViewId) > -1).toBe(true);
});
Expand All @@ -239,7 +243,7 @@ describe('Discover url generator', () => {
const { locator } = await setup();
const { path } = await locator.getLocation({
useHash: true,
indexPatternId: dataViewId,
dataViewId,
});

expect(path.indexOf(dataViewId) > -1).toBe(false);
Expand All @@ -250,7 +254,7 @@ describe('Discover url generator', () => {
test('when using default, does not set data view ID in the generated URL', async () => {
const { locator } = await setup({ useHash: true });
const { path } = await locator.getLocation({
indexPatternId: dataViewId,
dataViewId,
});

expect(path.indexOf(dataViewId) > -1).toBe(false);
Expand All @@ -260,7 +264,7 @@ describe('Discover url generator', () => {
const { locator } = await setup({ useHash: true });
const { path } = await locator.getLocation({
useHash: false,
indexPatternId: dataViewId,
dataViewId,
});

expect(path.indexOf(dataViewId) > -1).toBe(true);
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/discover/public/locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export interface DiscoverAppLocatorParams extends SerializableRecord {
/**
* Optionally set index pattern / data view ID.
*/
dataViewId?: string;
/**
* Duplication of dataViewId
* @deprecated
*/
indexPatternId?: string;

/**
Expand Down Expand Up @@ -101,6 +106,7 @@ export class DiscoverAppLocatorDefinition implements LocatorDefinition<DiscoverA
const {
useHash = this.deps.useHash,
filters,
dataViewId,
indexPatternId,
query,
refreshInterval,
Expand Down Expand Up @@ -132,6 +138,7 @@ export class DiscoverAppLocatorDefinition implements LocatorDefinition<DiscoverA
if (query) appState.query = query;
if (filters && filters.length) appState.filters = filters?.filter((f) => !isFilterPinned(f));
if (indexPatternId) appState.index = indexPatternId;
if (dataViewId) appState.index = dataViewId;
if (columns) appState.columns = columns;
if (savedQuery) appState.savedQuery = savedQuery;
if (sort) appState.sort = sort;
Expand Down

0 comments on commit 062624b

Please sign in to comment.