Skip to content

Commit

Permalink
[ML] fix forceInput
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Mar 13, 2020
1 parent 44cc41b commit 6b7d0bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const CreateAnalyticsAdvancedEditor: FC<CreateAnalyticsFormProps> = ({ ac
jobIdValid,
} = state.form;

let myInput: any = useRef();
const forceInput = useRef<HTMLInputElement | null>(null);

const onChange = (str: string) => {
setAdvancedEditorRawString(str);
Expand All @@ -55,9 +55,12 @@ export const CreateAnalyticsAdvancedEditor: FC<CreateAnalyticsFormProps> = ({ ac

// Temp effect to close the context menu popover on Clone button click
useEffect(() => {
if (forceInput.current === null) {
return;
}
const evt = document.createEvent('MouseEvents');
evt.initEvent('mouseup', true, true);
myInput.dispatchEvent(evt);
forceInput.current.dispatchEvent(evt);
}, []);

return (
Expand Down Expand Up @@ -109,7 +112,7 @@ export const CreateAnalyticsAdvancedEditor: FC<CreateAnalyticsFormProps> = ({ ac
<EuiFieldText
inputRef={input => {
if (input) {
myInput = input;
forceInput.current = input;
}
}}
disabled={isJobCreated}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
const mlContext = useMlContext();
const { form, indexPatternsMap, isAdvancedEditorEnabled, isJobCreated, requestMessages } = state;

let myInput: any = useRef(null);
const forceInput = useRef<HTMLInputElement | null>(null);

const {
createIndexPattern,
Expand Down Expand Up @@ -335,9 +335,12 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta

// Temp effect to close the context menu popover on Clone button click
useEffect(() => {
if (forceInput.current === null) {
return;
}
const evt = document.createEvent('MouseEvents');
evt.initEvent('mouseup', true, true);
myInput.dispatchEvent(evt);
forceInput.current.dispatchEvent(evt);
}, []);

return (
Expand Down Expand Up @@ -409,7 +412,7 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
<EuiFieldText
inputRef={input => {
if (input) {
myInput = input;
forceInput.current = input;
}
}}
disabled={isJobCreated}
Expand Down

0 comments on commit 6b7d0bf

Please sign in to comment.