-
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.
Make remaining route pages dynamic (React.lazy) to reduce app bundle.
- Loading branch information
1 parent
c24493c
commit d328894
Showing
9 changed files
with
236 additions
and
183 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
x-pack/plugins/ml/public/application/routing/routes/explorer/explorer.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 | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { FC } from 'react'; | ||
import React, { useMemo } from 'react'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { dynamic } from '@kbn/shared-ux-utility'; | ||
import { basicResolvers } from '../../resolvers'; | ||
import { ML_PAGES } from '../../../../locator'; | ||
import type { NavigateToPath } from '../../../contexts/kibana'; | ||
import { useMlKibana } from '../../../contexts/kibana'; | ||
|
||
import type { MlRoute, PageProps } from '../../router'; | ||
import { createPath, PageLoader } from '../../router'; | ||
import { useRouteResolver } from '../../use_resolver'; | ||
import { mlJobService } from '../../../services/job_service'; | ||
import { getDateFormatTz } from '../../../explorer/explorer_utils'; | ||
import { getBreadcrumbWithUrlForApp } from '../../breadcrumbs'; | ||
import { MlAnnotationUpdatesContext } from '../../../contexts/ml/ml_annotation_updates_context'; | ||
import { AnnotationUpdatesService } from '../../../services/annotations_service'; | ||
import { AnomalyExplorerContextProvider } from '../../../explorer/anomaly_explorer_context'; | ||
|
||
const ExplorerUrlStateManager = dynamic(async () => ({ | ||
default: (await import('./state_manager')).ExplorerUrlStateManager, | ||
})); | ||
|
||
export const explorerRouteFactory = ( | ||
navigateToPath: NavigateToPath, | ||
basePath: string | ||
): MlRoute => ({ | ||
id: 'explorer', | ||
path: createPath(ML_PAGES.ANOMALY_EXPLORER), | ||
title: i18n.translate('xpack.ml.anomalyDetection.anomalyExplorer.docTitle', { | ||
defaultMessage: 'Anomaly Explorer', | ||
}), | ||
render: (props, deps) => <PageWrapper {...props} deps={deps} />, | ||
breadcrumbs: [ | ||
getBreadcrumbWithUrlForApp('ML_BREADCRUMB', navigateToPath, basePath), | ||
getBreadcrumbWithUrlForApp('ANOMALY_DETECTION_BREADCRUMB', navigateToPath, basePath), | ||
{ | ||
text: i18n.translate('xpack.ml.anomalyDetection.anomalyExplorerLabel', { | ||
defaultMessage: 'Anomaly Explorer', | ||
}), | ||
}, | ||
], | ||
enableDatePicker: true, | ||
'data-test-subj': 'mlPageAnomalyExplorer', | ||
}); | ||
|
||
const PageWrapper: FC<PageProps> = () => { | ||
const { | ||
services: { | ||
mlServices: { mlApiServices }, | ||
}, | ||
} = useMlKibana(); | ||
|
||
const { context, results } = useRouteResolver('full', ['canGetJobs'], { | ||
...basicResolvers(), | ||
jobs: mlJobService.loadJobsWrapper, | ||
jobsWithTimeRange: () => mlApiServices.jobs.jobsWithTimerange(getDateFormatTz()), | ||
}); | ||
|
||
const annotationUpdatesService = useMemo(() => new AnnotationUpdatesService(), []); | ||
|
||
return ( | ||
<PageLoader context={context}> | ||
<MlAnnotationUpdatesContext.Provider value={annotationUpdatesService}> | ||
<AnomalyExplorerContextProvider> | ||
{results ? ( | ||
<ExplorerUrlStateManager jobsWithTimeRange={results.jobsWithTimeRange.jobs} /> | ||
) : null} | ||
</AnomalyExplorerContextProvider> | ||
</MlAnnotationUpdatesContext.Provider> | ||
</PageLoader> | ||
); | ||
}; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/ml/public/application/routing/routes/explorer/index.ts
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,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { explorerRouteFactory } from './explorer'; |
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
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
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/ml/public/application/routing/routes/timeseriesexplorer/index.ts
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,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { timeSeriesExplorerRouteFactory } from './timeseriesexplorer'; |
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
Oops, something went wrong.