-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] Originating App Breadcrumb (#75692)
* [Maps] Originating App Breadcrumb * pass getHasUnsavedChanges instead of passing boolean Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
f2fef70
commit c3e226c
Showing
3 changed files
with
105 additions
and
26 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
x-pack/plugins/maps/public/routing/routes/maps_app/get_breadcrumbs.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { getBreadcrumbs } from './get_breadcrumbs'; | ||
|
||
jest.mock('../../../kibana_services', () => {}); | ||
jest.mock('../../maps_router', () => {}); | ||
|
||
const getHasUnsavedChanges = () => { | ||
return false; | ||
}; | ||
|
||
test('should get breadcrumbs "Maps / mymap"', () => { | ||
const breadcrumbs = getBreadcrumbs({ title: 'mymap', getHasUnsavedChanges }); | ||
expect(breadcrumbs.length).toBe(2); | ||
expect(breadcrumbs[0].text).toBe('Maps'); | ||
expect(breadcrumbs[1].text).toBe('mymap'); | ||
}); | ||
|
||
test('should get breadcrumbs "Dashboard / Maps / mymap" with originatingApp', () => { | ||
const breadcrumbs = getBreadcrumbs({ | ||
title: 'mymap', | ||
getHasUnsavedChanges, | ||
originatingApp: 'dashboardId', | ||
getAppNameFromId: (appId) => { | ||
return 'Dashboard'; | ||
}, | ||
}); | ||
expect(breadcrumbs.length).toBe(3); | ||
expect(breadcrumbs[0].text).toBe('Dashboard'); | ||
expect(breadcrumbs[1].text).toBe('Maps'); | ||
expect(breadcrumbs[2].text).toBe('mymap'); | ||
}); |
59 changes: 59 additions & 0 deletions
59
x-pack/plugins/maps/public/routing/routes/maps_app/get_breadcrumbs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { getNavigateToApp } from '../../../kibana_services'; | ||
// @ts-expect-error | ||
import { goToSpecifiedPath } from '../../maps_router'; | ||
|
||
export const unsavedChangesWarning = i18n.translate( | ||
'xpack.maps.breadCrumbs.unsavedChangesWarning', | ||
{ | ||
defaultMessage: 'Your map has unsaved changes. Are you sure you want to leave?', | ||
} | ||
); | ||
|
||
export function getBreadcrumbs({ | ||
title, | ||
getHasUnsavedChanges, | ||
originatingApp, | ||
getAppNameFromId, | ||
}: { | ||
title: string; | ||
getHasUnsavedChanges: () => boolean; | ||
originatingApp?: string; | ||
getAppNameFromId?: (id: string) => string; | ||
}) { | ||
const breadcrumbs = []; | ||
if (originatingApp && getAppNameFromId) { | ||
breadcrumbs.push({ | ||
onClick: () => { | ||
getNavigateToApp()(originatingApp); | ||
}, | ||
text: getAppNameFromId(originatingApp), | ||
}); | ||
} | ||
|
||
breadcrumbs.push({ | ||
text: i18n.translate('xpack.maps.mapController.mapsBreadcrumbLabel', { | ||
defaultMessage: 'Maps', | ||
}), | ||
onClick: () => { | ||
if (getHasUnsavedChanges()) { | ||
const navigateAway = window.confirm(unsavedChangesWarning); | ||
if (navigateAway) { | ||
goToSpecifiedPath('/'); | ||
} | ||
} else { | ||
goToSpecifiedPath('/'); | ||
} | ||
}, | ||
}); | ||
|
||
breadcrumbs.push({ text: title }); | ||
|
||
return breadcrumbs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters