-
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.
[Uptime] Fix breadcrumb for link back to monitor from waterfall page (#…
- Loading branch information
Showing
5 changed files
with
148 additions
and
24 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...blic/components/monitor/synthetics/step_detail/__tests__/use_monitor_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,82 @@ | ||
/* | ||
* 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 { ChromeBreadcrumb } from 'kibana/public'; | ||
import React from 'react'; | ||
import { Route } from 'react-router-dom'; | ||
import { of } from 'rxjs'; | ||
import { MountWithReduxProvider, mountWithRouter } from '../../../../../lib'; | ||
import { KibanaContextProvider } from '../../../../../../../../../src/plugins/kibana_react/public'; | ||
import { useMonitorBreadcrumb } from '../use_monitor_breadcrumb'; | ||
import { OVERVIEW_ROUTE } from '../../../../../../common/constants'; | ||
import { Ping } from '../../../../../../common/runtime_types/ping'; | ||
import { JourneyState } from '../../../../../state/reducers/journey'; | ||
|
||
describe('useMonitorBreadcrumbs', () => { | ||
it('sets the given breadcrumbs', () => { | ||
const [getBreadcrumbs, core] = mockCore(); | ||
|
||
const Component = () => { | ||
useMonitorBreadcrumb({ | ||
activeStep: { monitor: { id: 'test-monitor' } } as Ping, | ||
journey: { details: { timestamp: '2021-01-04T11:25:19.104Z' } } as JourneyState, | ||
}); | ||
return <>Step Water Fall</>; | ||
}; | ||
|
||
mountWithRouter( | ||
<MountWithReduxProvider> | ||
<KibanaContextProvider services={{ ...core }}> | ||
<Route path={OVERVIEW_ROUTE}> | ||
<Component /> | ||
</Route> | ||
</KibanaContextProvider> | ||
</MountWithReduxProvider> | ||
); | ||
|
||
expect(getBreadcrumbs()).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"href": "/app/uptime", | ||
"onClick": [Function], | ||
"text": "Uptime", | ||
}, | ||
Object { | ||
"href": "/app/uptime/monitor/dGVzdC1tb25pdG9y", | ||
"onClick": [Function], | ||
"text": "test-monitor", | ||
}, | ||
Object { | ||
"text": "Jan 4, 2021 @ 06:25:19.104", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); | ||
|
||
const mockCore: () => [() => ChromeBreadcrumb[], any] = () => { | ||
let breadcrumbObj: ChromeBreadcrumb[] = []; | ||
const get = () => { | ||
return breadcrumbObj; | ||
}; | ||
const core = { | ||
application: { | ||
getUrlForApp: () => '/app/uptime', | ||
navigateToUrl: jest.fn(), | ||
}, | ||
chrome: { | ||
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => { | ||
breadcrumbObj = newBreadcrumbs; | ||
}, | ||
}, | ||
uiSettings: { | ||
get: (key: string) => 'MMM D, YYYY @ HH:mm:ss.SSS', | ||
get$: (key: string) => of('MMM D, YYYY @ HH:mm:ss.SSS'), | ||
}, | ||
}; | ||
|
||
return [get, core]; | ||
}; |
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
38 changes: 38 additions & 0 deletions
38
...lugins/uptime/public/components/monitor/synthetics/step_detail/use_monitor_breadcrumb.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,38 @@ | ||
/* | ||
* 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 moment from 'moment'; | ||
import { useBreadcrumbs } from '../../../../hooks/use_breadcrumbs'; | ||
import { useKibana, useUiSetting$ } from '../../../../../../../../src/plugins/kibana_react/public'; | ||
import { JourneyState } from '../../../../state/reducers/journey'; | ||
import { Ping } from '../../../../../common/runtime_types/ping'; | ||
import { PLUGIN } from '../../../../../common/constants/plugin'; | ||
|
||
interface Props { | ||
journey: JourneyState; | ||
activeStep?: Ping; | ||
} | ||
|
||
export const useMonitorBreadcrumb = ({ journey, activeStep }: Props) => { | ||
const [dateFormat] = useUiSetting$<string>('dateFormat'); | ||
|
||
const kibana = useKibana(); | ||
const appPath = kibana.services.application?.getUrlForApp(PLUGIN.ID) ?? ''; | ||
|
||
useBreadcrumbs([ | ||
...(activeStep?.monitor | ||
? [ | ||
{ | ||
text: activeStep?.monitor?.name || activeStep?.monitor.id, | ||
href: `${appPath}/monitor/${btoa(activeStep?.monitor.id)}`, | ||
}, | ||
] | ||
: []), | ||
...(journey?.details?.timestamp | ||
? [{ text: moment(journey?.details?.timestamp).format(dateFormat) }] | ||
: []), | ||
]); | ||
}; |
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
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