@@ -15,9 +15,10 @@ import { loadFields, selectedFieldsSelector } from './fields';
1515import { updateSettings , settingsSelector } from './advanced_settings' ;
1616import { loadTemplates , templatesSelector } from './url_templates' ;
1717import {
18- lookupIndexPattern ,
18+ migrateLegacyIndexPatternRef ,
1919 savedWorkspaceToAppState ,
2020 appStateToSavedWorkspace ,
21+ lookupIndexPatternId ,
2122} from '../services/persistence' ;
2223import { updateMetaData , metaDataSelector } from './meta_data' ;
2324import { openSaveModal , SaveWorkspaceHandler } from '../services/save_modal' ;
@@ -43,23 +44,28 @@ export const loadingSaga = ({
4344 indexPatternProvider,
4445} : GraphStoreDependencies ) => {
4546 function * deserializeWorkspace ( action : Action < GraphWorkspaceSavedObject > ) {
46- const selectedIndex = lookupIndexPattern ( action . payload , indexPatterns ) ;
47- if ( ! selectedIndex ) {
47+ const workspacePayload = action . payload ;
48+ const migrationStatus = migrateLegacyIndexPatternRef ( workspacePayload , indexPatterns ) ;
49+ if ( ! migrationStatus . success ) {
4850 notifications . toasts . addDanger (
4951 i18n . translate ( 'xpack.graph.loadWorkspace.missingIndexPatternErrorMessage' , {
50- defaultMessage : 'Index pattern not found' ,
52+ defaultMessage : 'Index pattern "{name}" not found' ,
53+ values : {
54+ name : migrationStatus . missingIndexPattern ,
55+ } ,
5156 } )
5257 ) ;
5358 return ;
5459 }
5560
56- const indexPattern = yield call ( indexPatternProvider . get , selectedIndex . id ) ;
61+ const selectedIndexPatternId = lookupIndexPatternId ( workspacePayload ) ;
62+ const indexPattern = yield call ( indexPatternProvider . get , selectedIndexPatternId ) ;
5763 const initialSettings = settingsSelector ( yield select ( ) ) ;
5864
59- createWorkspace ( selectedIndex . attributes . title , initialSettings ) ;
65+ createWorkspace ( indexPattern . title , initialSettings ) ;
6066
6167 const { urlTemplates, advancedSettings, allFields } = savedWorkspaceToAppState (
62- action . payload ,
68+ workspacePayload ,
6369 indexPattern ,
6470 // workspace won't be null because it's created in the same call stack
6571 getWorkspace ( ) !
@@ -68,16 +74,16 @@ export const loadingSaga = ({
6874 // put everything in the store
6975 yield put (
7076 updateMetaData ( {
71- title : action . payload . title ,
72- description : action . payload . description ,
73- savedObjectId : action . payload . id ,
77+ title : workspacePayload . title ,
78+ description : workspacePayload . description ,
79+ savedObjectId : workspacePayload . id ,
7480 } )
7581 ) ;
7682 yield put (
7783 setDatasource ( {
7884 type : 'indexpattern' ,
79- id : selectedIndex . id ,
80- title : selectedIndex . attributes . title ,
85+ id : indexPattern . id ,
86+ title : indexPattern . title ,
8187 } )
8288 ) ;
8389 yield put ( loadFields ( allFields ) ) ;
0 commit comments