Skip to content

Commit 75e7eb8

Browse files
committed
wip
1 parent 0af1659 commit 75e7eb8

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

packages/form-js-editor/src/render/components/editor-form-fields/EditorJSFunctionField.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const type = 'script';
55

66
export function EditorJSFunctionField(props) {
77
const { field } = props;
8-
const { jsFunction = '' } = field;
8+
const { jsFunction = '', key } = field;
99

1010
const Icon = iconsByType(type);
1111

1212
let placeholderContent = 'JS function is empty';
1313

1414
if (jsFunction.trim()) {
15-
placeholderContent = 'JS function';
15+
placeholderContent = `JS function for '${key}'`;
1616
}
1717

1818
return (

packages/form-js-viewer/src/render/components/form-fields/JSFunctionField.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function JSFunctionField(props) {
4343
try {
4444
value = JSON.parse(JSON.stringify(value));
4545
onChange({ field, value });
46-
} catch (e) {
46+
} catch {
4747
sandboxError('Unparsable return value');
4848
clearValue();
4949
}
@@ -96,19 +96,17 @@ export function JSFunctionField(props) {
9696
const iframe = iframeContainerRef.current.querySelector('iframe');
9797
iframe.removeAttribute('allow');
9898

99-
// (3) run user code in sandbox
99+
// (3) load user code in sandbox
100100
_sandbox.promise.then((sandboxInstance) => {
101101
sandboxInstance
102-
103-
// @ts-ignore
104102
.run(wrappedUserCode)
105103
.then(() => { setSandbox(sandboxInstance); setHasRunLoad(false); });
106104
});
107105

108106
return () => {
109107
_sandbox.destroy();
110108
};
111-
}, [ iframeContainerId, functionDefinition, onChange, field, paramsDefinition, computeOn, interval, safeSetValue, clearValue, sandboxError ]);
109+
}, [ clearValue, functionDefinition, iframeContainerId, safeSetValue, sandboxError ]);
112110

113111
const prevParams = usePrevious(params);
114112
const prevSandbox = usePrevious(sandbox);
@@ -137,7 +135,7 @@ export function JSFunctionField(props) {
137135
return () => clearInterval(intervalId);
138136
}
139137

140-
}, [ params, prevParams, sandbox, prevSandbox, onChange, field, computeOn, hasRunLoad, interval, clearValue, safeSetValue ]);
138+
}, [ params, prevParams, sandbox, prevSandbox, field, computeOn, hasRunLoad, interval, clearValue, safeSetValue ]);
141139

142140
return (
143141
<div ref={ iframeContainerRef } id={ iframeContainerId } className="fjs-sandbox-iframe-container"></div>
Lines changed: 1 addition & 3 deletions
Loading

packages/form-js-viewer/test/spec/render/components/form-fields/JSFunctionField.spec.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,13 @@ describe('JSFunctionField', function() {
4343
};
4444

4545
// when
46-
act(() => {
46+
await act(() => {
4747
createJSFunctionField({ field, onChange: onChangeSpy, services });
4848
});
4949

50-
// wait for the iframe to compute the expression and pass it back
51-
await new Promise(r => setTimeout(r, 100)).then(() => {
52-
53-
// then
54-
expect(onChangeSpy).to.be.calledOnce;
55-
expect(onChangeSpy).to.be.calledWith({ field, value: 42 });
56-
});
50+
// then
51+
expect(onChangeSpy).to.be.calledOnce;
52+
expect(onChangeSpy).to.be.calledWith({ field, value: 42 });
5753

5854
});
5955

0 commit comments

Comments
 (0)