Skip to content

Commit

Permalink
made Lens visualizations appear in recently accessed
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Sep 10, 2020
1 parent a39c44c commit 9595722
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions x-pack/plugins/lens/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
}
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/app_plugin/mounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
17 changes: 9 additions & 8 deletions x-pack/plugins/lens/public/persistence/saved_object_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 };
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 9595722

Please sign in to comment.