Skip to content

Commit

Permalink
hide duplicate when workspace disabled in dashboard
Browse files Browse the repository at this point in the history
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
  • Loading branch information
yuye-aws committed Sep 18, 2023
1 parent 133a380 commit c4d1a31
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const TopNav = ({
getTopNavConfig(
currentAppState?.viewMode,
navActions,
dashboardConfig.getHideWriteControls()
dashboardConfig.getHideWriteControls(),
services.workspaces.workspaceEnabled$.value
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import { NavAction } from '../../../../types';
export function getTopNavConfig(
dashboardMode: ViewMode,
actions: { [key: string]: NavAction },
hideWriteControls: boolean
hideWriteControls: boolean,
workspaceEnabled?: boolean
) {
switch (dashboardMode) {
case ViewMode.VIEW:
Expand All @@ -54,8 +55,9 @@ export function getTopNavConfig(
: [
getFullScreenConfig(actions[TopNavIds.FULL_SCREEN]),
getShareConfig(actions[TopNavIds.SHARE]),
getCloneConfig(actions[TopNavIds.CLONE]),
getDuplicateConfig(actions[TopNavIds.DUPLICATE]),
...(workspaceEnabled
? [getDuplicateConfig(actions[TopNavIds.DUPLICATE])]
: [getCloneConfig(actions[TopNavIds.CLONE])]),
getEditConfig(actions[TopNavIds.ENTER_EDIT_MODE]),
];
case ViewMode.EDIT:
Expand Down
99 changes: 51 additions & 48 deletions src/plugins/dashboard/public/application/utils/get_nav_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const getNavActions = (
const navActions: {
[key: string]: NavAction;
} = {};
const workspaceEnabled = workspaces.workspaceEnabled$.value;

if (!stateContainer) {
return navActions;
Expand Down Expand Up @@ -174,57 +175,59 @@ export const getNavActions = (
showCloneModal(onClone, currentTitle);
};

navActions[TopNavIds.DUPLICATE] = () => {
const onDuplicate = async (
dashboardSavedObjects: SavedObjectWithMetadata[],
includeReferencesDeep: boolean,
targetWorkspace: string
) => {
const objectsToDuplicate = dashboardSavedObjects.map((obj) => ({
id: obj.id,
type: obj.type,
}));

try {
await duplicateSavedObjects(
http,
objectsToDuplicate,
includeReferencesDeep,
targetWorkspace
);
if (workspaceEnabled) {
navActions[TopNavIds.DUPLICATE] = () => {
const onDuplicate = async (
dashboardSavedObjects: SavedObjectWithMetadata[],
includeReferencesDeep: boolean,
targetWorkspace: string
) => {
const objectsToDuplicate = dashboardSavedObjects.map((obj) => ({
id: obj.id,
type: obj.type,
}));

try {
await duplicateSavedObjects(
http,
objectsToDuplicate,
includeReferencesDeep,
targetWorkspace
);

notifications.toasts.addSuccess({
title: i18n.translate('dashboard.dashboardWasDuplicatedSuccessMessage', {
defaultMessage: 'Duplicate dashboard successfully',
}),
});
} catch (e) {
notifications.toasts.addDanger({
title: i18n.translate('dashboard.dashboardWasNotDuplicatedDangerMessage', {
defaultMessage: 'Unable to duplicate dashboard',
}),
});
}
};

notifications.toasts.addSuccess({
title: i18n.translate('dashboard.dashboardWasDuplicatedSuccessMessage', {
defaultMessage: 'Duplicate dashboard successfully',
}),
});
} catch (e) {
notifications.toasts.addDanger({
title: i18n.translate('dashboard.dashboardWasNotDuplicatedDangerMessage', {
defaultMessage: 'Unable to duplicate dashboard',
}),
});
}
};
const currentWorkspace = workspaces.currentWorkspace$.value;
const dashboardSavedObject = ({
...currentContainer,
...savedDashboard,
} as unknown) as SavedObjectWithMetadata;
dashboardSavedObject.meta = { title: savedDashboard.title };

const currentWorkspace = workspaces.currentWorkspace$.value;
const dashboardSavedObject = ({
...currentContainer,
...savedDashboard,
} as unknown) as SavedObjectWithMetadata;
dashboardSavedObject.meta = { title: savedDashboard.title };

const showDuplicateModalProps = {
http,
onDuplicate,
notifications,
currentWorkspace,
duplicateMode: DuplicateMode.Selected,
selectedSavedObjects: [dashboardSavedObject],
};
const showDuplicateModalProps = {
http,
onDuplicate,
notifications,
currentWorkspace,
duplicateMode: DuplicateMode.Selected,
selectedSavedObjects: [dashboardSavedObject],
};

showDuplicateModal(showDuplicateModalProps, I18nContext);
};
showDuplicateModal(showDuplicateModalProps, I18nContext);
};
}

navActions[TopNavIds.ADD_EXISTING] = () => {
if (currentContainer && !isErrorEmbeddable(currentContainer)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const getTopNavConfig = (
workspaces,
}: VisualizeServices
) => {
const workspaceEnabled = workspaces.workspaceEnabled$.value;
const { vis, embeddableHandler } = visInstance;
const savedVis = 'savedVis' in visInstance ? visInstance.savedVis : undefined;

Expand Down Expand Up @@ -252,7 +253,7 @@ export const getTopNavConfig = (
// disable the Share button if no action specified
disableButton: !share || !!embeddableId,
},
...(savedVis?.id
...(savedVis?.id && workspaceEnabled
? [
{
id: 'duplicate',
Expand Down

0 comments on commit c4d1a31

Please sign in to comment.