Skip to content

Commit 4f833f4

Browse files
committed
wip review comments
1 parent dcbe010 commit 4f833f4

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
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 & 4 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,7 +96,7 @@ 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
102102

@@ -108,7 +108,7 @@ export function JSFunctionField(props) {
108108
return () => {
109109
_sandbox.destroy();
110110
};
111-
}, [ iframeContainerId, functionDefinition, onChange, field, paramsDefinition, computeOn, interval, safeSetValue, clearValue, sandboxError ]);
111+
}, [ clearValue, functionDefinition, iframeContainerId, safeSetValue, sandboxError ]);
112112

113113
const prevParams = usePrevious(params);
114114
const prevSandbox = usePrevious(sandbox);
@@ -137,7 +137,7 @@ export function JSFunctionField(props) {
137137
return () => clearInterval(intervalId);
138138
}
139139

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

142142
return (
143143
<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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
2-
render
2+
render,
3+
waitFor
34
} from '@testing-library/preact/pure';
45

56
import { JSFunctionField } from '../../../../../src/render/components/form-fields/JSFunctionField';
@@ -43,14 +44,12 @@ describe('JSFunctionField', function() {
4344
};
4445

4546
// when
46-
act(() => {
47+
await act(() => {
4748
createJSFunctionField({ field, onChange: onChangeSpy, services });
4849
});
4950

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
51+
// then
52+
await waitFor(() => {
5453
expect(onChangeSpy).to.be.calledOnce;
5554
expect(onChangeSpy).to.be.calledWith({ field, value: 42 });
5655
});

0 commit comments

Comments
 (0)