1717 * under the License.
1818 */
1919
20- import React , { useEffect } from 'react' ;
20+ import React , { lazy , Suspense } from 'react' ;
2121import ReactDOM from 'react-dom' ;
22- import { HashRouter , Switch , Route , useParams , useLocation } from 'react-router-dom' ;
23- import { parse } from 'query-string' ;
24- import { get } from 'lodash' ;
25- import { i18n } from '@kbn/i18n' ;
22+ import { HashRouter , Switch , Route } from 'react-router-dom' ;
2623import { I18nProvider } from '@kbn/i18n/react' ;
27- import { CoreSetup , CoreStart , ChromeBreadcrumb , Capabilities } from 'src/core/public' ;
24+ import { EuiLoadingSpinner } from '@elastic/eui' ;
25+ import { CoreSetup , Capabilities } from 'src/core/public' ;
2826import { ManagementAppMountParams } from '../../../management/public' ;
29- import { DataPublicPluginStart } from '../../../data/public' ;
3027import { StartDependencies , SavedObjectsManagementPluginStart } from '../plugin' ;
31- import {
32- ISavedObjectsManagementServiceRegistry ,
33- SavedObjectsManagementActionServiceStart ,
34- } from '../services' ;
35- import { SavedObjectsTable } from './objects_table' ;
36- import { SavedObjectEdition } from './object_view' ;
28+ import { ISavedObjectsManagementServiceRegistry } from '../services' ;
3729import { getAllowedTypes } from './../lib' ;
3830
3931interface MountParams {
@@ -44,6 +36,8 @@ interface MountParams {
4436
4537let allowedObjectTypes : string [ ] | undefined ;
4638
39+ const SavedObjectsEditionPage = lazy ( ( ) => import ( './saved_objects_edition_page' ) ) ;
40+ const SavedObjectsTablePage = lazy ( ( ) => import ( './saved_objects_table_page' ) ) ;
4741export const mountManagementSection = async ( {
4842 core,
4943 mountParams,
@@ -63,23 +57,27 @@ export const mountManagementSection = async ({
6357 < Switch >
6458 < Route path = { '/:service/:id' } exact = { true } >
6559 < RedirectToHomeIfUnauthorized capabilities = { capabilities } >
66- < SavedObjectsEditionPage
67- coreStart = { coreStart }
68- serviceRegistry = { serviceRegistry }
69- setBreadcrumbs = { setBreadcrumbs }
70- />
60+ < Suspense fallback = { < EuiLoadingSpinner /> } >
61+ < SavedObjectsEditionPage
62+ coreStart = { coreStart }
63+ serviceRegistry = { serviceRegistry }
64+ setBreadcrumbs = { setBreadcrumbs }
65+ />
66+ </ Suspense >
7167 </ RedirectToHomeIfUnauthorized >
7268 </ Route >
7369 < Route path = { '/' } exact = { false } >
7470 < RedirectToHomeIfUnauthorized capabilities = { capabilities } >
75- < SavedObjectsTablePage
76- coreStart = { coreStart }
77- dataStart = { data }
78- serviceRegistry = { serviceRegistry }
79- actionRegistry = { pluginStart . actions }
80- allowedTypes = { allowedObjectTypes }
81- setBreadcrumbs = { setBreadcrumbs }
82- />
71+ < Suspense fallback = { < EuiLoadingSpinner /> } >
72+ < SavedObjectsTablePage
73+ coreStart = { coreStart }
74+ dataStart = { data }
75+ serviceRegistry = { serviceRegistry }
76+ actionRegistry = { pluginStart . actions }
77+ allowedTypes = { allowedObjectTypes }
78+ setBreadcrumbs = { setBreadcrumbs }
79+ />
80+ </ Suspense >
8381 </ RedirectToHomeIfUnauthorized >
8482 </ Route >
8583 </ Switch >
@@ -103,110 +101,3 @@ const RedirectToHomeIfUnauthorized: React.FunctionComponent<{
103101 }
104102 return children ! as React . ReactElement ;
105103} ;
106-
107- const SavedObjectsEditionPage = ( {
108- coreStart,
109- serviceRegistry,
110- setBreadcrumbs,
111- } : {
112- coreStart : CoreStart ;
113- serviceRegistry : ISavedObjectsManagementServiceRegistry ;
114- setBreadcrumbs : ( crumbs : ChromeBreadcrumb [ ] ) => void ;
115- } ) => {
116- const { service : serviceName , id } = useParams < { service : string ; id : string } > ( ) ;
117- const capabilities = coreStart . application . capabilities ;
118-
119- const { search } = useLocation ( ) ;
120- const query = parse ( search ) ;
121- const service = serviceRegistry . get ( serviceName ) ;
122-
123- useEffect ( ( ) => {
124- setBreadcrumbs ( [
125- {
126- text : i18n . translate ( 'savedObjectsManagement.breadcrumb.index' , {
127- defaultMessage : 'Saved objects' ,
128- } ) ,
129- href : '#/management/kibana/objects' ,
130- } ,
131- {
132- text : i18n . translate ( 'savedObjectsManagement.breadcrumb.edit' , {
133- defaultMessage : 'Edit {savedObjectType}' ,
134- values : { savedObjectType : service ?. service . type ?? 'object' } ,
135- } ) ,
136- } ,
137- ] ) ;
138- } , [ setBreadcrumbs , service ] ) ;
139-
140- return (
141- < SavedObjectEdition
142- id = { id }
143- serviceName = { serviceName }
144- serviceRegistry = { serviceRegistry }
145- savedObjectsClient = { coreStart . savedObjects . client }
146- overlays = { coreStart . overlays }
147- notifications = { coreStart . notifications }
148- capabilities = { capabilities }
149- notFoundType = { query . notFound as string }
150- />
151- ) ;
152- } ;
153-
154- const SavedObjectsTablePage = ( {
155- coreStart,
156- dataStart,
157- allowedTypes,
158- serviceRegistry,
159- actionRegistry,
160- setBreadcrumbs,
161- } : {
162- coreStart : CoreStart ;
163- dataStart : DataPublicPluginStart ;
164- allowedTypes : string [ ] ;
165- serviceRegistry : ISavedObjectsManagementServiceRegistry ;
166- actionRegistry : SavedObjectsManagementActionServiceStart ;
167- setBreadcrumbs : ( crumbs : ChromeBreadcrumb [ ] ) => void ;
168- } ) => {
169- const capabilities = coreStart . application . capabilities ;
170- const itemsPerPage = coreStart . uiSettings . get < number > ( 'savedObjects:perPage' , 50 ) ;
171-
172- useEffect ( ( ) => {
173- setBreadcrumbs ( [
174- {
175- text : i18n . translate ( 'savedObjectsManagement.breadcrumb.index' , {
176- defaultMessage : 'Saved objects' ,
177- } ) ,
178- href : '#/management/kibana/objects' ,
179- } ,
180- ] ) ;
181- } , [ setBreadcrumbs ] ) ;
182-
183- return (
184- < SavedObjectsTable
185- allowedTypes = { allowedTypes }
186- serviceRegistry = { serviceRegistry }
187- actionRegistry = { actionRegistry }
188- savedObjectsClient = { coreStart . savedObjects . client }
189- indexPatterns = { dataStart . indexPatterns }
190- search = { dataStart . search }
191- http = { coreStart . http }
192- overlays = { coreStart . overlays }
193- notifications = { coreStart . notifications }
194- applications = { coreStart . application }
195- perPageConfig = { itemsPerPage }
196- goInspectObject = { savedObject => {
197- const { editUrl } = savedObject . meta ;
198- if ( editUrl ) {
199- // previously, kbnUrl.change(object.meta.editUrl); was used.
200- // using direct access to location.hash seems the only option for now,
201- // as using react-router-dom will prefix the url with the router's basename
202- // which should be ignored there.
203- window . location . hash = editUrl ;
204- }
205- } }
206- canGoInApp = { savedObject => {
207- const { inAppUrl } = savedObject . meta ;
208- return inAppUrl ? get ( capabilities , inAppUrl . uiCapabilitiesPath ) : false ;
209- } }
210- />
211- ) ;
212- } ;
0 commit comments