-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable right click on visualizations and dashboards listings (#88936)
* Enable right-click on visualizations listing page * Make it simpler * Enable right click to the dashboard listing * Add unit tests * Fix link on dashboard * Fix visualize link * Fix PR comments * Fix functional test failure * Use kbnUrlStateStorage instead * Change method to getDashboardListItemLink * Change method to getVisualizeListItemLink Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
8534faf
commit b4931e6
Showing
9 changed files
with
370 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
src/plugins/dashboard/public/application/listing/get_dashboard_list_item_link.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
|
||
import { getDashboardListItemLink } from './get_dashboard_list_item_link'; | ||
import { ApplicationStart } from 'kibana/public'; | ||
import { esFilters } from '../../../../data/public'; | ||
import { createHashHistory } from 'history'; | ||
import { createKbnUrlStateStorage } from '../../../../kibana_utils/public'; | ||
import { GLOBAL_STATE_STORAGE_KEY } from '../../url_generator'; | ||
|
||
const DASHBOARD_ID = '13823000-99b9-11ea-9eb6-d9e8adceb647'; | ||
|
||
const application = ({ | ||
getUrlForApp: jest.fn((appId: string, options?: { path?: string; absolute?: boolean }) => { | ||
return `/app/${appId}${options?.path}`; | ||
}), | ||
} as unknown) as ApplicationStart; | ||
|
||
const history = createHashHistory(); | ||
const kbnUrlStateStorage = createKbnUrlStateStorage({ | ||
history, | ||
useHash: false, | ||
}); | ||
kbnUrlStateStorage.set(GLOBAL_STATE_STORAGE_KEY, { time: { from: 'now-7d', to: 'now' } }); | ||
|
||
describe('listing dashboard link', () => { | ||
test('creates a link to a dashboard without the timerange query if time is saved on the dashboard', async () => { | ||
const url = getDashboardListItemLink( | ||
application, | ||
kbnUrlStateStorage, | ||
false, | ||
DASHBOARD_ID, | ||
true | ||
); | ||
expect(url).toMatchInlineSnapshot(`"/app/dashboards#/view/${DASHBOARD_ID}?_g=()"`); | ||
}); | ||
|
||
test('creates a link to a dashboard with the timerange query if time is not saved on the dashboard', async () => { | ||
const url = getDashboardListItemLink( | ||
application, | ||
kbnUrlStateStorage, | ||
false, | ||
DASHBOARD_ID, | ||
false | ||
); | ||
expect(url).toMatchInlineSnapshot( | ||
`"/app/dashboards#/view/${DASHBOARD_ID}?_g=(time:(from:now-7d,to:now))"` | ||
); | ||
}); | ||
}); | ||
|
||
describe('when global time changes', () => { | ||
beforeEach(() => { | ||
kbnUrlStateStorage.set(GLOBAL_STATE_STORAGE_KEY, { | ||
time: { | ||
from: '2021-01-05T11:45:53.375Z', | ||
to: '2021-01-21T11:46:00.990Z', | ||
}, | ||
}); | ||
}); | ||
|
||
test('propagates the correct time on the query', async () => { | ||
const url = getDashboardListItemLink( | ||
application, | ||
kbnUrlStateStorage, | ||
false, | ||
DASHBOARD_ID, | ||
false | ||
); | ||
expect(url).toMatchInlineSnapshot( | ||
`"/app/dashboards#/view/${DASHBOARD_ID}?_g=(time:(from:'2021-01-05T11:45:53.375Z',to:'2021-01-21T11:46:00.990Z'))"` | ||
); | ||
}); | ||
}); | ||
|
||
describe('when global refreshInterval changes', () => { | ||
beforeEach(() => { | ||
kbnUrlStateStorage.set(GLOBAL_STATE_STORAGE_KEY, { | ||
refreshInterval: { pause: false, value: 300 }, | ||
}); | ||
}); | ||
|
||
test('propagates the refreshInterval on the query', async () => { | ||
const url = getDashboardListItemLink( | ||
application, | ||
kbnUrlStateStorage, | ||
false, | ||
DASHBOARD_ID, | ||
false | ||
); | ||
expect(url).toMatchInlineSnapshot( | ||
`"/app/dashboards#/view/${DASHBOARD_ID}?_g=(refreshInterval:(pause:!f,value:300))"` | ||
); | ||
}); | ||
}); | ||
|
||
describe('when global filters change', () => { | ||
beforeEach(() => { | ||
const filters = [ | ||
{ | ||
meta: { | ||
alias: null, | ||
disabled: false, | ||
negate: false, | ||
}, | ||
query: { query: 'q1' }, | ||
}, | ||
{ | ||
meta: { | ||
alias: null, | ||
disabled: false, | ||
negate: false, | ||
}, | ||
query: { query: 'q1' }, | ||
$state: { | ||
store: esFilters.FilterStateStore.GLOBAL_STATE, | ||
}, | ||
}, | ||
]; | ||
kbnUrlStateStorage.set(GLOBAL_STATE_STORAGE_KEY, { | ||
filters, | ||
}); | ||
}); | ||
|
||
test('propagates the filters on the query', async () => { | ||
const url = getDashboardListItemLink( | ||
application, | ||
kbnUrlStateStorage, | ||
false, | ||
DASHBOARD_ID, | ||
false | ||
); | ||
expect(url).toMatchInlineSnapshot( | ||
`"/app/dashboards#/view/${DASHBOARD_ID}?_g=(filters:!((meta:(alias:!n,disabled:!f,negate:!f),query:(query:q1)),('$state':(store:globalState),meta:(alias:!n,disabled:!f,negate:!f),query:(query:q1))))"` | ||
); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
src/plugins/dashboard/public/application/listing/get_dashboard_list_item_link.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
import { ApplicationStart } from 'kibana/public'; | ||
import { QueryState } from '../../../../data/public'; | ||
import { setStateToKbnUrl } from '../../../../kibana_utils/public'; | ||
import { createDashboardEditUrl, DashboardConstants } from '../../dashboard_constants'; | ||
import { GLOBAL_STATE_STORAGE_KEY } from '../../url_generator'; | ||
import { IKbnUrlStateStorage } from '../../services/kibana_utils'; | ||
|
||
export const getDashboardListItemLink = ( | ||
application: ApplicationStart, | ||
kbnUrlStateStorage: IKbnUrlStateStorage, | ||
useHash: boolean, | ||
id: string, | ||
timeRestore: boolean | ||
) => { | ||
let url = application.getUrlForApp(DashboardConstants.DASHBOARDS_ID, { | ||
path: `#${createDashboardEditUrl(id)}`, | ||
}); | ||
const globalStateInUrl = kbnUrlStateStorage.get<QueryState>(GLOBAL_STATE_STORAGE_KEY) || {}; | ||
|
||
if (timeRestore) { | ||
delete globalStateInUrl.time; | ||
delete globalStateInUrl.refreshInterval; | ||
} | ||
url = setStateToKbnUrl<QueryState>(GLOBAL_STATE_STORAGE_KEY, globalStateInUrl, { useHash }, url); | ||
return url; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.