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

Simplify workflow for dashboard copy creation in both view and edit interaction modes #180938

Merged
merged 26 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d28203a
flush dashboard settings button so it aligns
eokoneyo Apr 16, 2024
bcaa425
remove save as nav option from dashboard view for existing dashboards
eokoneyo Apr 16, 2024
389e65f
change nav menu item render order to reduce visual jank
eokoneyo Apr 16, 2024
606505d
modify translation key string to match changeset
eokoneyo Apr 17, 2024
6120971
test: align a11y tests to match expectation
eokoneyo Apr 22, 2024
e575c4d
changes to accomodate new direction
eokoneyo May 3, 2024
d2be40e
add modal for saveas and duplicate action in edit and view dashboard …
eokoneyo May 3, 2024
b0e498d
fix issue with A11y tests
eokoneyo May 7, 2024
1b666a2
fix issue with dashboard save related tests
eokoneyo May 7, 2024
c791131
convert dashboard modal to functional component and add idfferentiato…
eokoneyo May 8, 2024
2662018
modify dashboard page objects to account for new duplicate and save a…
eokoneyo May 9, 2024
30a9895
add description to differentiate runClone and runSaveAs method
eokoneyo May 9, 2024
8893c75
more test fixes
eokoneyo May 9, 2024
25c8743
adjust existing tests to accomodate change in dashboard page object m…
eokoneyo May 13, 2024
3900781
extend test expectation adjustment to missed occurrence
eokoneyo May 13, 2024
e32bf84
consolidate saveas and clone methods into new interactiveSave method
eokoneyo May 14, 2024
2d3c553
extend new interactive save method to be used in top nav menu items
eokoneyo May 14, 2024
1be2054
adjustment to test to accomodate new changes
eokoneyo May 15, 2024
93bd157
adjust defaut count for extractTitleAndCount
eokoneyo May 16, 2024
7926932
remove comment
eokoneyo May 17, 2024
7fd8089
fix issue with dashboard getting scrolled on opening save modal
eokoneyo May 17, 2024
7b87800
incorporate feedback on operation property for the saveDashboard page…
eokoneyo May 20, 2024
b8a4419
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine May 21, 2024
8b0fc1d
fix failing test relating to dashboard duplication behaviour
eokoneyo May 21, 2024
1796bc9
incorporate PR feedback
eokoneyo May 23, 2024
472d85b
condense store time description into tooltip
eokoneyo May 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ export const topNavStrings = {
defaultMessage: 'Quick save your dashboard without any prompts',
}),
},
saveAs: {
label: i18n.translate('dashboard.topNave.saveAsButtonAriaLabel', {
editModeInteractiveSave: {
label: i18n.translate('dashboard.topNave.editModeInteractiveSaveButtonAriaLabel', {
defaultMessage: 'save as',
}),
description: i18n.translate('dashboard.topNave.saveAsConfigDescription', {
description: i18n.translate('dashboard.topNave.editModeInteractiveSaveConfigDescription', {
defaultMessage: 'Save as a new dashboard',
}),
},
Expand Down Expand Up @@ -229,11 +229,11 @@ export const topNavStrings = {
defaultMessage: 'Open dashboard settings',
}),
},
clone: {
label: i18n.translate('dashboard.topNave.cloneButtonAriaLabel', {
defaultMessage: 'clone',
viewModeInteractiveSave: {
label: i18n.translate('dashboard.topNave.viewModeInteractiveSaveButtonAriaLabel', {
defaultMessage: 'duplicate',
}),
description: i18n.translate('dashboard.topNave.cloneConfigDescription', {
description: i18n.translate('dashboard.topNave.viewModeInteractiveSaveConfigDescription', {
defaultMessage: 'Create a copy of your dashboard',
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,11 @@ export const useDashboardMenuItems = ({
}, [dashboard]);

/**
* Show the dashboard's save modal
* initiate interactive dashboard copy action
*/
const saveDashboardAs = useCallback(() => {
dashboard.runSaveAs().then((result) => maybeRedirect(result));
}, [maybeRedirect, dashboard]);

/**
* Clone the dashboard
*/
const clone = useCallback(() => {
setIsSaveInProgress(true);

dashboard.runClone().then((result) => {
setIsSaveInProgress(false);
maybeRedirect(result);
});
}, [maybeRedirect, dashboard]);
const dashboardInteractiveSave = useCallback(() => {
dashboard.runInteractiveSave(viewMode).then((result) => maybeRedirect(result));
}, [maybeRedirect, dashboard, viewMode]);

/**
* Show the dashboard's "Confirm reset changes" modal. If confirmed:
Expand Down Expand Up @@ -197,15 +185,22 @@ export const useDashboardMenuItems = ({
run: () => quickSaveDashboard(),
} as TopNavMenuData,

saveAs: {
description: topNavStrings.saveAs.description,
interactiveSave: {
disableButton: disableTopNav,
id: 'save',
emphasize: !Boolean(lastSavedId),
testId: 'dashboardSaveMenuItem',
iconType: Boolean(lastSavedId) ? undefined : 'save',
label: Boolean(lastSavedId) ? topNavStrings.saveAs.label : topNavStrings.quickSave.label,
run: () => saveDashboardAs(),
id: 'interactive-save',
testId: 'dashboardInteractiveSaveMenuItem',
run: dashboardInteractiveSave,
label:
viewMode === ViewMode.VIEW
? topNavStrings.viewModeInteractiveSave.label
: Boolean(lastSavedId)
? topNavStrings.editModeInteractiveSave.label
: topNavStrings.quickSave.label,
description:
viewMode === ViewMode.VIEW
? topNavStrings.viewModeInteractiveSave.description
: topNavStrings.editModeInteractiveSave.description,
} as TopNavMenuData,

switchToViewMode: {
Expand All @@ -230,31 +225,23 @@ export const useDashboardMenuItems = ({
testId: 'dashboardSettingsButton',
disableButton: disableTopNav,
run: () => dashboard.showSettings(),
} as TopNavMenuData,

clone: {
...topNavStrings.clone,
id: 'clone',
testId: 'dashboardClone',
disableButton: disableTopNav,
run: () => clone(),
} as TopNavMenuData,
},
};
}, [
quickSaveDashboard,
disableTopNav,
isSaveInProgress,
hasRunMigrations,
hasUnsavedChanges,
dashboardBackup,
saveDashboardAs,
setIsLabsShown,
disableTopNav,
resetChanges,
isLabsShown,
lastSavedId,
dashboardInteractiveSave,
viewMode,
showShare,
dashboard,
clone,
setIsLabsShown,
isLabsShown,
dashboardBackup,
quickSaveDashboard,
resetChanges,
]);

const resetChangesMenuItem = useMemo(() => {
Expand All @@ -276,15 +263,15 @@ export const useDashboardMenuItems = ({
const viewModeTopNavConfig = useMemo(() => {
const labsMenuItem = isLabsEnabled ? [menuItems.labs] : [];
const shareMenuItem = share ? [menuItems.share] : [];
const cloneMenuItem = showWriteControls ? [menuItems.clone] : [];
const duplicateMenuItem = showWriteControls ? [menuItems.interactiveSave] : [];
const editMenuItem = showWriteControls && !managed ? [menuItems.edit] : [];
const mayberesetChangesMenuItem = showResetChange ? [resetChangesMenuItem] : [];

return [
...labsMenuItem,
menuItems.fullScreen,
...shareMenuItem,
...cloneMenuItem,
...duplicateMenuItem,
...mayberesetChangesMenuItem,
...editMenuItem,
];
Expand All @@ -304,30 +291,18 @@ export const useDashboardMenuItems = ({
const editModeItems: TopNavMenuData[] = [];

if (lastSavedId) {
editModeItems.push(menuItems.saveAs, menuItems.switchToViewMode);
editModeItems.push(menuItems.interactiveSave, menuItems.switchToViewMode);

if (showResetChange) {
editModeItems.push(resetChangesMenuItem);
}

editModeItems.push(menuItems.quickSave);
} else {
editModeItems.push(menuItems.switchToViewMode, menuItems.saveAs);
editModeItems.push(menuItems.switchToViewMode, menuItems.interactiveSave);
}
return [...labsMenuItem, menuItems.settings, ...shareMenuItem, ...editModeItems];
}, [
isLabsEnabled,
menuItems.labs,
menuItems.share,
menuItems.settings,
menuItems.saveAs,
menuItems.switchToViewMode,
menuItems.quickSave,
share,
lastSavedId,
showResetChange,
resetChangesMenuItem,
]);
}, [isLabsEnabled, menuItems, share, lastSavedId, showResetChange, resetChangesMenuItem]);

return { viewModeTopNavConfig, editModeTopNavConfig };
};
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,11 @@ export const DashboardSettings = ({ onClose }: DashboardSettingsProps) => {
<EuiFlyoutFooter>
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
<EuiButtonEmpty data-test-subj="cancelCustomizeDashboardButton" onClick={onClose}>
<EuiButtonEmpty
flush="left"
data-test-subj="cancelCustomizeDashboardButton"
onClick={onClose}
>
<FormattedMessage
id="dashboard.embeddableApi.showSettings.flyout.cancelButtonTitle"
defaultMessage="Cancel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
export { showSettings } from './show_settings';
export { addFromLibrary } from './add_panel_from_library';
export { addOrUpdateEmbeddable } from './panel_management';
export { runSaveAs, runQuickSave, runClone } from './run_save_functions';
export { runQuickSave, runInteractiveSave } from './run_save_functions';
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ describe('extractTitleAndCount', () => {
]);
});

it('defaults to the count to 1 and returns the original title when the provided title does not contain a valid count', () => {
expect(extractTitleAndCount('Test dashboard')).toEqual(['Test dashboard', 1]);
expect(extractTitleAndCount('Test dashboard 2')).toEqual(['Test dashboard 2', 1]);
expect(extractTitleAndCount('Test dashboard (-1)')).toEqual(['Test dashboard (-1)', 1]);
expect(extractTitleAndCount('Test dashboard (0)')).toEqual(['Test dashboard (0)', 1]);
expect(extractTitleAndCount('Test dashboard (3.0)')).toEqual(['Test dashboard (3.0)', 1]);
expect(extractTitleAndCount('Test dashboard (8.4)')).toEqual(['Test dashboard (8.4)', 1]);
expect(extractTitleAndCount('Test dashboard (foo3.0)')).toEqual(['Test dashboard (foo3.0)', 1]);
expect(extractTitleAndCount('Test dashboard (bar7)')).toEqual(['Test dashboard (bar7)', 1]);
it('defaults to the count to 0 and returns the original title when the provided title does not contain a valid count', () => {
expect(extractTitleAndCount('Test dashboard')).toEqual(['Test dashboard', 0]);
expect(extractTitleAndCount('Test dashboard 2')).toEqual(['Test dashboard 2', 0]);
expect(extractTitleAndCount('Test dashboard (-1)')).toEqual(['Test dashboard (-1)', 0]);
expect(extractTitleAndCount('Test dashboard (0)')).toEqual(['Test dashboard (0)', 0]);
expect(extractTitleAndCount('Test dashboard (3.0)')).toEqual(['Test dashboard (3.0)', 0]);
expect(extractTitleAndCount('Test dashboard (8.4)')).toEqual(['Test dashboard (8.4)', 0]);
expect(extractTitleAndCount('Test dashboard (foo3.0)')).toEqual(['Test dashboard (foo3.0)', 0]);
expect(extractTitleAndCount('Test dashboard (bar7)')).toEqual(['Test dashboard (bar7)', 0]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export const extractTitleAndCount = (title: string): [string, number] => {
return [baseTitle, Number(count)];
}
}
return [title, 1];
return [title, 0];
Copy link
Contributor Author

@eokoneyo eokoneyo May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return zero instead of 1 when passed string is not of duplicate format. So we can increment whatever value is returned from this function with reckless abandon on duplicate attempt, other wise if we choose not to do so, the first duplicate dashboard value would be of the form dashboard name (2) especially that we wouldn't be able to guard against it.

};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading