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

[Lens] Register saved object references #74523

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3ad79cd
clear out all attribute properties before updating
flash1293 Aug 6, 2020
94293c2
fix tests
flash1293 Aug 6, 2020
8e182aa
Merge remote-tracking branch 'upstream/master' into lens/fix-persiste…
flash1293 Aug 6, 2020
9f1bf89
Merge branch 'lens/fix-persistence-bug-72855' into lens/register-save…
flash1293 Aug 6, 2020
ff69693
start implementing saved object references
flash1293 Aug 6, 2020
a16dad9
implement some more things
flash1293 Aug 10, 2020
358659b
add reference stuff
flash1293 Aug 10, 2020
781488e
make references work everywhere
flash1293 Aug 11, 2020
0238da8
Merge remote-tracking branch 'upstream/master' into lens/register-sav…
flash1293 Aug 11, 2020
2f1c7cd
fix types and tests
flash1293 Aug 13, 2020
476b6d2
fix tests
flash1293 Aug 13, 2020
8f1b752
Merge remote-tracking branch 'upstream/master' into lens/register-sav…
flash1293 Aug 13, 2020
e82c1fa
fix tests
flash1293 Aug 14, 2020
c5066cd
Merge remote-tracking branch 'upstream/master' into lens/register-sav…
flash1293 Aug 14, 2020
0f54f77
Merge remote-tracking branch 'upstream/master' into lens/register-sav…
flash1293 Aug 14, 2020
660cfe8
do not show modal on global filters
flash1293 Aug 14, 2020
451fb87
fix on app leave condition
flash1293 Aug 17, 2020
6386be5
Merge remote-tracking branch 'upstream/master' into lens/register-sav…
flash1293 Aug 17, 2020
2e5d279
fix datatable test
flash1293 Aug 17, 2020
63c8183
Merge branch 'master' into lens/register-saved-object-references
elasticmachine Aug 19, 2020
02a1ca9
Merge remote-tracking branch 'upstream/master' into lens/register-sav…
flash1293 Aug 19, 2020
fdf6061
refactor
flash1293 Aug 20, 2020
a898781
Merge remote-tracking branch 'upstream/master' into lens/register-sav…
flash1293 Aug 20, 2020
a343e44
fix tests and types
flash1293 Aug 20, 2020
d6a2075
Merge remote-tracking branch 'upstream/master' into lens/register-sav…
flash1293 Aug 21, 2020
eacb355
remarks
flash1293 Aug 21, 2020
7017916
Merge remote-tracking branch 'upstream/master' into lens/register-sav…
flash1293 Aug 21, 2020
6e545ce
fix loader test
flash1293 Aug 21, 2020
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
10 changes: 10 additions & 0 deletions x-pack/plugins/lens/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { FilterMeta, Filter } from 'src/plugins/data/common';

export interface ExistingFields {
indexPatternTitle: string;
existingFieldNames: string[];
Expand All @@ -13,3 +15,11 @@ export interface DateRange {
fromDate: string;
toDate: string;
}

export interface PersistableFilterMeta extends FilterMeta {
indexRefName?: string;
}

export interface PersistableFilter extends Filter {
meta: PersistableFilterMeta;
}
133 changes: 82 additions & 51 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { navigationPluginMock } from '../../../../../src/plugins/navigation/publ
import { TopNavMenuData } from '../../../../../src/plugins/navigation/public';
import { coreMock } from 'src/core/public/mocks';

jest.mock('../persistence');
jest.mock('../editor_frame_service/editor_frame/expression_helpers');
jest.mock('src/core/public');
jest.mock('../../../../../src/plugins/saved_objects/public', () => {
// eslint-disable-next-line no-shadow
Expand Down Expand Up @@ -282,10 +282,10 @@ describe('Lens App', () => {
(defaultArgs.docStorage.load as jest.Mock).mockResolvedValue({
id: '1234',
title: 'Daaaaaaadaumching!',
expression: 'valid expression',
state: {
query: 'fake query',
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
filters: [],
datasourceMetaData: { numberFilterableIndexPatterns: 0 },
},
});
await act(async () => {
Expand All @@ -312,12 +312,12 @@ describe('Lens App', () => {
args.editorFrame = frame;
(args.docStorage.load as jest.Mock).mockResolvedValue({
id: '1234',
expression: 'valid expression',
state: {
query: 'fake query',
filters: [{ query: { match_phrase: { src: 'test' } } }],
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
datasourceMetaData: { numberFilterableIndexPatterns: 1 },
},
references: [{ type: 'index-pattern', id: '1', name: 'filterable-index-pattern-0' }],
});

instance = mount(<App {...args} />);
Expand All @@ -341,15 +341,14 @@ describe('Lens App', () => {
expect(frame.mount).toHaveBeenCalledWith(
expect.any(Element),
expect.objectContaining({
doc: {
doc: expect.objectContaining({
id: '1234',
expression: 'valid expression',
state: {
state: expect.objectContaining({
query: 'fake query',
filters: [{ query: { match_phrase: { src: 'test' } } }],
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
},
},
datasourceMetaData: { numberFilterableIndexPatterns: 1 },
}),
}),
})
);
});
Expand Down Expand Up @@ -433,7 +432,15 @@ describe('Lens App', () => {
}

async function save({
lastKnownDoc = { expression: 'kibana 3' },
lastKnownDoc = {
references: [],
state: {
filters: [],
datasourceMetaData: {
numberFilterableIndexPatterns: 0,
},
},
},
initialDocId,
...saveProps
}: SaveProps & {
Expand All @@ -447,16 +454,15 @@ describe('Lens App', () => {
args.editorFrame = frame;
(args.docStorage.load as jest.Mock).mockResolvedValue({
id: '1234',
expression: 'kibana',
references: [],
state: {
query: 'fake query',
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
datasourceMetaData: { numberFilterableIndexPatterns: 0 },
filters: [],
},
});
(args.docStorage.save as jest.Mock).mockImplementation(async ({ id }) => ({
id: id || 'aaa',
expression: 'kibana 2',
}));

await act(async () => {
Expand All @@ -474,6 +480,7 @@ describe('Lens App', () => {
onChange({
filterableIndexPatterns: [],
doc: { id: initialDocId, ...lastKnownDoc } as Document,
isSaveable: true,
})
);

Expand Down Expand Up @@ -507,7 +514,8 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: 'will save this', expression: 'valid expression' } as unknown) as Document,
doc: ({ id: 'will save this' } as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand All @@ -526,7 +534,8 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: 'will save this', expression: 'valid expression' } as unknown) as Document,
doc: ({ id: 'will save this' } as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand All @@ -541,11 +550,12 @@ describe('Lens App', () => {
newTitle: 'hello there',
});

expect(args.docStorage.save).toHaveBeenCalledWith({
id: undefined,
title: 'hello there',
expression: 'kibana 3',
});
expect(args.docStorage.save).toHaveBeenCalledWith(
expect.objectContaining({
id: undefined,
title: 'hello there',
})
);

expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined, true);

Expand All @@ -561,11 +571,12 @@ describe('Lens App', () => {
newTitle: 'hello there',
});

expect(args.docStorage.save).toHaveBeenCalledWith({
id: undefined,
title: 'hello there',
expression: 'kibana 3',
});
expect(args.docStorage.save).toHaveBeenCalledWith(
expect.objectContaining({
id: undefined,
title: 'hello there',
})
);

expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined, true);

Expand All @@ -581,11 +592,12 @@ describe('Lens App', () => {
newTitle: 'hello there',
});

expect(args.docStorage.save).toHaveBeenCalledWith({
id: '1234',
title: 'hello there',
expression: 'kibana 3',
});
expect(args.docStorage.save).toHaveBeenCalledWith(
expect.objectContaining({
id: '1234',
title: 'hello there',
})
);

expect(args.redirectTo).not.toHaveBeenCalled();

Expand All @@ -605,7 +617,8 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: undefined, expression: 'new expression' } as unknown) as Document,
doc: ({ id: undefined } as unknown) as Document,
isSaveable: true,
})
);

Expand All @@ -629,11 +642,12 @@ describe('Lens App', () => {
newTitle: 'hello there',
});

expect(args.docStorage.save).toHaveBeenCalledWith({
expression: 'kibana 3',
id: undefined,
title: 'hello there',
});
expect(args.docStorage.save).toHaveBeenCalledWith(
expect.objectContaining({
id: undefined,
title: 'hello there',
})
);

expect(args.redirectTo).toHaveBeenCalledWith('aaa', true, true);
});
Expand Down Expand Up @@ -683,7 +697,8 @@ describe('Lens App', () => {
await act(async () =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: '123', expression: 'valid expression' } as unknown) as Document,
doc: ({ id: '123' } as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand Down Expand Up @@ -722,7 +737,8 @@ describe('Lens App', () => {
await act(async () =>
onChange({
filterableIndexPatterns: [],
doc: ({ expression: 'valid expression' } as unknown) as Document,
doc: ({} as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand Down Expand Up @@ -790,8 +806,9 @@ describe('Lens App', () => {

await act(async () => {
onChange({
filterableIndexPatterns: [{ id: '1', title: 'newIndex' }],
doc: ({ id: undefined, expression: 'valid expression' } as unknown) as Document,
filterableIndexPatterns: ['1'],
doc: ({ id: undefined } as unknown) as Document,
isSaveable: true,
});
});

Expand All @@ -808,8 +825,9 @@ describe('Lens App', () => {

await act(async () => {
onChange({
filterableIndexPatterns: [{ id: '2', title: 'second index' }],
doc: ({ id: undefined, expression: 'valid expression' } as unknown) as Document,
filterableIndexPatterns: ['2'],
doc: ({ id: undefined } as unknown) as Document,
isSaveable: true,
});
});

Expand Down Expand Up @@ -1044,10 +1062,10 @@ describe('Lens App', () => {
(defaultArgs.docStorage.load as jest.Mock).mockResolvedValue({
id: '1234',
title: 'My cool doc',
expression: 'valid expression',
state: {
query: 'kuery',
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
filters: [],
datasourceMetaData: { numberFilterableIndexPatterns: 0 },
},
} as jest.ResolvedValue<Document>);
});
Expand Down Expand Up @@ -1080,7 +1098,8 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: undefined, expression: 'valid expression' } as unknown) as Document,
doc: ({ id: undefined } as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand All @@ -1101,7 +1120,8 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: undefined, expression: 'valid expression' } as unknown) as Document,
doc: ({ id: undefined, state: {} } as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand All @@ -1125,7 +1145,8 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: '1234', expression: 'different expression' } as unknown) as Document,
doc: ({ id: '1234' } as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand All @@ -1149,7 +1170,16 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: '1234', expression: 'valid expression' } as unknown) as Document,
doc: ({
id: '1234',
title: 'My cool doc',
state: {
query: 'kuery',
filters: [],
datasourceMetaData: { numberFilterableIndexPatterns: 0 },
},
} as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand All @@ -1173,7 +1203,8 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: '1234', expression: null } as unknown) as Document,
doc: ({ id: '1234' } as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand Down
Loading