From 062624b8148c4397531630c50a8647c28ec71c60 Mon Sep 17 00:00:00 2001 From: Dmitry Tomashevich <39378793+dimaanj@users.noreply.github.com> Date: Fri, 12 Aug 2022 12:04:26 +0300 Subject: [PATCH] [Discover] Update data view naming for locator (#138423) * [Discover] update data view naming for locator * [Discover] leave deprecated param * [Discover] add legacy param test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- src/plugins/discover/public/locator.test.ts | 22 ++++++++++++--------- src/plugins/discover/public/locator.ts | 7 +++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/plugins/discover/public/locator.test.ts b/src/plugins/discover/public/locator.test.ts index 98e0d7e853b61..274e339c91343 100644 --- a/src/plugins/discover/public/locator.test.ts +++ b/src/plugins/discover/public/locator.test.ts @@ -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({ @@ -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); }); @@ -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); @@ -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); @@ -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); diff --git a/src/plugins/discover/public/locator.ts b/src/plugins/discover/public/locator.ts index b7ca5d78e4ab7..0fa2195cc246f 100644 --- a/src/plugins/discover/public/locator.ts +++ b/src/plugins/discover/public/locator.ts @@ -24,6 +24,11 @@ export interface DiscoverAppLocatorParams extends SerializableRecord { /** * Optionally set index pattern / data view ID. */ + dataViewId?: string; + /** + * Duplication of dataViewId + * @deprecated + */ indexPatternId?: string; /** @@ -101,6 +106,7 @@ export class DiscoverAppLocatorDefinition implements LocatorDefinition !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;