import actionCreatorFactory from 'typescript-fsa' ; import { reducerWithInitialState } from 'typescript-fsa-reducers' ; import { select , takeLatest , call } from 'redux-saga/effects' ; import { i18n } from '@kbn/i18n' ; import { GraphState , GraphStoreDependencies } from './store' ; import { reset } from './global' ; import { setBreadcrumbs } from '../services/url' ; const actionCreator = actionCreatorFactory ( 'x-pack/graph/metaData' ) ; export interface MetaDataState { title : string ; description : string ; savedObjectId ? : string ; } export const updateMetaData = actionCreator < Partial < MetaDataState > > ( 'UPDATE_META_DATA' ) ; const initialMetaData = { title : i18n . translate ( 'xpack.graph.newGraphTitle' , { defaultMessage : 'Unsaved graph' , } ) , description : '' , } ; export const metaDataReducer = reducerWithInitialState ( initialMetaData ) . case ( reset , ( ) => initialMetaData ) . case ( updateMetaData , ( oldMetaData , newMetaData ) => ( { ... oldMetaData , ... newMetaData } ) ) . build ( ) ; export const metaDataSelector = ( state ) => state . metaData ; /**
 * Saga updating the breadcrumb when the shown workspace changes.
 */ export const syncBreadcrumbSaga = ( { chrome , changeUrl } ) => { function * syncBreadcrumb ( ) { const metaData = metaDataSelector ( yield select ( ) ) ; setBreadcrumbs ( { chrome , metaData , navigateTo : ( path ) => { changeUrl ( path ) ; } , } ) ; } return function * ( ) { yield call ( syncBreadcrumb ) ; yield takeLatest ( updateMetaData . match , syncBreadcrumb ) ; } ; } ;