Skip to content

Commit 1de2ce7

Browse files
committed
feat: adjust clear button to undoable reset to default prefill
Closes #76
1 parent e88295e commit 1de2ce7

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

lib/components/Input/Input.jsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export default function Input({
1313
onSetInput,
1414
variablesForElement
1515
}) {
16-
const handleResetInput = () => {
17-
onResetInput();
18-
};
1916

2017
return (
2118
<div className="input">
@@ -28,8 +25,8 @@ export default function Input({
2825
</Link>
2926
<Link
3027
className="input__header--button-reset"
31-
onClick={ handleResetInput }
32-
role="button">Clear</Link>
28+
onClick={ onResetInput }
29+
role="button">Reset</Link>
3330
</div>
3431
<InputEditor
3532
allOutputs={ allOutputs }

lib/components/Input/InputEditor.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
22
import { renderToStaticMarkup } from 'react-dom/server';
33

44
import { autocompletion, closeBrackets } from '@codemirror/autocomplete';
5-
import { defaultKeymap } from '@codemirror/commands';
5+
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
66
import { bracketMatching, indentOnInput } from '@codemirror/language';
77
import { Compartment, EditorState, Annotation } from '@codemirror/state';
88
import { EditorView, keymap, placeholder } from '@codemirror/view';
@@ -100,8 +100,10 @@ export default function InputEditor({
100100
closeBrackets(),
101101
bracketMatching(),
102102
indentOnInput(),
103+
history(),
103104
keymap.of([
104-
...defaultKeymap
105+
...defaultKeymap,
106+
...historyKeymap
105107
]),
106108
new Compartment().of(json()),
107109
new Compartment().of(EditorState.tabSize.of(2)),

lib/utils/prefill.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { has, isObject, isString } from 'min-dash';
22

3-
export const DEFAULT_INPUT_CONFIG = '{}';
3+
export const DEFAULT_INPUT_CONFIG = '{\n \n}';
44

55

66
/**

test/ElementConfig.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('ElementConfig', function() {
112112
// then
113113
const inputConfigForElement = elementConfig.getInputConfigForElement(element);
114114

115-
expect(inputConfigForElement).to.eql('{}');
115+
expect(inputConfigForElement).to.eql('{\n \n}');
116116

117117
expect(spy).to.have.been.calledOnce;
118118
}));
@@ -195,7 +195,7 @@ describe('ElementConfig', function() {
195195
const inputConfigForElement = elementConfig.getInputConfigForElement(element);
196196

197197
// then
198-
expect(inputConfigForElement).to.eql('{}');
198+
expect(inputConfigForElement).to.eql('{\n \n}');
199199
}));
200200

201201
});

test/components/Input/Input.spec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ function renderWithProps(props) {
3838
const {
3939
element = elementRegistry.get('ServiceTask_1'),
4040
input = '{}',
41-
setInput = () => {},
42-
reset = () => {},
41+
onSetInput = () => {},
42+
onResetInput = () => {},
43+
onErrorChange = () => {},
4344
variablesForElement,
4445
output,
4546
onRunTask = () => {}
@@ -49,8 +50,9 @@ function renderWithProps(props) {
4950
<Input
5051
element={ element }
5152
input={ input }
52-
setInput={ setInput }
53-
reset={ reset }
53+
onSetInput={ onSetInput }
54+
onResetInput={ onResetInput }
55+
onErrorChange={ onErrorChange }
5456
variablesForElement={ variablesForElement }
5557
output={ output }
5658
onRunTask={ onRunTask }

0 commit comments

Comments
 (0)