Skip to content

Commit

Permalink
Fix saved dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sulemanof committed Mar 25, 2020
1 parent 9d1a9a9 commit 64bea6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ jest.mock('../../../legacy_imports', () => ({
}));

describe('', () => {
it('addEmbeddableToDashboardUrl', () => {
it('addEmbeddableToDashboardUrl when dashboard is not saved', () => {
const id = '123eb456cd';
const url =
"/pep/app/kibana#/dashboard?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&_a=(description:'',filters:!())";
expect(addEmbeddableToDashboardUrl(url, id)).toEqual(
`/dashboard?_a=%28description%3A%27%27%2Cfilters%3A%21%28%29%29&_g=%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29&addEmbeddableId=${id}&addEmbeddableType=visualization`
);
});
it('addEmbeddableToDashboardUrl when dashboard is saved', () => {
const id = '123eb456cd';
const url =
"/pep/app/kibana#/dashboard/9b780cd0-3dd3-11e8-b2b9-5d5dc1715159?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))&_a=(description:'',filters:!())";
expect(addEmbeddableToDashboardUrl(url, id)).toEqual(
`/dashboard/9b780cd0-3dd3-11e8-b2b9-5d5dc1715159?_a=%28description%3A%27%27%2Cfilters%3A%21%28%29%29&_g=%28refreshInterval%3A%28pause%3A%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29&addEmbeddableId=${id}&addEmbeddableType=visualization`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import { DashboardConstants, VISUALIZE_EMBEDDABLE_TYPE } from '../../../legacy_i
* @param url dasbhoard absolute url
* @param embeddableId id of the saved visualization
*/
export function addEmbeddableToDashboardUrl(url: string, embeddableId: string) {
const dashboardParsedUrl = parseUrl(url);
export function addEmbeddableToDashboardUrl(dashboardUrl: string, embeddableId: string) {
const { url, query } = parseUrl(dashboardUrl);
const [, dashboardId] = url.split(DashboardConstants.CREATE_NEW_DASHBOARD_URL);

dashboardParsedUrl.query[DashboardConstants.ADD_EMBEDDABLE_TYPE] = VISUALIZE_EMBEDDABLE_TYPE;
dashboardParsedUrl.query[DashboardConstants.ADD_EMBEDDABLE_ID] = embeddableId;
const query = stringify(dashboardParsedUrl.query);
query[DashboardConstants.ADD_EMBEDDABLE_TYPE] = VISUALIZE_EMBEDDABLE_TYPE;
query[DashboardConstants.ADD_EMBEDDABLE_ID] = embeddableId;

return `${DashboardConstants.CREATE_NEW_DASHBOARD_URL}?${query}`;
return `${DashboardConstants.CREATE_NEW_DASHBOARD_URL}${dashboardId}?${stringify(query)}`;
}

0 comments on commit 64bea6e

Please sign in to comment.