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 De-Angular] Add breadcrumb with view/edit mode and unsaved flow #4479

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -14,10 +14,15 @@ import { DashboardServices } from '../../types';
import { useDashboardAppState } from '../utils/use/use_dashboard_app_state';
import { useDashboardContainer } from '../utils/use/use_dashboard_container';
import { useEditorUpdates } from '../utils/use/use_editor_updates';
import {
setBreadcrumbsForExistingDashboard,
setBreadcrumbsForNewDashboard,
} from '../utils/breadcrumbs';

export const DashboardEditor = () => {
const { id: dashboardIdFromUrl } = useParams<{ id: string }>();
const { services } = useOpenSearchDashboards<DashboardServices>();
const { chrome } = services;
const isChromeVisible = useChromeVisibility(services.chrome);
const [eventEmitter] = useState(new EventEmitter());

Expand Down Expand Up @@ -48,6 +53,25 @@ export const DashboardEditor = () => {
appState
);

useEffect(() => {
if (appState) {
if (savedDashboardInstance?.id) {
chrome.setBreadcrumbs(
setBreadcrumbsForExistingDashboard(
savedDashboardInstance.title,
appState?.getState().viewMode,
appState?.getState().isDirty
)
);
chrome.docTitle.change(savedDashboardInstance.title);
} else {
chrome.setBreadcrumbs(
setBreadcrumbsForNewDashboard(appState?.getState().viewMode, appState?.getState().isDirty)
);
}
}
}, [appState?.getState(), savedDashboardInstance, chrome]);

useEffect(() => {
// clean up all registered listeners if any is left
return () => {
Expand Down
98 changes: 98 additions & 0 deletions src/plugins/dashboard/public/application/utils/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import { i18n } from '@osd/i18n';
import { DashboardConstants } from '../../dashboard_constants';
import { ViewMode } from '../../embeddable_plugin';

export function getLandingBreadcrumbs() {
return [
{
text: i18n.translate('dashboard.dashboardAppBreadcrumbsTitle', {
defaultMessage: 'Dashboards',
}),
href: `#${DashboardConstants.LANDING_PAGE_PATH}`,
},
];
}

export const setBreadcrumbsForNewDashboard = (viewMode: ViewMode, isDirty: boolean) => {
if (viewMode === ViewMode.VIEW) {
return [
...getLandingBreadcrumbs(),
{
text: i18n.translate('dashboard.strings.dashboardViewTitle', {
defaultMessage: 'New Dashboard',
}),
},
];
} else {
if (isDirty) {
return [
...getLandingBreadcrumbs(),
{
text: i18n.translate('dashboard.strings.dashboardEditTitle', {
defaultMessage: 'Editing New Dashboard (unsaved)',
}),
},
];
} else {
return [
...getLandingBreadcrumbs(),
{
text: i18n.translate('dashboard.strings.dashboardEditTitle', {
defaultMessage: 'Editing New Dashboard',
}),
},
];
}
}
};

export const setBreadcrumbsForExistingDashboard = (
title: string,
viewMode: ViewMode,
isDirty: boolean
) => {
if (viewMode === ViewMode.VIEW) {
return [
...getLandingBreadcrumbs(),
{
text: i18n.translate('dashboard.strings.dashboardViewTitle', {
defaultMessage: '{title}',
values: { title },
}),
},
];
} else {
if (isDirty) {
return [
...getLandingBreadcrumbs(),
{
text: i18n.translate('dashboard.strings.dashboardEditTitle', {
defaultMessage: 'Editing {title} (unsaved)',
values: { title },
}),
},
];
} else {
return [
...getLandingBreadcrumbs(),
{
text: i18n.translate('dashboard.strings.dashboardEditTitle', {
defaultMessage: 'Editing {title}',
values: { title },
}),
},
];
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export const getNavActions = (
stateContainer.transitions.set('description', currentDescription);
stateContainer.transitions.set('timeRestore', currentTimeRestore);
}

// If the save was successfull, then set the app state isDirty back to false
stateContainer.transitions.set('isDirty', false);
return response;
});
};
Expand Down