From de622f2b84ff2b429eaf7e27a93d80ac42fce39e Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Fri, 20 Dec 2024 10:39:13 +0100 Subject: [PATCH] fix: clean up useEffect dependencies --- src/data-workspace/inputs/boolean-radios.js | 2 +- src/data-workspace/inputs/date-input.js | 2 +- src/data-workspace/inputs/datetime-input.js | 2 +- src/data-workspace/inputs/file-inputs.js | 2 +- src/data-workspace/inputs/generic-input.js | 11 +++++++---- src/data-workspace/inputs/long-text.js | 2 +- src/data-workspace/inputs/option-set.js | 2 +- src/data-workspace/inputs/true-only-checkbox.js | 2 +- 8 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/data-workspace/inputs/boolean-radios.js b/src/data-workspace/inputs/boolean-radios.js index 800622c32..f504b338b 100644 --- a/src/data-workspace/inputs/boolean-radios.js +++ b/src/data-workspace/inputs/boolean-radios.js @@ -27,7 +27,7 @@ export const BooleanRadios = ({ if (syncTouched) { setValueSynced(value === lastSyncedValue) } - }, [value, lastSyncedValue, syncTouched]) + }, [value, lastSyncedValue, syncTouched, setValueSynced]) const { mutate } = useSetDataValueMutation({ deId, cocId }) diff --git a/src/data-workspace/inputs/date-input.js b/src/data-workspace/inputs/date-input.js index f4388b1bb..28413a630 100644 --- a/src/data-workspace/inputs/date-input.js +++ b/src/data-workspace/inputs/date-input.js @@ -29,7 +29,7 @@ export const DateInput = ({ if (syncTouched) { setValueSynced(value === lastSyncedValue) } - }, [value, lastSyncedValue, syncTouched]) + }, [value, lastSyncedValue, syncTouched, setValueSynced]) const { data: userInfo } = useUserInfo() const keyUiLocale = userInfo?.settings?.keyUiLocale diff --git a/src/data-workspace/inputs/datetime-input.js b/src/data-workspace/inputs/datetime-input.js index 7b3ff76eb..92dc79be5 100644 --- a/src/data-workspace/inputs/datetime-input.js +++ b/src/data-workspace/inputs/datetime-input.js @@ -44,7 +44,7 @@ export const DateTimeInput = ({ const dateWithTime = convertToDateWithTime({ date, time }) setValueSynced(dateWithTime === lastSyncedValue) } - }, [date, time, lastSyncedValue, syncTouched]) + }, [date, time, lastSyncedValue, syncTouched, setValueSynced]) const { mutate } = useSetDataValueMutation({ deId, cocId }) diff --git a/src/data-workspace/inputs/file-inputs.js b/src/data-workspace/inputs/file-inputs.js index 140f6e18c..b22a4ebb7 100644 --- a/src/data-workspace/inputs/file-inputs.js +++ b/src/data-workspace/inputs/file-inputs.js @@ -45,7 +45,7 @@ export const FileResourceInput = ({ ) } } - }, [value, lastSyncedValue, syncTouched]) + }, [value, lastSyncedValue, syncTouched, setValueSynced]) const dataValueParams = useDataValueParams({ deId, cocId }) const fileLink = useFileInputUrl(dataValueParams) diff --git a/src/data-workspace/inputs/generic-input.js b/src/data-workspace/inputs/generic-input.js index 3e8b7316a..29935d458 100644 --- a/src/data-workspace/inputs/generic-input.js +++ b/src/data-workspace/inputs/generic-input.js @@ -63,7 +63,7 @@ export const GenericInput = ({ if (syncTouched) { setValueSynced(value === lastSyncedValue) } - }, [value, lastSyncedValue, syncTouched]) + }, [value, lastSyncedValue, syncTouched, setValueSynced]) const limits = useMinMaxLimits(deId, cocId) @@ -75,9 +75,12 @@ export const GenericInput = ({ // check if the initial value has any associated warnings useEffect(() => { - const warningValidationResult = warningValidator(value) - setWarning(fieldname, warningValidationResult) - }, [initialValue, warningValidator, setWarning, fieldname]) + // only check if the value has not been updated (i.e. is initial value) + if (!syncTouched) { + const warningValidationResult = warningValidator(value) + setWarning(fieldname, warningValidationResult) + } + }, [value, syncTouched, warningValidator, setWarning, fieldname]) const { mutate } = useSetDataValueMutation({ deId, cocId }) diff --git a/src/data-workspace/inputs/long-text.js b/src/data-workspace/inputs/long-text.js index b5c93ebe7..8d6be58f1 100644 --- a/src/data-workspace/inputs/long-text.js +++ b/src/data-workspace/inputs/long-text.js @@ -22,7 +22,7 @@ export const LongText = ({ if (syncTouched) { setValueSynced(value === lastSyncedValue) } - }, [value, lastSyncedValue, syncTouched]) + }, [value, lastSyncedValue, syncTouched, setValueSynced]) const { mutate } = useSetDataValueMutation({ deId, cocId }) const syncData = (newValue) => { diff --git a/src/data-workspace/inputs/option-set.js b/src/data-workspace/inputs/option-set.js index f3303fde5..3e872372c 100644 --- a/src/data-workspace/inputs/option-set.js +++ b/src/data-workspace/inputs/option-set.js @@ -78,7 +78,7 @@ export const OptionSet = ({ if (syncTouched) { setValueSynced(value === lastSyncedValue) } - }, [value, lastSyncedValue, syncTouched]) + }, [value, lastSyncedValue, syncTouched, setValueSynced]) const { mutate } = useSetDataValueMutation({ deId, cocId }) const syncData = (newValue) => { diff --git a/src/data-workspace/inputs/true-only-checkbox.js b/src/data-workspace/inputs/true-only-checkbox.js index a77038e60..b4bbf57f7 100644 --- a/src/data-workspace/inputs/true-only-checkbox.js +++ b/src/data-workspace/inputs/true-only-checkbox.js @@ -25,7 +25,7 @@ export const TrueOnlyCheckbox = ({ if (syncTouched) { setValueSynced(value === lastSyncedValue) } - }, [value, lastSyncedValue, syncTouched]) + }, [value, lastSyncedValue, syncTouched, setValueSynced]) const { mutate } = useSetDataValueMutation({ deId, cocId }) const syncData = (newValue) => {