Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manager): dataset edit keeping old form values #446

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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