Skip to content

Commit

Permalink
Redirect back to dashboard if input is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Maja Grubic committed Aug 12, 2020
1 parent d4b69dc commit 875be62
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export const VisualizeByValueEditor = () => {
setOriginatingApp(value);
setValueInput(valueInputValue);
setEmbeddableId(embeddableIdValue);
if (!valueInputValue) {
history.back();
}
}, [services]);

const isChromeVisible = useChromeVisibility(services.chrome);
Expand All @@ -58,7 +61,8 @@ export const VisualizeByValueEditor = () => {
services,
eventEmitter,
isChromeVisible,
valueInput
valueInput,
originatingApp
);
const { appState, hasUnappliedChanges } = useVisualizeAppState(
services,
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/visualize/public/application/utils/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import { i18n } from '@kbn/i18n';

import { VisualizeConstants } from '../visualize_constants';

const appPrefixes: Record<string, any> = {
dashboards: {
text: i18n.translate('dashboard.listing.breadcrumb', {
defaultMessage: 'Dashboard',
}),
},
};

const defaultEditText = i18n.translate('visualize.editor.defaultEditBreadcrumbText', {
defaultMessage: 'Edit',
});
Expand All @@ -47,6 +55,11 @@ export function getCreateBreadcrumbs() {
];
}

export function getBreadcrumbsPrefixedWithApp(originatingApp: string) {
const originatingAppBreadcrumb = appPrefixes[originatingApp];
return [originatingAppBreadcrumb, ...getLandingBreadcrumbs(), { text: defaultEditText }];
}

export function getEditBreadcrumbs(text: string = defaultEditText) {
return [
...getLandingBreadcrumbs(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const getTopNavConfig = (
};

const topNavMenu: TopNavMenuData[] = [
...(originatingApp && (savedVis?.id || embeddableId)
...(originatingApp && ((savedVis && savedVis.id) || embeddableId)
? [
{
id: 'saveAndReturn',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import { useEffect, useRef, useState } from 'react';
import { VisualizeInput } from 'src/plugins/visualizations/public';
import { ByValueVisInstance, IEditorController, VisualizeServices } from '../../types';
import { getVisualizationInstanceFromInput } from '../get_visualization_instance';
import { getEditBreadcrumbs } from '../breadcrumbs';
import { getBreadcrumbsPrefixedWithApp, getEditBreadcrumbs } from '../breadcrumbs';
import { DefaultEditorController } from '../../../../../vis_default_editor/public';

export const useVisByValue = (
services: VisualizeServices,
eventEmitter: EventEmitter,
isChromeVisible: boolean | undefined,
valueInput?: VisualizeInput
valueInput?: VisualizeInput,
originatingApp?: string
) => {
const [state, setState] = useState<{
byValueVisInstance?: ByValueVisInstance;
Expand All @@ -53,7 +54,9 @@ export const useVisByValue = (
embeddableHandler
);

if (chrome) {
if (chrome && originatingApp) {
chrome.setBreadcrumbs(getBreadcrumbsPrefixedWithApp(originatingApp));
} else if (chrome) {
chrome.setBreadcrumbs(getEditBreadcrumbs());
}

Expand All @@ -72,6 +75,7 @@ export const useVisByValue = (
state.byValueVisInstance,
state.visEditorController,
valueInput,
originatingApp,
]);

useEffect(() => {
Expand Down

0 comments on commit 875be62

Please sign in to comment.