Skip to content

Commit

Permalink
[Lens] Register saved object references (elastic#74523)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Aug 21, 2020
1 parent 65293aa commit c3b3e7f
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 @@ -282,11 +282,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 All @@ -312,12 +312,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 @@ -341,15 +340,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 @@ -410,7 +407,6 @@ describe('Lens App', () => {
expression: 'valid expression',
state: {
query: 'kuery',
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
},
} as jest.ResolvedValue<Document>);
});
Expand All @@ -433,7 +429,12 @@ describe('Lens App', () => {
}

async function save({
lastKnownDoc = { expression: 'kibana 3' },
lastKnownDoc = {
references: [],
state: {
filters: [],
},
},
initialDocId,
...saveProps
}: SaveProps & {
Expand All @@ -447,16 +448,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 @@ -474,6 +473,7 @@ describe('Lens App', () => {
onChange({
filterableIndexPatterns: [],
doc: { id: initialDocId, ...lastKnownDoc } as Document,
isSaveable: true,
})
);

Expand Down Expand Up @@ -507,7 +507,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 +527,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 +543,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 +564,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 +585,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 +610,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 +635,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 +690,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 +730,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 @@ -745,7 +754,6 @@ describe('Lens App', () => {
expression: 'valid expression',
state: {
query: 'kuery',
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
},
} as jest.ResolvedValue<Document>);
});
Expand Down Expand Up @@ -790,8 +798,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 +817,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,11 +1054,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 @@ -1080,7 +1090,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 @@ -1101,7 +1116,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 +1141,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 @@ -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',
references: [],
state: {
query: 'kuery',
filters: [],
},
} 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', references: [] } as unknown) as Document,
isSaveable: true,
})
);
instance.update();
Expand Down
Loading

0 comments on commit c3b3e7f

Please sign in to comment.