Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export interface CreateControlButtonProps {
setLastUsedDataViewId?: (newDataViewId: string) => void;
getRelevantDataViewId?: () => string | undefined;
buttonType: CreateControlButtonTypes;
closePopover?: () => void;
onClick?: () => void;
onFlyoutClose?: () => void;
}

interface CreateControlResult {
Expand All @@ -44,7 +45,8 @@ export const CreateControlButton = ({
defaultControlWidth,
defaultControlGrow,
addNewEmbeddable,
closePopover,
onClick,
onFlyoutClose,
getRelevantDataViewId,
setLastUsedDataViewId,
updateDefaultWidth,
Expand Down Expand Up @@ -76,6 +78,7 @@ export const CreateControlButton = ({
if (confirmed) {
reject();
ref.close();
onFlyoutClose?.();
}
});
};
Expand All @@ -93,6 +96,7 @@ export const CreateControlButton = ({
}
resolve({ type, controlInput: inputToReturn });
ref.close();
onFlyoutClose?.();
};

const flyoutInstance = openFlyout(
Expand Down Expand Up @@ -140,9 +144,7 @@ export const CreateControlButton = ({
key: 'addControl',
onClick: () => {
createNewControl();
if (closePopover) {
closePopover();
}
onClick?.();
},
'data-test-subj': 'controls-create-button',
'aria-label': ControlGroupStrings.management.getManageButtonTitle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import { setFlyoutRef } from '../embeddable/control_group_container';

export interface EditControlGroupButtonProps {
controlGroupContainer: ControlGroupContainer;
closePopover: () => void;
onClick?: () => void;
onFlyoutClose?: () => void;
}

export const EditControlGroup = ({
controlGroupContainer,
closePopover,
onClick,
onFlyoutClose,
}: EditControlGroupButtonProps) => {
const { overlays } = pluginServices.getServices();
const { openConfirm, openFlyout } = overlays;
Expand All @@ -44,6 +46,7 @@ export const EditControlGroup = ({
controlGroupContainer.removeEmbeddable(panelId)
);
ref.close();
onFlyoutClose?.();
});
};

Expand All @@ -55,7 +58,10 @@ export const EditControlGroup = ({
updateInput={(changes) => controlGroupContainer.updateInput(changes)}
controlCount={Object.keys(controlGroupContainer.getInput().panels ?? {}).length}
onDeleteAll={() => onDeleteAll(flyoutInstance)}
onClose={() => flyoutInstance.close()}
onClose={() => {
flyoutInstance.close();
onFlyoutClose?.();
}}
/>
</PresentationUtilProvider>
),
Expand All @@ -64,6 +70,7 @@ export const EditControlGroup = ({
onClose: () => {
flyoutInstance.close();
setFlyoutRef(undefined);
onFlyoutClose?.();
},
}
);
Expand All @@ -74,7 +81,7 @@ export const EditControlGroup = ({
key: 'manageControls',
onClick: () => {
editControlGroup();
closePopover();
onClick?.();
},
icon: 'gear',
'data-test-subj': 'controls-settings-button',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,14 @@ export class ControlGroupContainer extends Container<
/**
* Returns a button that allows controls to be created externally using the embeddable
* @param buttonType Controls the button styling
* @param closePopover Closes the create control menu popover when flyout opens - only necessary if `buttonType === 'toolbar'`
* @param onClick Optional parameter that controls what secondary actions should happen when the "create control" button is clicked
* @return If `buttonType == 'toolbar'`, returns `EuiContextMenuPanel` with input control types as items.
* Otherwise, if `buttonType == 'callout'` returns `EuiButton` with popover containing input control types.
*/
public getCreateControlButton = (
buttonType: CreateControlButtonTypes,
closePopover?: () => void
onClick?: () => void,
onClose?: () => void
) => {
return (
<CreateControlButton
Expand All @@ -128,22 +129,31 @@ export class ControlGroupContainer extends Container<
this.updateInput({ defaultControlGrow })
}
addNewEmbeddable={(type, input) => this.addNewEmbeddable(type, input)}
closePopover={closePopover}
onClick={onClick}
onFlyoutClose={onClose}
getRelevantDataViewId={() => this.getMostRelevantDataViewId()}
setLastUsedDataViewId={(newId) => this.setLastUsedDataViewId(newId)}
/>
);
};

private getEditControlGroupButton = (closePopover: () => void) => {
return <EditControlGroup controlGroupContainer={this} closePopover={closePopover} />;
private getEditControlGroupButton = (onClick: () => void, onClose?: () => void) => {
return (
<EditControlGroup controlGroupContainer={this} onClick={onClick} onFlyoutClose={onClose} />
);
};

/**
* Returns the toolbar button that is used for creating controls and managing control settings
* @return `SolutionToolbarPopover` button for input controls
*/
public getToolbarButtons = () => {
public getToolbarButtons = ({
onClick,
onClose,
}: {
onClick?: () => void;
onClose?: () => void;
}) => {
return (
<SolutionToolbarPopover
ownFocus
Expand All @@ -156,8 +166,21 @@ export class ControlGroupContainer extends Container<
{({ closePopover }: { closePopover: () => void }) => (
<EuiContextMenuPanel
items={[
this.getCreateControlButton('toolbar', closePopover),
this.getEditControlGroupButton(closePopover),
this.getCreateControlButton(
'toolbar',
() => {
closePopover();
onClick?.();
},
() => onClose?.()
),
this.getEditControlGroupButton(
() => {
closePopover();
onClick?.();
},
() => onClose?.()
),
]}
/>
)}
Expand Down
17 changes: 11 additions & 6 deletions src/plugins/dashboard/public/application/dashboard_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DashboardTopNav, isCompleteDashboardAppState } from './top_nav/dashboar
import { DashboardAppServices, DashboardEmbedSettings, DashboardRedirect } from '../types';
import { createKbnUrlStateStorage, withNotifyOnErrors } from '../services/kibana_utils';
import { DashboardAppNoDataPage } from './dashboard_app_no_data';
import { DashboardEditTourProvider } from './tour';
export interface DashboardAppProps {
history: History;
savedDashboardId?: string;
Expand Down Expand Up @@ -120,10 +121,14 @@ export function DashboardApp({
};
}, [data.search.session]);

const printMode = useMemo(
() => dashboardAppState.getLatestDashboardState?.().viewMode === ViewMode.PRINT,
[dashboardAppState]
);
const [printMode, editMode, viewMode] = useMemo(() => {
const currentViewMode = dashboardAppState.getLatestDashboardState?.().viewMode;
return [
currentViewMode === ViewMode.PRINT,
currentViewMode === ViewMode.EDIT,
currentViewMode === ViewMode.VIEW,
];
}, [dashboardAppState]);

useEffect(() => {
if (!embedSettings) chrome.setIsVisible(!printMode);
Expand All @@ -135,7 +140,7 @@ export function DashboardApp({
<DashboardAppNoDataPage onDataViewCreated={() => setShowNoDataPage(false)} />
)}
{!showNoDataPage && isCompleteDashboardAppState(dashboardAppState) && (
<>
<DashboardEditTourProvider editMode={editMode} viewMode={viewMode}>
<DashboardTopNav
printMode={printMode}
redirectTo={redirectTo}
Expand Down Expand Up @@ -163,7 +168,7 @@ export function DashboardApp({
>
<EmbeddableRenderer embeddable={dashboardAppState.dashboardContainer} />
</div>
</>
</DashboardEditTourProvider>
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
useDashboardDispatch,
useDashboardSelector,
} from '../state';
import { useDashboardEditTourContext } from '../tour';

export interface DashboardTopNavState {
chromeIsVisible: boolean;
Expand Down Expand Up @@ -129,6 +130,9 @@ export function DashboardTopNav({
const IS_DARK_THEME = uiSettings.get('theme:darkMode');
const isLabsEnabled = uiSettings.get(UI_SETTINGS.ENABLE_LABS_UI);

const { currentEditTourStep, getNextEditTourStep, onViewModeChange, setTourVisibility } =
useDashboardEditTourContext();

const trackUiMetric = usageCollection?.reportUiCounter.bind(
usageCollection,
DashboardConstants.DASHBOARD_ID
Expand All @@ -153,6 +157,7 @@ export function DashboardTopNav({

const addFromLibrary = useCallback(() => {
if (!isErrorEmbeddable(dashboardAppState.dashboardContainer)) {
setTourVisibility(false);
setState((s) => ({
...s,
addPanelOverlay: openAddPanelFlyout({
Expand All @@ -161,6 +166,9 @@ export function DashboardTopNav({
getFactory: embeddable.getEmbeddableFactory,
notifications: core.notifications,
overlays: core.overlays,
showTour: () => {
setTourVisibility(true);
},
SavedObjectFinder: getSavedObjectFinder(core.savedObjects, uiSettings),
reportUiCounter: usageCollection?.reportUiCounter,
theme: core.theme,
Expand All @@ -177,6 +185,7 @@ export function DashboardTopNav({
core.theme,
uiSettings,
usageCollection,
setTourVisibility,
]);

const createNewVisType = useCallback(
Expand Down Expand Up @@ -208,8 +217,18 @@ export function DashboardTopNav({
searchSessionId: data.search.session.getSessionId(),
},
});

if (currentEditTourStep === 1) {
getNextEditTourStep();
}
},
[stateTransferService, data.search.session, trackUiMetric]
[
stateTransferService,
data.search.session,
trackUiMetric,
currentEditTourStep,
getNextEditTourStep,
]
);

const closeAllFlyouts = useCallback(() => {
Expand All @@ -221,7 +240,8 @@ export function DashboardTopNav({
}, [state.addPanelOverlay, dashboardAppState.dashboardContainer.controlGroup]);

const onChangeViewMode = useCallback(
(newMode: ViewMode) => {
async (newMode: ViewMode) => {
onViewModeChange(newMode);
closeAllFlyouts();
const willLoseChanges = newMode === ViewMode.VIEW && dashboardAppState.hasUnsavedChanges;

Expand All @@ -234,7 +254,13 @@ export function DashboardTopNav({
dashboardAppState.resetToLastSavedState?.()
);
},
[closeAllFlyouts, core.overlays, dashboardAppState, dispatchDashboardStateChange]
[
closeAllFlyouts,
core.overlays,
dashboardAppState,
dispatchDashboardStateChange,
onViewModeChange,
]
);

const runSaveAs = useCallback(async () => {
Expand Down Expand Up @@ -617,7 +643,14 @@ export function DashboardTopNav({
onClick={addFromLibrary}
data-test-subj="dashboardAddPanelButton"
/>,
dashboardAppState.dashboardContainer.controlGroup?.getToolbarButtons(),
dashboardAppState.dashboardContainer.controlGroup?.getToolbarButtons({
onClick: () => {
setTourVisibility(false);
},
onClose: () => {
setTourVisibility(true);
},
}),
],
}}
</SolutionToolbar>
Expand Down
Loading