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

[Dashboard] Sharing via link to an expanded panel #190086

Merged
merged 98 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
6d28f6e
sharing via link to expanded panel
rshen91 Aug 7, 2024
b532740
add comment
rshen91 Aug 14, 2024
35a84ed
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 14, 2024
0e702a4
Merge branch 'main' into expandedPanelId-link
rshen91 Aug 20, 2024
318443e
wip
rshen91 Aug 20, 2024
e5850cc
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 20, 2024
74e1c64
Merge remote-tracking branch 'origin/expandedPanelId-link' into expan…
rshen91 Aug 20, 2024
40b58a2
wip
rshen91 Aug 21, 2024
62bdd9b
got it working!
rshen91 Aug 21, 2024
80e2fd2
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 21, 2024
1b2fbb0
remove unnecessary changes
rshen91 Aug 21, 2024
3e4935e
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 21, 2024
af64338
clean up
rshen91 Aug 21, 2024
924a8a3
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 21, 2024
4226427
fix
rshen91 Aug 21, 2024
bf90e88
fix time restore boolean
rshen91 Aug 21, 2024
ecc366a
more fix
rshen91 Aug 21, 2024
0348004
fix helper function
rshen91 Aug 21, 2024
c335be3
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 21, 2024
1ba7b28
order of parameters
rshen91 Aug 22, 2024
a89027c
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 22, 2024
9dca988
fix
rshen91 Aug 22, 2024
5f58b34
order of stop watching state in dashboardapp
rshen91 Aug 22, 2024
8e592f2
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 22, 2024
d197ab3
refactor to avoid race
rshen91 Aug 22, 2024
bcdf7e3
mostly working
rshen91 Aug 26, 2024
fe64ceb
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 26, 2024
e39f6e2
fix
rshen91 Aug 26, 2024
3b1ee94
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 26, 2024
98b0fb4
clean up
rshen91 Aug 26, 2024
f588023
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 26, 2024
334f7de
Merge branch 'main' into expandedPanelId-link
rshen91 Aug 26, 2024
53f19f1
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Aug 29, 2024
5277709
wip history
rshen91 Sep 3, 2024
8833219
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 3, 2024
aaad93b
pair with Hannah about history
rshen91 Sep 3, 2024
dd8f508
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 3, 2024
ffa503c
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 4, 2024
02c4e99
revert unneeded changes
rshen91 Sep 4, 2024
8c388ba
Merge remote-tracking branch 'origin/expandedPanelId-link' into expan…
rshen91 Sep 4, 2024
3292e81
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 5, 2024
83c4462
change hook type to avoid collisions with state transfer
rshen91 Sep 5, 2024
b5ff1b7
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 5, 2024
d3d86d0
code review
rshen91 Sep 5, 2024
2226362
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 5, 2024
fe839bf
order of cleanup
rshen91 Sep 5, 2024
c8cfcdd
refactor
rshen91 Sep 9, 2024
21e74d5
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 9, 2024
7bb9aea
fix
rshen91 Sep 9, 2024
697e31a
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 9, 2024
d8f4066
fix
rshen91 Sep 9, 2024
f990a26
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 9, 2024
b69d56d
code review and pairing with Hannah
rshen91 Sep 10, 2024
4929113
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 10, 2024
b560671
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 10, 2024
28591e2
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 10, 2024
547ad52
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 11, 2024
2bb66e4
wip test
rshen91 Sep 11, 2024
792f33d
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 11, 2024
36f5a70
Merge remote-tracking branch 'origin/expandedPanelId-link' into expan…
rshen91 Sep 11, 2024
ba236a4
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Sep 11, 2024
192f089
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 12, 2024
99f575f
add test
rshen91 Sep 13, 2024
b204837
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 13, 2024
10eca46
Merge remote-tracking branch 'origin/expandedPanelId-link' into expan…
rshen91 Sep 13, 2024
b8b691a
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Sep 13, 2024
8b2ff8a
expanded panel update test
rshen91 Sep 13, 2024
49745b4
Merge remote-tracking branch 'origin/expandedPanelId-link' into expan…
rshen91 Sep 13, 2024
fe94eb8
unit tests w hannah
rshen91 Sep 13, 2024
4d66d52
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 13, 2024
3129d45
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 16, 2024
4aaee31
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 16, 2024
cc06466
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 16, 2024
65a9147
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 16, 2024
6ac5521
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 17, 2024
0a89da4
code review
rshen91 Sep 17, 2024
4234e10
code review
rshen91 Sep 17, 2024
c0bcc10
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 17, 2024
599a92e
fix initial load of expanded panel returning undefined
rshen91 Sep 17, 2024
e2e8d03
fix code review
rshen91 Sep 17, 2024
e8272d5
merge
rshen91 Sep 17, 2024
31303e6
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 17, 2024
5208cae
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 17, 2024
04c4877
Get mocks working again after conflicts
Heenawter Sep 18, 2024
5f44194
working test
rshen91 Sep 18, 2024
d6c13a2
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 18, 2024
29a9551
before all block restoration
rshen91 Sep 18, 2024
d1097d0
test refactoring
rshen91 Sep 19, 2024
76e62d4
Update src/plugins/dashboard/public/dashboard_app/dashboard_app.test.tsx
rshen91 Sep 19, 2024
2a1ac13
remove redundant spy
rshen91 Sep 19, 2024
3d18a3d
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 19, 2024
b0fb938
Merge remote-tracking branch 'origin/expandedPanelId-link' into expan…
rshen91 Sep 19, 2024
4a8130c
[CI] Auto-commit changed files from 'yarn openapi:bundle'
kibanamachine Sep 19, 2024
d5b8ae9
Merge branch 'main' into expandedPanelId-link
rshen91 Sep 19, 2024
460084b
code review feedback
rshen91 Sep 19, 2024
008ca1c
Merge remote-tracking branch 'upstream/main' into expandedPanelId-link
rshen91 Sep 19, 2024
5456f8d
Merge remote-tracking branch 'origin/expandedPanelId-link' into expan…
rshen91 Sep 19, 2024
6eed21c
pairing with hannah tests
rshen91 Sep 19, 2024
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
1 change: 1 addition & 0 deletions src/plugins/dashboard/common/dashboard_container/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface DashboardContainerInput extends EmbeddableInput {
description?: string;
isEmbeddedExternally?: boolean;
executionContext: KibanaExecutionContext;
expandedPanelId?: string;

// dashboard options: TODO, build a new system to avoid all shared state appearing here. See https://github.com/elastic/kibana/issues/144532 for more information.
hidePanelTitles: DashboardOptions['hidePanelTitles'];
Expand Down
21 changes: 18 additions & 3 deletions src/plugins/dashboard/public/dashboard_app/dashboard_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useExecutionContext } from '@kbn/kibana-react-plugin/public';
import { createKbnUrlStateStorage, withNotifyOnErrors } from '@kbn/kibana-utils-plugin/public';

import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics';
import { DashboardContainerInput } from '../../common';
import {
DashboardAppNoDataPage,
isDashboardAppInNoDataState,
Expand All @@ -36,7 +37,11 @@ import { pluginServices } from '../services/plugin_services';
import { AwaitingDashboardAPI } from '../dashboard_container';
import { DashboardRedirect } from '../dashboard_container/types';
import { useDashboardMountContext } from './hooks/dashboard_mount_context';
import { createDashboardEditUrl, DASHBOARD_APP_ID } from '../dashboard_constants';
import {
createDashboardEditUrl,
DASHBOARD_APP_ID,
DASHBOARD_STATE_STORAGE_KEY,
} from '../dashboard_constants';
import { useDashboardOutcomeValidation } from './hooks/use_dashboard_outcome_validation';
import { loadDashboardHistoryLocationState } from './locator/load_dashboard_history_location_state';
import type { DashboardCreationOptions } from '../dashboard_container/embeddable/dashboard_container_factory';
Expand Down Expand Up @@ -68,9 +73,16 @@ export function DashboardApp({
history,
}: DashboardAppProps) {
const [showNoDataPage, setShowNoDataPage] = useState<boolean>(false);
const [redirectToExpandedPanel, setRedirectToExpandedPanel] = useState<string | undefined>();

useMount(() => {
(async () => setShowNoDataPage(await isDashboardAppInNoDataState()))();
(async () => {
setShowNoDataPage(await isDashboardAppInNoDataState());
const state: DashboardContainerInput | null = kbnUrlStateStorage.get(
DASHBOARD_STATE_STORAGE_KEY
);
if (state) setRedirectToExpandedPanel(state?.expandedPanelId);
Heenawter marked this conversation as resolved.
Show resolved Hide resolved
})();
});
const [dashboardAPI, setDashboardAPI] = useState<AwaitingDashboardAPI>(null);

Expand Down Expand Up @@ -197,8 +209,11 @@ export function DashboardApp({
kbnUrlStateStorage,
dashboardAPI,
});
if (redirectToExpandedPanel) {
return dashboardAPI?.setExpandedPanelId(redirectToExpandedPanel);
}
return () => stopWatchingAppStateInUrl();
}, [dashboardAPI, kbnUrlStateStorage, savedDashboardId]);
}, [dashboardAPI, kbnUrlStateStorage, redirectToExpandedPanel, savedDashboardId]);

const locator = useMemo(() => url?.locators.get(DASHBOARD_APP_LOCATOR), [url]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe('ShowShareModal', () => {
isDirty: true,
anchorElement: document.createElement('div'),
getDashboardState: () => ({} as DashboardContainerInput),
hasExpandedPanel: unsavedState?.expandedPanelId ?? undefined,
};
};

Expand Down Expand Up @@ -221,4 +222,10 @@ describe('ShowShareModal', () => {
expect(shareLocatorParams.panels![1].embeddableConfig.changedKey2).toBe('definitely changed');
expect(shareLocatorParams.panels![2].embeddableConfig.changedKey3).toBe('should still exist');
});
it('generates a shareable URL to the application state with an expanded panel', () => {
const showModalProps = getPropsAndShare({ expandedPanelId: 'panel_1' });
ShowShareModal(showModalProps);
const mockShareableUrl = toggleShareMenuSpy.mock.calls[0][0].shareableUrl;
expect(mockShareableUrl).toBe('http://localhost/#?_g=!n&_a=(expandedPanelId:panel_1)');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface ShowShareModalProps {
dashboardTitle?: string;
anchorElement: HTMLElement;
getDashboardState: () => DashboardContainerInput;
hasExpandedPanel?: string;
}

export const showPublicUrlSwitch = (anonymousUserCapabilities: Capabilities) => {
Expand All @@ -51,6 +52,7 @@ export function ShowShareModal({
savedObjectId,
dashboardTitle,
getDashboardState,
hasExpandedPanel,
}: ShowShareModalProps) {
const {
dashboardCapabilities: { createShortUrl: allowShortUrl },
Expand Down Expand Up @@ -199,7 +201,7 @@ export function ShowShareModal({

const shareableUrl = setStateToKbnUrl(
'_a',
unsavedStateForLocator,
{ ...unsavedStateForLocator, expandedPanelId: hasExpandedPanel },
{ useHash: false, storeInHashQuery: true },
unhashUrl(baseUrl)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const useDashboardMenuItems = ({
savedObjectId: lastSavedId,
isDirty: Boolean(hasUnsavedChanges),
getDashboardState: () => dashboard.getState().explicitInput,
hasExpandedPanel: dashboard.getExpandedPanelId(),
});
},
[dashboardTitle, hasUnsavedChanges, lastSavedId, dashboard]
Expand Down