Skip to content

Commit a474208

Browse files
committed
feat: confirm input changes
1 parent 122f3c5 commit a474208

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,28 @@ function QueryEditor(props: QueryEditorProps) {
9898

9999
const isResultLoaded = Boolean(executeQuery.result);
100100

101+
const [inputValue, setInputValue] = React.useState<string>(executeQuery.input);
102+
103+
const propsChangeUserInput = props.changeUserInput;
104+
const changeInputValue = React.useCallback(
105+
(input: string) => {
106+
setInputValue(input);
107+
propsChangeUserInput({input});
108+
},
109+
[propsChangeUserInput],
110+
);
111+
112+
React.useEffect(() => {
113+
if (executeQuery.input !== inputValue) {
114+
const response = window.confirm('Input value will be lost. Continue?');
115+
if (response) {
116+
setInputValue(executeQuery.input);
117+
} else {
118+
changeInputValue(inputValue);
119+
}
120+
}
121+
}, [changeInputValue, executeQuery.input, inputValue]);
122+
101123
const [querySettings] = useQueryExecutionSettings();
102124
const enableTracingLevel = useTracingLevelOptionAvailable();
103125
const [lastQueryExecutionSettings, setLastQueryExecutionSettings] =
@@ -292,10 +314,6 @@ function QueryEditor(props: QueryEditorProps) {
292314
});
293315
};
294316

295-
const onChange = (newValue: string) => {
296-
props.changeUserInput({input: newValue});
297-
};
298-
299317
const onCollapseResultHandler = () => {
300318
dispatchResultVisibilityState(PaneVisibilityActionTypes.triggerCollapse);
301319
};
@@ -340,9 +358,9 @@ function QueryEditor(props: QueryEditorProps) {
340358
<div className={b('monaco')}>
341359
<MonacoEditor
342360
language={YQL_LANGUAGE_ID}
343-
value={executeQuery.input}
361+
value={inputValue}
344362
options={editorOptions}
345-
onChange={onChange}
363+
onChange={changeInputValue}
346364
editorDidMount={editorDidMount}
347365
theme={`vs-${theme}`}
348366
/>

0 commit comments

Comments
 (0)