Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Update data view naming for locator #138423

Merged
merged 5 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
dimaanj marked this conversation as resolved.
Show resolved Hide resolved
});
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