Skip to content

Commit

Permalink
Merge pull request #1826 from epam/fix-schema-migration
Browse files Browse the repository at this point in the history
[Editor] Fix schema migration
  • Loading branch information
AlekseyManetov authored Dec 8, 2023
2 parents 4c85213 + adc24a7 commit cbf3c4c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions uui-editor/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const migrateTable = (oldTable: any) => {
const migrateElementNode = (node: any) => {
const mediaTypes = ['image', 'iframe'];

if (node.type === 'paragraph' && node.nodes?.[0].type === 'table') {
if (node.type === 'paragraph' && node.nodes?.[0]?.type === 'table') {
const tableNode = node.nodes[0];
node = migrateTable(tableNode);
}
Expand All @@ -62,5 +62,16 @@ export const migrateNode = (oldNode: any) => {
};

export const migrateSchema = (oldSchema: any) => {
return oldSchema?.document?.nodes.map(migrateNode) || oldSchema;
let migratedSchema;
try {
migratedSchema = oldSchema?.document?.nodes.map(migrateNode);
} catch (e) {
console.error("Can't migrate schema", e);
}

if (migratedSchema) {
return migratedSchema;
}

return oldSchema;
};

0 comments on commit cbf3c4c

Please sign in to comment.