mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Dashboard] Disables top nav actions when cloning or overlay is showing (#162091)
## Summary Closes #162093. This fixes a few UX bugs around top nav actions being available when they shouldn't be. I noticed that we check for overlays in the top nav buttons, but the dashboard container wasn't actually updating app state when overlays were being opened and closed by nested embeddables. Main changes: - disables all top nav actions while cloning/save is in progress - tracks overlay state in dashboard container when panel actions open/close flyouts - disables all top nav actions while flyout is open ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### Risk Matrix Delete this section if it is not applicable to this PR. Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release. When forming the risk matrix, consider some of the following examples and how they may potentially impact the change: | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Multiple Spaces—unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. | | Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. | | Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. | | [See more potential risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) | ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
7770ccc19f
commit
e09da1dbf4
12 changed files with 88 additions and 28 deletions
|
@ -14,6 +14,7 @@ import type {
|
|||
EmbeddableInput,
|
||||
EmbeddableOutput,
|
||||
} from '@kbn/embeddable-plugin/public';
|
||||
import { tracksOverlays } from '@kbn/embeddable-plugin/public';
|
||||
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
|
||||
|
||||
import { ReplacePanelFlyout } from './replace_panel_flyout';
|
||||
|
@ -33,12 +34,18 @@ export async function openReplacePanelFlyout(options: {
|
|||
overlays: { openFlyout },
|
||||
} = pluginServices.getServices();
|
||||
|
||||
// send the overlay ref to the root embeddable if it is capable of tracking overlays
|
||||
const rootEmbeddable = embeddable.getRoot();
|
||||
const overlayTracker = tracksOverlays(rootEmbeddable) ? rootEmbeddable : undefined;
|
||||
|
||||
const flyoutSession = openFlyout(
|
||||
toMountPoint(
|
||||
<ReplacePanelFlyout
|
||||
container={embeddable}
|
||||
onClose={() => {
|
||||
if (flyoutSession) {
|
||||
if (overlayTracker) overlayTracker.clearOverlays();
|
||||
|
||||
flyoutSession.close();
|
||||
}
|
||||
}}
|
||||
|
@ -50,6 +57,12 @@ export async function openReplacePanelFlyout(options: {
|
|||
{
|
||||
'data-test-subj': 'dashboardReplacePanel',
|
||||
ownFocus: true,
|
||||
onClose: (overlayRef) => {
|
||||
if (overlayTracker) overlayTracker.clearOverlays();
|
||||
overlayRef.close();
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
overlayTracker?.openOverlay(flyoutSession);
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ export const useDashboardMenuItems = ({
|
|||
const lastSavedId = dashboard.select((state) => state.componentState.lastSavedId);
|
||||
const dashboardTitle = dashboard.select((state) => state.explicitInput.title);
|
||||
const viewMode = dashboard.select((state) => state.explicitInput.viewMode);
|
||||
const disableTopNav = isSaveInProgress || hasOverlays;
|
||||
|
||||
/**
|
||||
* Show the Dashboard app's share menu
|
||||
|
@ -106,7 +107,12 @@ export const useDashboardMenuItems = ({
|
|||
* Clone the dashboard
|
||||
*/
|
||||
const clone = useCallback(() => {
|
||||
dashboard.runClone().then((result) => maybeRedirect(result));
|
||||
setIsSaveInProgress(true);
|
||||
|
||||
dashboard.runClone().then((result) => {
|
||||
setIsSaveInProgress(false);
|
||||
maybeRedirect(result);
|
||||
});
|
||||
}, [maybeRedirect, dashboard]);
|
||||
|
||||
/**
|
||||
|
@ -134,6 +140,7 @@ export const useDashboardMenuItems = ({
|
|||
/**
|
||||
* Register all of the top nav configs that can be used by dashboard.
|
||||
*/
|
||||
|
||||
const menuItems = useMemo(() => {
|
||||
return {
|
||||
fullScreen: {
|
||||
|
@ -141,6 +148,7 @@ export const useDashboardMenuItems = ({
|
|||
id: 'full-screen',
|
||||
testId: 'dashboardFullScreenMode',
|
||||
run: () => dashboard.dispatch.setFullScreenMode(true),
|
||||
disableButton: disableTopNav,
|
||||
} as TopNavMenuData,
|
||||
|
||||
labs: {
|
||||
|
@ -161,6 +169,7 @@ export const useDashboardMenuItems = ({
|
|||
dashboard.dispatch.setViewMode(ViewMode.EDIT);
|
||||
dashboard.clearOverlays();
|
||||
},
|
||||
disableButton: disableTopNav,
|
||||
} as TopNavMenuData,
|
||||
|
||||
quickSave: {
|
||||
|
@ -170,13 +179,13 @@ export const useDashboardMenuItems = ({
|
|||
emphasize: true,
|
||||
isLoading: isSaveInProgress,
|
||||
testId: 'dashboardQuickSaveMenuItem',
|
||||
disableButton: !hasUnsavedChanges || isSaveInProgress || hasOverlays,
|
||||
disableButton: disableTopNav || !hasUnsavedChanges,
|
||||
run: () => quickSaveDashboard(),
|
||||
} as TopNavMenuData,
|
||||
|
||||
saveAs: {
|
||||
description: topNavStrings.saveAs.description,
|
||||
disableButton: isSaveInProgress || hasOverlays,
|
||||
disableButton: disableTopNav,
|
||||
id: 'save',
|
||||
emphasize: !Boolean(lastSavedId),
|
||||
testId: 'dashboardSaveMenuItem',
|
||||
|
@ -188,7 +197,7 @@ export const useDashboardMenuItems = ({
|
|||
switchToViewMode: {
|
||||
...topNavStrings.switchToViewMode,
|
||||
id: 'cancel',
|
||||
disableButton: isSaveInProgress || !lastSavedId || hasOverlays,
|
||||
disableButton: disableTopNav || !lastSavedId,
|
||||
testId: 'dashboardViewOnlyMode',
|
||||
run: () => resetChanges(true),
|
||||
} as TopNavMenuData,
|
||||
|
@ -197,7 +206,7 @@ export const useDashboardMenuItems = ({
|
|||
...topNavStrings.share,
|
||||
id: 'share',
|
||||
testId: 'shareTopNavButton',
|
||||
disableButton: isSaveInProgress || hasOverlays,
|
||||
disableButton: disableTopNav,
|
||||
run: showShare,
|
||||
} as TopNavMenuData,
|
||||
|
||||
|
@ -205,7 +214,7 @@ export const useDashboardMenuItems = ({
|
|||
...topNavStrings.settings,
|
||||
id: 'settings',
|
||||
testId: 'dashboardSettingsButton',
|
||||
disableButton: isSaveInProgress || hasOverlays,
|
||||
disableButton: disableTopNav,
|
||||
run: () => dashboard.showSettings(),
|
||||
} as TopNavMenuData,
|
||||
|
||||
|
@ -213,22 +222,22 @@ export const useDashboardMenuItems = ({
|
|||
...topNavStrings.clone,
|
||||
id: 'clone',
|
||||
testId: 'dashboardClone',
|
||||
disableButton: isSaveInProgress,
|
||||
disableButton: disableTopNav,
|
||||
run: () => clone(),
|
||||
} as TopNavMenuData,
|
||||
};
|
||||
}, [
|
||||
quickSaveDashboard,
|
||||
hasUnsavedChanges,
|
||||
disableTopNav,
|
||||
isSaveInProgress,
|
||||
saveDashboardAs,
|
||||
setIsLabsShown,
|
||||
resetChanges,
|
||||
hasOverlays,
|
||||
hasUnsavedChanges,
|
||||
lastSavedId,
|
||||
isLabsShown,
|
||||
showShare,
|
||||
dashboard,
|
||||
setIsLabsShown,
|
||||
isLabsShown,
|
||||
quickSaveDashboard,
|
||||
saveDashboardAs,
|
||||
resetChanges,
|
||||
clone,
|
||||
]);
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ export function addFromLibrary(this: DashboardContainer) {
|
|||
this.setScrollToPanelId(id);
|
||||
this.setHighlightPanelId(id);
|
||||
},
|
||||
onClose: () => {
|
||||
this.clearOverlays();
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -427,10 +427,12 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
|
|||
|
||||
public openOverlay = (ref: OverlayRef) => {
|
||||
this.clearOverlays();
|
||||
this.dispatch.setHasOverlays(true);
|
||||
this.overlayRef = ref;
|
||||
};
|
||||
|
||||
public clearOverlays = () => {
|
||||
this.dispatch.setHasOverlays(false);
|
||||
this.controlGroup?.closeAllFlyouts();
|
||||
this.overlayRef?.close();
|
||||
};
|
||||
|
|
|
@ -23,10 +23,13 @@ const LazyAddPanelFlyout = React.lazy(async () => {
|
|||
export const openAddPanelFlyout = ({
|
||||
container,
|
||||
onAddPanel,
|
||||
onClose,
|
||||
}: {
|
||||
container: IContainer;
|
||||
onAddPanel?: (id: string) => void;
|
||||
onClose?: () => void;
|
||||
}): OverlayRef => {
|
||||
// send the overlay ref to the root embeddable if it is capable of tracking overlays
|
||||
const flyoutSession = core.overlays.openFlyout(
|
||||
toMountPoint(
|
||||
<Suspense fallback={<EuiLoadingSpinner />}>
|
||||
|
@ -37,7 +40,12 @@ export const openAddPanelFlyout = ({
|
|||
{
|
||||
'data-test-subj': 'dashboardAddPanel',
|
||||
ownFocus: true,
|
||||
onClose: (overlayRef) => {
|
||||
if (onClose) onClose();
|
||||
overlayRef.close();
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return flyoutSession;
|
||||
};
|
||||
|
|
|
@ -10,12 +10,13 @@ import React from 'react';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { TimeRange } from '@kbn/es-query';
|
||||
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
|
||||
import { OverlayRef, OverlayStart, ThemeServiceStart } from '@kbn/core/public';
|
||||
import { OverlayStart, ThemeServiceStart } from '@kbn/core/public';
|
||||
import { Action, IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
|
||||
|
||||
import { CustomizePanelEditor } from './customize_panel_editor';
|
||||
import { ViewMode, CommonlyUsedRange } from '../../../lib/types';
|
||||
import { IEmbeddable, Embeddable, EmbeddableInput, EmbeddableOutput } from '../../..';
|
||||
import { ViewMode, CommonlyUsedRange } from '../../../lib/types';
|
||||
import { tracksOverlays } from '../track_overlays';
|
||||
import { CustomizePanelEditor } from './customize_panel_editor';
|
||||
|
||||
export const ACTION_CUSTOMIZE_PANEL = 'ACTION_CUSTOMIZE_PANEL';
|
||||
|
||||
|
@ -23,15 +24,6 @@ const VISUALIZE_EMBEDDABLE_TYPE = 'visualization';
|
|||
|
||||
type VisualizeEmbeddable = IEmbeddable<{ id: string }, EmbeddableOutput & { visTypeName: string }>;
|
||||
|
||||
interface TracksOverlays {
|
||||
openOverlay: (ref: OverlayRef) => void;
|
||||
clearOverlays: () => void;
|
||||
}
|
||||
|
||||
function tracksOverlays(root: unknown): root is TracksOverlays {
|
||||
return Boolean((root as TracksOverlays).openOverlay && (root as TracksOverlays).clearOverlays);
|
||||
}
|
||||
|
||||
function isVisualizeEmbeddable(
|
||||
embeddable: IEmbeddable | VisualizeEmbeddable
|
||||
): embeddable is VisualizeEmbeddable {
|
||||
|
|
|
@ -291,7 +291,7 @@ export const CustomizePanelEditor = (props: CustomizePanelProps) => {
|
|||
<EuiButton data-test-subj="saveCustomizePanelButton" onClick={save} fill>
|
||||
<FormattedMessage
|
||||
id="embeddableApi.customizePanel.flyout.saveButtonTitle"
|
||||
defaultMessage="Save"
|
||||
defaultMessage="Apply"
|
||||
/>
|
||||
</EuiButton>
|
||||
</EuiFlexItem>
|
||||
|
|
|
@ -17,3 +17,4 @@ export {
|
|||
} from './customize_panel_action';
|
||||
export { EditPanelAction, ACTION_EDIT_PANEL } from './edit_panel_action/edit_panel_action';
|
||||
export { RemovePanelAction, REMOVE_PANEL_ACTION } from './remove_panel_action/remove_panel_action';
|
||||
export { tracksOverlays } from './track_overlays';
|
||||
|
|
|
@ -11,6 +11,7 @@ import { Action } from '@kbn/ui-actions-plugin/public';
|
|||
import { Start as InspectorStartContract } from '@kbn/inspector-plugin/public';
|
||||
|
||||
import { IEmbeddable } from '../../../lib/embeddables';
|
||||
import { tracksOverlays } from '../track_overlays';
|
||||
|
||||
export const ACTION_INSPECT_PANEL = 'openInspector';
|
||||
|
||||
|
@ -45,6 +46,11 @@ export class InspectPanelAction implements Action<ActionContext> {
|
|||
if (!(await this.isCompatible({ embeddable })) || adapters === undefined) {
|
||||
throw new Error('Action not compatible with context');
|
||||
}
|
||||
|
||||
// send the overlay ref to the root embeddable if it is capable of tracking overlays
|
||||
const rootEmbeddable = embeddable.getRoot();
|
||||
const overlayTracker = tracksOverlays(rootEmbeddable) ? rootEmbeddable : undefined;
|
||||
|
||||
const session = this.inspector.open(adapters, {
|
||||
title: embeddable.getTitle(),
|
||||
options: {
|
||||
|
@ -62,14 +68,20 @@ export class InspectPanelAction implements Action<ActionContext> {
|
|||
// before calling the original destroy method
|
||||
const originalDestroy = embeddable.destroy;
|
||||
embeddable.destroy = () => {
|
||||
if (overlayTracker) overlayTracker.clearOverlays();
|
||||
|
||||
session.close();
|
||||
if (originalDestroy) {
|
||||
originalDestroy.call(embeddable);
|
||||
}
|
||||
};
|
||||
|
||||
// In case the inspector gets closed (otherwise), restore the original destroy function
|
||||
session.onClose.finally(() => {
|
||||
if (overlayTracker) overlayTracker.clearOverlays();
|
||||
embeddable.destroy = originalDestroy;
|
||||
});
|
||||
|
||||
overlayTracker?.openOverlay(session);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* 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 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 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { OverlayRef } from '@kbn/core-mount-utils-browser';
|
||||
|
||||
interface TracksOverlays {
|
||||
openOverlay: (ref: OverlayRef) => void;
|
||||
clearOverlays: () => void;
|
||||
}
|
||||
|
||||
export const tracksOverlays = (root: unknown): root is TracksOverlays => {
|
||||
return Boolean((root as TracksOverlays).openOverlay && (root as TracksOverlays).clearOverlays);
|
||||
};
|
|
@ -92,6 +92,7 @@ export {
|
|||
ACTION_EDIT_PANEL,
|
||||
RemovePanelAction,
|
||||
REMOVE_PANEL_ACTION,
|
||||
tracksOverlays,
|
||||
} from './embeddable_panel/panel_actions';
|
||||
|
||||
export type {
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
"@kbn/saved-objects-finder-plugin",
|
||||
"@kbn/analytics",
|
||||
"@kbn/usage-collection-plugin",
|
||||
"@kbn/ui-theme"
|
||||
"@kbn/ui-theme",
|
||||
"@kbn/core-mount-utils-browser"
|
||||
],
|
||||
"exclude": ["target/**/*"]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue