Skip to content

Commit

Permalink
[Lens] Register saved object references (#74523)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Aug 21, 2020
1 parent 471b114 commit 86f73cb
Show file tree
Hide file tree
Showing 51 changed files with 1,609 additions and 659 deletions.
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;
}
137 changes: 84 additions & 53 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 @@ -284,11 +284,11 @@ 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: [],
},
references: [],
});
await act(async () => {
instance.setProps({ docId: '1234' });
Expand Down Expand Up @@ -346,12 +346,11 @@ 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' }] },
},
references: [{ type: 'index-pattern', id: '1', name: 'index-pattern-0' }],
});

instance = mount(<App {...args} />);
Expand All @@ -375,15 +374,13 @@ 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' }] },
},
},
}),
}),
})
);
});
Expand Down Expand Up @@ -444,7 +441,6 @@ describe('Lens App', () => {
expression: 'valid expression',
state: {
query: 'kuery',
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
},
} as jest.ResolvedValue<Document>);
});
Expand All @@ -467,7 +463,12 @@ describe('Lens App', () => {
}

async function save({
lastKnownDoc = { expression: 'kibana 3' },
lastKnownDoc = {
references: [],
state: {
filters: [],
},
},
initialDocId,
...saveProps
}: SaveProps & {
Expand All @@ -481,16 +482,14 @@ 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' }] },
filters: [],
},
});
(args.docStorage.save as jest.Mock).mockImplementation(async ({ id }) => ({
id: id || 'aaa',
expression: 'kibana 2',
}));

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

Expand Down Expand Up @@ -541,7 +541,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 @@ -560,7 +561,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 @@ -575,11 +577,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 @@ -595,11 +598,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 @@ -615,11 +619,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 @@ -639,7 +644,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 @@ -663,11 +669,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 @@ -717,7 +724,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 @@ -756,7 +764,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 All @@ -779,7 +788,6 @@ describe('Lens App', () => {
expression: 'valid expression',
state: {
query: 'kuery',
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
},
} as jest.ResolvedValue<Document>);
});
Expand Down Expand Up @@ -824,8 +832,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 @@ -842,8 +851,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 @@ -1078,11 +1088,11 @@ 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: [],
},
references: [],
} as jest.ResolvedValue<Document>);
});

Expand Down Expand Up @@ -1114,7 +1124,12 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: undefined, expression: 'valid expression' } as unknown) as Document,
doc: ({
id: undefined,

references: [],
} as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand All @@ -1135,7 +1150,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 @@ -1159,7 +1175,12 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: '1234', expression: 'different expression' } as unknown) as Document,
doc: ({
id: '1234',

references: [],
} as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand All @@ -1183,7 +1204,16 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: '1234', expression: 'valid expression' } as unknown) as Document,
doc: ({
id: '1234',
title: 'My cool doc',
references: [],
state: {
query: 'kuery',
filters: [],
},
} as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand All @@ -1207,7 +1237,8 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: ({ id: '1234', expression: null } as unknown) as Document,
doc: ({ id: '1234', references: [] } as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand Down
Loading

0 comments on commit 86f73cb

Please sign in to comment.