From cbc26c907d1557be742adbc1c5c6c87386138d94 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 11 Sep 2024 16:45:09 -0400 Subject: [PATCH 1/3] fix(manager): dataset edit keeping old form values --- src/components/datasets/DatasetForm.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/datasets/DatasetForm.js b/src/components/datasets/DatasetForm.js index 9e9f1c53..15c2803c 100644 --- a/src/components/datasets/DatasetForm.js +++ b/src/components/datasets/DatasetForm.js @@ -1,7 +1,7 @@ import PropTypes from "prop-types"; import { Form, Input } from "antd"; -import { useMemo } from "react"; +import { useEffect, useMemo } from "react"; const { Item } = Form; @@ -17,13 +17,20 @@ const DatasetForm = ({ initialValue, form }) => { const discoveryValidator = useDiscoveryValidator(); const datsValidator = useDatsValidator(); - const initialFormData = useMemo(() => { - return { - ...initialValue, - data_use: initialValue?.data_use ?? simpleDeepCopy(INITIAL_DATA_USE_VALUE), - }; + // If the initial value changes (and is truthy), i.e., the dataset being edited has changed, then reset the form. + // This lets it be re-populated from the initialFormData object below. + useEffect(() => { + if (initialValue) { + form.resetFields(); + } }, [initialValue]); + const initialFormData = useMemo(() => ({ + ...(initialValue ?? {}), + // TODO: the input should populate its own initial value + data_use: initialValue?.data_use ?? simpleDeepCopy(INITIAL_DATA_USE_VALUE), + }), [initialValue]); + return (
From 8ab8f6e1a57c0b2c79d2cb2c7d23ad1e6dbd83db Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 11 Sep 2024 16:46:43 -0400 Subject: [PATCH 2/3] lint --- src/components/datasets/DatasetForm.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/datasets/DatasetForm.js b/src/components/datasets/DatasetForm.js index 15c2803c..3833b920 100644 --- a/src/components/datasets/DatasetForm.js +++ b/src/components/datasets/DatasetForm.js @@ -25,11 +25,14 @@ const DatasetForm = ({ initialValue, form }) => { } }, [initialValue]); - const initialFormData = useMemo(() => ({ - ...(initialValue ?? {}), - // TODO: the input should populate its own initial value - data_use: initialValue?.data_use ?? simpleDeepCopy(INITIAL_DATA_USE_VALUE), - }), [initialValue]); + const initialFormData = useMemo( + () => ({ + ...(initialValue ?? {}), + // TODO: the input should populate its own initial value + data_use: initialValue?.data_use ?? simpleDeepCopy(INITIAL_DATA_USE_VALUE), + }), + [initialValue], + ); return ( From 24bcec748ec480ac0ea36ea977fa9c5ba007b3e4 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Wed, 11 Sep 2024 16:48:14 -0400 Subject: [PATCH 3/3] lint: fix missing hook dependency --- src/components/datasets/DatasetForm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/datasets/DatasetForm.js b/src/components/datasets/DatasetForm.js index 3833b920..694e9226 100644 --- a/src/components/datasets/DatasetForm.js +++ b/src/components/datasets/DatasetForm.js @@ -23,7 +23,7 @@ const DatasetForm = ({ initialValue, form }) => { if (initialValue) { form.resetFields(); } - }, [initialValue]); + }, [form, initialValue]); const initialFormData = useMemo( () => ({