Skip to content

Commit

Permalink
Smart editor: Add logging for undefined type normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
eriksson-daniel committed Oct 14, 2024
1 parent 806adac commit 98933cb
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions frontend/src/plate/plugins/normalize-node.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LogLevel } from '@grafana/faro-web-sdk';
import {
PlateEditor,
TNode,
Expand Down Expand Up @@ -57,24 +58,36 @@ export const createNormalizeNodePlugin = createPluginFactory({

const parentEntry = getParentNode(editor, path);

const options = { context: { node: Scrubber.stringify(node), path: JSON.stringify(path) } };

if (parentEntry === undefined) {
pushLog('Missing node type, but no parent. Unable to normalize.', options, LogLevel.ERROR);

return normalizeNode([node, path]);
}

const [parentNode] = parentEntry;

if (!isElement(parentNode)) {
pushLog('Missing node type, but parent node is not element. Unable to normalize.', options, LogLevel.ERROR);

return normalizeNode([node, path]);
}

switch (parentNode.type) {
case ELEMENT_LI: {
pushLog('Normalized missing LIC', {
context: { node: Scrubber.stringify(node), path: JSON.stringify(path) },
});
pushLog('Normalized missing LIC', options);

return setNodes(editor, { type: ELEMENT_LIC }, { at: path, match: (n) => n === node });
}
default:
pushLog(
'Missing node type, but parent type was not LIC. Case not implemented.',
{ ...options, context: { ...options.context, parent: Scrubber.stringify(parentNode) } },
LogLevel.ERROR,
);

return normalizeNode([node, path]);
}
}

Expand Down

0 comments on commit 98933cb

Please sign in to comment.