Skip to content

Commit 003fcb1

Browse files
authored
Add Lens to Recently Accessed (#77249)
added lens to recently accessed on load and save in app.tsx
1 parent 5c457d1 commit 003fcb1

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

x-pack/plugins/lens/common/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ export function getBasePath() {
1616
export function getEditPath(id: string) {
1717
return `#/edit/${encodeURIComponent(id)}`;
1818
}
19+
20+
export function getFullPath(id: string) {
21+
return `/app/${PLUGIN_ID}${getEditPath(id)}`;
22+
}

x-pack/plugins/lens/public/app_plugin/app.test.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,29 @@ describe('Lens App', () => {
300300
]);
301301
});
302302

303+
it('adds to the recently viewed list on load', async () => {
304+
const defaultArgs = makeDefaultArgs();
305+
instance = mount(<App {...defaultArgs} />);
306+
307+
(defaultArgs.docStorage.load as jest.Mock).mockResolvedValue({
308+
id: '1234',
309+
title: 'Daaaaaaadaumching!',
310+
state: {
311+
query: 'fake query',
312+
filters: [],
313+
},
314+
references: [],
315+
});
316+
await act(async () => {
317+
instance.setProps({ docId: '1234' });
318+
});
319+
expect(defaultArgs.core.chrome.recentlyAccessed.add).toHaveBeenCalledWith(
320+
'/app/lens#/edit/1234',
321+
'Daaaaaaadaumching!',
322+
'1234'
323+
);
324+
});
325+
303326
it('sets originatingApp breadcrumb when the document title changes', async () => {
304327
const defaultArgs = makeDefaultArgs();
305328
defaultArgs.originatingApp = 'ultraCoolDashboard';
@@ -591,6 +614,19 @@ describe('Lens App', () => {
591614
expect(args.docStorage.load).not.toHaveBeenCalled();
592615
});
593616

617+
it('adds to the recently viewed list on save', async () => {
618+
const { args } = await save({
619+
initialDocId: undefined,
620+
newCopyOnSave: false,
621+
newTitle: 'hello there',
622+
});
623+
expect(args.core.chrome.recentlyAccessed.add).toHaveBeenCalledWith(
624+
'/app/lens#/edit/aaa',
625+
'hello there',
626+
'aaa'
627+
);
628+
});
629+
594630
it('saves the latest doc as a copy', async () => {
595631
const { args, instance: inst } = await save({
596632
initialDocId: '1234',

x-pack/plugins/lens/public/app_plugin/app.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
IndexPatternsContract,
4040
SavedQuery,
4141
} from '../../../../../src/plugins/data/public';
42+
import { getFullPath } from '../../common';
4243

4344
interface State {
4445
indicateNoData: boolean;
@@ -271,6 +272,7 @@ export function App({
271272
docStorage
272273
.load(docId)
273274
.then((doc) => {
275+
core.chrome.recentlyAccessed.add(getFullPath(docId), doc.title, docId);
274276
getAllIndexPatterns(
275277
_.uniq(
276278
doc.references.filter(({ type }) => type === 'index-pattern').map(({ id }) => id)
@@ -365,6 +367,7 @@ export function App({
365367
docStorage
366368
.save(doc)
367369
.then(({ id }) => {
370+
core.chrome.recentlyAccessed.add(getFullPath(id), doc.title, id);
368371
// Prevents unnecessary network request and disables save button
369372
const newDoc = { ...doc, id };
370373
const currentOriginatingApp = state.originatingApp;

0 commit comments

Comments
 (0)