44 * you may not use this file except in compliance with the Elastic License.
55 */
66
7- import React , { useEffect } from 'react' ;
7+ import React , { useEffect , useCallback } from 'react' ;
88import { Route , RouteComponentProps , Switch } from 'react-router-dom' ;
99import { FormattedMessage } from '@kbn/i18n/react' ;
1010import {
@@ -17,13 +17,16 @@ import {
1717 EuiTab ,
1818 EuiTabs ,
1919 EuiTitle ,
20+ EuiButton ,
2021} from '@elastic/eui' ;
22+ import { RuntimeField } from '../../../../../runtime_fields/public' ;
2123import { documentationService } from '../../services/documentation' ;
2224import { DataStreamList } from './data_stream_list' ;
2325import { IndexList } from './index_list' ;
2426import { TemplateList } from './template_list' ;
2527import { ComponentTemplateList } from '../../components/component_templates' ;
2628import { breadcrumbService } from '../../services/breadcrumbs' ;
29+ import { useAppContext } from '../../app_context' ;
2730
2831export enum Section {
2932 Indices = 'indices' ,
@@ -43,6 +46,8 @@ interface MatchParams {
4346 section : Section ;
4447}
4548
49+ const defaultRuntimeField : RuntimeField = { name : 'myField' , type : 'date' , script : 'test=123' } ;
50+
4651export const IndexManagementHome : React . FunctionComponent < RouteComponentProps < MatchParams > > = ( {
4752 match : {
4853 params : { section } ,
@@ -87,6 +92,19 @@ export const IndexManagementHome: React.FunctionComponent<RouteComponentProps<Ma
8792 history . push ( `/${ newSection } ` ) ;
8893 } ;
8994
95+ const {
96+ plugins : { runtimeFields } ,
97+ } = useAppContext ( ) ;
98+
99+ const onSaveRuntimeField = useCallback ( ( field : RuntimeField ) => {
100+ console . log ( 'Updated field' , field ) ;
101+ } , [ ] ) ;
102+
103+ const openRuntimeFieldEditor = useCallback ( async ( ) => {
104+ const { openEditor } = await runtimeFields . loadEditor ( ) ;
105+ openEditor ( { onSave : onSaveRuntimeField , defaultValue : defaultRuntimeField } ) ;
106+ } , [ onSaveRuntimeField , runtimeFields ] ) ;
107+
90108 useEffect ( ( ) => {
91109 breadcrumbService . setBreadcrumbs ( 'home' ) ;
92110 } , [ ] ) ;
@@ -117,6 +135,11 @@ export const IndexManagementHome: React.FunctionComponent<RouteComponentProps<Ma
117135 />
118136 </ EuiButtonEmpty >
119137 </ EuiFlexItem >
138+ < EuiFlexItem grow = { false } >
139+ < EuiButton onClick = { openRuntimeFieldEditor } fill >
140+ Create field
141+ </ EuiButton >
142+ </ EuiFlexItem >
120143 </ EuiFlexGroup >
121144 </ EuiTitle >
122145
0 commit comments