Skip to content

Commit

Permalink
remove 7.17 migration and harden inject method
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Feb 16, 2022
1 parent 387c585 commit 028b4b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
32 changes: 23 additions & 9 deletions x-pack/plugins/maps/common/embeddable/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { EmbeddableRegistryDefinition } from 'src/plugins/embeddable/server';
import { MapEmbeddablePersistableState } from './types';
import { MapSavedObjectAttributes } from '../map_saved_object_type';
import { injectReferences } from '../migrations/references';
import { extractReferences, injectReferences } from '../migrations/references';

export const inject: EmbeddableRegistryDefinition['inject'] = (state, references) => {
const typedState = state as MapEmbeddablePersistableState;
Expand All @@ -19,12 +19,26 @@ export const inject: EmbeddableRegistryDefinition['inject'] = (state, references
}

// by-value embeddable
const { attributes } = injectReferences({
attributes: typedState.attributes as MapSavedObjectAttributes,
references,
});
return {
...typedState,
attributes,
};
try {
// run embeddable state through extract logic to ensure any state with hard coded ids is replace with refNames
// refName generation will produce consistent values allowing inject logic to then replace refNames with current ids.
const { attributes: attributesWithNoHardCodedIds } = extractReferences({
attributes: typedState.attributes as MapSavedObjectAttributes,
});

const { attributes: attributesWithInjectedIds } = injectReferences({
attributes: attributesWithNoHardCodedIds,
references,
});
return {
...typedState,
attributes: attributesWithInjectedIds,
};
} catch (error) {
// inject exception prevents entire dashboard from display
// Instead of throwing, swallow error and let dashboard display
// Errors will surface in map panel. Any layer that failed injection will surface the error in the legend
// Users can then manually edit map to resolve any problems.
return typedState;
}
};
13 changes: 0 additions & 13 deletions x-pack/plugins/maps/server/embeddable_migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ export const embeddableMigrations = {
return state;
}
},
'7.17.1': (state: SerializableRecord) => {
try {
const { attributes } = extractReferences(state as { attributes: MapSavedObjectAttributes });
return {
...state,
attributes,
} as SerializableRecord;
} catch (e) {
// Do not failed migration
// Maps application can display error when viewed
return state;
}
},
'8.0.0': (state: SerializableRecord) => {
try {
return {
Expand Down

0 comments on commit 028b4b1

Please sign in to comment.