Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lens to Recently Accessed #77249

Merged
merged 3 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}${getEditPath(id)}`;
}
36 changes: 36 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,29 @@ describe('Lens App', () => {
]);
});

it('adds to the recently viewed list on load', async () => {
const defaultArgs = makeDefaultArgs();
instance = mount(<App {...defaultArgs} />);

(defaultArgs.docStorage.load as jest.Mock).mockResolvedValue({
id: '1234',
title: 'Daaaaaaadaumching!',
state: {
query: 'fake query',
filters: [],
},
references: [],
});
await act(async () => {
instance.setProps({ docId: '1234' });
});
expect(defaultArgs.core.chrome.recentlyAccessed.add).toHaveBeenCalledWith(
'/app/lens#/edit/1234',
'Daaaaaaadaumching!',
'1234'
);
});

it('sets originatingApp breadcrumb when the document title changes', async () => {
const defaultArgs = makeDefaultArgs();
defaultArgs.originatingApp = 'ultraCoolDashboard';
Expand Down Expand Up @@ -591,6 +614,19 @@ describe('Lens App', () => {
expect(args.docStorage.load).not.toHaveBeenCalled();
});

it('adds to the recently viewed list on save', async () => {
const { args } = await save({
initialDocId: undefined,
newCopyOnSave: false,
newTitle: 'hello there',
});
expect(args.core.chrome.recentlyAccessed.add).toHaveBeenCalledWith(
'/app/lens#/edit/aaa',
'hello there',
'aaa'
);
});

it('saves the latest doc as a copy', async () => {
const { args, instance: inst } = await save({
initialDocId: '1234',
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
IndexPatternsContract,
SavedQuery,
} from '../../../../../src/plugins/data/public';
import { getFullPath } from '../../common';

interface State {
indicateNoData: boolean;
Expand Down Expand Up @@ -271,6 +272,7 @@ export function App({
docStorage
.load(docId)
.then((doc) => {
core.chrome.recentlyAccessed.add(getFullPath(docId), doc.title, docId);
getAllIndexPatterns(
_.uniq(
doc.references.filter(({ type }) => type === 'index-pattern').map(({ id }) => id)
Expand Down Expand Up @@ -365,6 +367,7 @@ export function App({
docStorage
.save(doc)
.then(({ id }) => {
core.chrome.recentlyAccessed.add(getFullPath(id), doc.title, id);
// Prevents unnecessary network request and disables save button
const newDoc = { ...doc, id };
const currentOriginatingApp = state.originatingApp;
Expand Down