Skip to content

Commit

Permalink
Workaround fix for cursor issue
Browse files Browse the repository at this point in the history
  • Loading branch information
spong committed Feb 9, 2023
1 parent c80f8b4 commit 1775e75
Showing 1 changed file with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const ContainerActions = styled.div.attrs(

export const RuleActionsField: React.FC<Props> = ({ field, messageVariables }) => {
const [fieldErrors, setFieldErrors] = useState<string | null>(null);
const [isInitializingAction, setIsInitializingAction] = useState(false);
const form = useFormContext();
const { isSubmitted, isSubmitting, isValid } = form;
const {
Expand All @@ -83,6 +84,9 @@ export const RuleActionsField: React.FC<Props> = ({ field, messageVariables }) =
const setActionIdByIndex = useCallback(
(id: string, index: number) => {
const updatedActions = [...(actions as Array<Partial<RuleAction>>)];
if (isEmpty(updatedActions[index].params)) {
setIsInitializingAction(true);
}
updatedActions[index] = deepMerge(updatedActions[index], { id });
field.setValue(updatedActions);
},
Expand All @@ -99,23 +103,28 @@ export const RuleActionsField: React.FC<Props> = ({ field, messageVariables }) =
// validation is not triggered correctly when actions params updated (more details in https://github.com/elastic/kibana/issues/142217)
// wrapping field.setValue in setTimeout fixes the issue above
// and triggers validation after params have been updated
setTimeout(
() =>
field.setValue((prevValue: RuleAction[]) => {
const updatedActions = [...prevValue];
updatedActions[index] = {
...updatedActions[index],
params: {
...updatedActions[index].params,
[key]: value,
},
};
return updatedActions;
}),
0
);
const updateValue = () => {
field.setValue((prevValue: RuleAction[]) => {
const updatedActions = [...prevValue];
updatedActions[index] = {
...updatedActions[index],
params: {
...updatedActions[index].params,
[key]: value,
},
};
return updatedActions;
});
};

if (isInitializingAction) {
setTimeout(updateValue, 0);
setIsInitializingAction(false);
} else {
updateValue();
}
},
[field]
[field, isInitializingAction]
);

const actionForm = useMemo(
Expand Down

0 comments on commit 1775e75

Please sign in to comment.