Skip to content

Commit

Permalink
Merge pull request #446 from bento-platform/fix/manager/dataset-edit
Browse files Browse the repository at this point in the history
fix(manager): dataset edit keeping old form values
  • Loading branch information
davidlougheed authored Sep 12, 2024
2 parents 2ffa3df + 24bcec7 commit 63ef45e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/components/datasets/DatasetForm.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -17,12 +17,22 @@ const DatasetForm = ({ initialValue, form }) => {
const discoveryValidator = useDiscoveryValidator();
const datsValidator = useDatsValidator();

const initialFormData = useMemo(() => {
return {
...initialValue,
// 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();
}
}, [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]);
}),
[initialValue],
);

return (
<Form form={form} layout="vertical" initialValues={initialFormData}>
Expand Down

0 comments on commit 63ef45e

Please sign in to comment.