diff --git a/x-pack/plugins/lens/common/constants.ts b/x-pack/plugins/lens/common/constants.ts index 16397d340d951..80d433873d2a0 100644 --- a/x-pack/plugins/lens/common/constants.ts +++ b/x-pack/plugins/lens/common/constants.ts @@ -16,3 +16,7 @@ export function getBasePath() { export function getEditPath(id: string) { return `#/edit/${encodeURIComponent(id)}`; } + +export function getFullPath(id: string) { + return `/app/${PLUGIN_ID}#/edit/${encodeURIComponent(id)}`; +} diff --git a/x-pack/plugins/lens/public/app_plugin/mounter.tsx b/x-pack/plugins/lens/public/app_plugin/mounter.tsx index 398d01af7f1b3..b233a1154b081 100644 --- a/x-pack/plugins/lens/public/app_plugin/mounter.tsx +++ b/x-pack/plugins/lens/public/app_plugin/mounter.tsx @@ -82,7 +82,7 @@ export async function mountApp( editorFrame={instance} storage={new Storage(localStorage)} docId={routeProps.match.params.id} - docStorage={new SavedObjectIndexStore(savedObjectsClient)} + docStorage={new SavedObjectIndexStore(savedObjectsClient, coreStart.chrome)} redirectTo={(id, returnToOrigin, newlyCreated) => redirectTo(routeProps, id, returnToOrigin, newlyCreated) } diff --git a/x-pack/plugins/lens/public/persistence/saved_object_store.ts b/x-pack/plugins/lens/public/persistence/saved_object_store.ts index e4609213ec792..a74d3fc97eea7 100644 --- a/x-pack/plugins/lens/public/persistence/saved_object_store.ts +++ b/x-pack/plugins/lens/public/persistence/saved_object_store.ts @@ -8,9 +8,10 @@ import { SavedObjectAttributes, SavedObjectsClientContract, SavedObjectReference, + ChromeStart, } from 'kibana/public'; import { Query } from '../../../../../src/plugins/data/public'; -import { PersistableFilter } from '../../common'; +import { getFullPath, PersistableFilter } from '../../common'; export interface Document { id?: string; @@ -40,11 +41,7 @@ export interface DocumentLoader { export type SavedObjectStore = DocumentLoader & DocumentSaver; export class SavedObjectIndexStore implements SavedObjectStore { - private client: SavedObjectsClientContract; - - constructor(client: SavedObjectsClientContract) { - this.client = client; - } + constructor(private client: SavedObjectsClientContract, private chrome: ChromeStart) {} async save(vis: Document) { const { id, type, references, ...rest } = vis; @@ -58,6 +55,8 @@ export class SavedObjectIndexStore implements SavedObjectStore { references, })); + this.chrome.recentlyAccessed.add(getFullPath(result.id), vis.title, result.id); + return { ...vis, id: result.id }; } @@ -90,12 +89,14 @@ export class SavedObjectIndexStore implements SavedObjectStore { if (error) { throw error; } - - return { + const document = { ...(attributes as SavedObjectAttributes), references, id, type, } as Document; + this.chrome.recentlyAccessed.add(getFullPath(id), document.title, id); + + return document; } }