Skip to content

Commit

Permalink
Support legacy text/x-red script type
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaCWebDeveloper committed Apr 24, 2024
1 parent 6c93d8e commit acd2e8f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions packages/flow-client/src/app/redux/modules/node/node.logic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,42 @@ describe('NodeLogic', () => {
})
);
});

it('updates editor templates from script tags with type text/x-red correctly', async () => {
const nodeScriptsData = `
<script type="text/x-red" data-template-name="x-red-test-node">
<div>X-Red Editor Template</div>
</script>
`;
const nodeLogic = new NodeLogic();
await nodeLogic.setNodeScripts(nodeScriptsData)(mockDispatch);

expect(mockDispatch).toHaveBeenCalledWith(
nodeActions.updateOne({
id: 'x-red-test-node',
changes: {
editorTemplate: '<div>X-Red Editor Template</div>',
},
})
);
});

it('updates help templates from script tags with type text/x-red correctly', async () => {
const nodeScriptsData = `
<script type="text/x-red" data-help-name="x-red-test-node">
<p>X-Red Help Template</p>
</script>
`;
const nodeLogic = new NodeLogic();
await nodeLogic.setNodeScripts(nodeScriptsData)(mockDispatch);

expect(mockDispatch).toHaveBeenCalledWith(
nodeActions.updateOne({
id: 'x-red-test-node',
changes: { helpTemplate: '<p>X-Red Help Template</p>' },
})
);
});
});

describe('applyConfigDefaults', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/flow-client/src/app/redux/modules/node/node.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class NodeLogic {

// Process text/html script tags for editor templates
doc.querySelectorAll(
'script[type="text/html"][data-template-name]'
'script[type="text/html"][data-template-name], script[type="text/x-red"][data-template-name]'
).forEach(script => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const nodeName = script.getAttribute('data-template-name')!;
Expand All @@ -54,7 +54,7 @@ export class NodeLogic {

// Process text/html script tags for help templates
doc.querySelectorAll(
'script[type="text/html"][data-help-name]'
'script[type="text/html"][data-help-name], script[type="text/x-red"][data-help-name]'
).forEach(script => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const nodeName = script.getAttribute('data-help-name')!;
Expand Down

0 comments on commit acd2e8f

Please sign in to comment.