-
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.
Browse files
Browse the repository at this point in the history
…93458) # Backport This will backport the following commits from `main` to `8.x`: - [[Dashboard] Sharing via link to an expanded panel (#190086)](#190086) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Rachel Shen","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-19T17:38:21Z","message":"[Dashboard] Sharing via link to an expanded panel (#190086)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/145454\r\n\r\nThis PR allows users with a dashboard with an expanded (maximized) panel\r\nto be shared to other users via url or the share modal link. To\r\nimplement this, the expanded panel Id is added to the url:\r\n\r\n`/app/dashboard/{dashboardID}/{expandedPanelID}_g()_a()`\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\nCo-authored-by: Hannah Mudge <[email protected]>","sha":"603023124681429ee900ff3a73793ce31a9cad58","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Presentation","loe:medium","impact:medium","v9.0.0","backport:prev-minor","v8.16.0"],"title":"[Dashboard] Sharing via link to an expanded panel","number":190086,"url":"https://github.com/elastic/kibana/pull/190086","mergeCommit":{"message":"[Dashboard] Sharing via link to an expanded panel (#190086)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/145454\r\n\r\nThis PR allows users with a dashboard with an expanded (maximized) panel\r\nto be shared to other users via url or the share modal link. To\r\nimplement this, the expanded panel Id is added to the url:\r\n\r\n`/app/dashboard/{dashboardID}/{expandedPanelID}_g()_a()`\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\nCo-authored-by: Hannah Mudge <[email protected]>","sha":"603023124681429ee900ff3a73793ce31a9cad58"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/190086","number":190086,"mergeCommit":{"message":"[Dashboard] Sharing via link to an expanded panel (#190086)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/145454\r\n\r\nThis PR allows users with a dashboard with an expanded (maximized) panel\r\nto be shared to other users via url or the share modal link. To\r\nimplement this, the expanded panel Id is added to the url:\r\n\r\n`/app/dashboard/{dashboardID}/{expandedPanelID}_g()_a()`\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\nCo-authored-by: Hannah Mudge <[email protected]>","sha":"603023124681429ee900ff3a73793ce31a9cad58"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Rachel Shen <[email protected]>
- Loading branch information
1 parent
0977302
commit 331de8d
Showing
5 changed files
with
160 additions
and
7 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
src/plugins/dashboard/public/dashboard_app/dashboard_app.test.tsx
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,98 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { render, waitFor } from '@testing-library/react'; | ||
import { MemoryHistory, createMemoryHistory } from 'history'; | ||
import React, { useEffect } from 'react'; | ||
import type { DashboardRendererProps } from '../dashboard_container/external_api/dashboard_renderer'; | ||
import { buildMockDashboard } from '../mocks'; | ||
import { DashboardApp } from './dashboard_app'; | ||
|
||
import * as dashboardRendererStuff from '../dashboard_container/external_api/lazy_dashboard_renderer'; | ||
import { DashboardApi } from '..'; | ||
|
||
/* These tests circumvent the need to test the router and legacy code | ||
/* the dashboard app will be passed the expanded panel id from the DashboardRouter through mountApp() | ||
/* @link https://github.com/elastic/kibana/pull/190086/ | ||
*/ | ||
|
||
describe('Dashboard App', () => { | ||
const mockDashboard = buildMockDashboard(); | ||
let mockHistory: MemoryHistory; | ||
// this is in url_utils dashboardApi expandedPanel subscription | ||
let historySpy: jest.SpyInstance; | ||
// this is in the dashboard app for the renderer when provided an expanded panel id | ||
const expandPanelSpy = jest.spyOn(mockDashboard, 'expandPanel'); | ||
|
||
beforeAll(() => { | ||
mockHistory = createMemoryHistory(); | ||
historySpy = jest.spyOn(mockHistory, 'replace'); | ||
|
||
/** | ||
* Mock the LazyDashboardRenderer component to avoid rendering the actual dashboard | ||
* and hitting errors that aren't relevant | ||
*/ | ||
jest | ||
.spyOn(dashboardRendererStuff, 'LazyDashboardRenderer') | ||
// we need overwrite the onApiAvailable prop to get the dashboard Api in the dashboard app | ||
.mockImplementation(({ onApiAvailable }: DashboardRendererProps) => { | ||
useEffect(() => { | ||
onApiAvailable?.(mockDashboard as DashboardApi); | ||
}, [onApiAvailable]); | ||
|
||
return <div>Test renderer</div>; | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
// reset the spies before each test | ||
expandPanelSpy.mockClear(); | ||
historySpy.mockClear(); | ||
}); | ||
|
||
it('test the default behavior without an expandedPanel id passed as a prop to the DashboardApp', async () => { | ||
render(<DashboardApp redirectTo={jest.fn()} history={mockHistory} />); | ||
|
||
await waitFor(() => { | ||
expect(expandPanelSpy).not.toHaveBeenCalled(); | ||
// this value should be undefined by default | ||
expect(mockDashboard.expandedPanelId.getValue()).toBe(undefined); | ||
// history should not be called | ||
expect(historySpy).toHaveBeenCalledTimes(0); | ||
expect(mockHistory.location.pathname).toBe('/'); | ||
}); | ||
|
||
// simulate expanding a panel | ||
mockDashboard.expandPanel('123'); | ||
|
||
await waitFor(() => { | ||
expect(mockDashboard.expandedPanelId.getValue()).toBe('123'); | ||
expect(historySpy).toHaveBeenCalledTimes(1); | ||
expect(mockHistory.location.pathname).toBe('/create/123'); | ||
}); | ||
}); | ||
|
||
it('test that the expanded panel behavior subject and history is called when passed as a prop to the DashboardApp', async () => { | ||
render(<DashboardApp redirectTo={jest.fn()} history={mockHistory} expandedPanelId="456" />); | ||
|
||
await waitFor(() => { | ||
expect(expandPanelSpy).toHaveBeenCalledTimes(1); | ||
expect(historySpy).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
// simulate minimizing a panel | ||
mockDashboard.expandedPanelId.next(undefined); | ||
|
||
await waitFor(() => { | ||
expect(mockDashboard.expandedPanelId.getValue()).toBe(undefined); | ||
expect(historySpy).toHaveBeenCalledTimes(1); | ||
expect(mockHistory.location.pathname).toBe('/create'); | ||
}); | ||
}); | ||
}); |
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
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