-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from bento-platform/feat/katsu-config
feat(discovery): scoped discovery config forms
- Loading branch information
Showing
34 changed files
with
639 additions
and
318 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,49 @@ | ||
import PropTypes from "prop-types"; | ||
|
||
import { Form, Input } from "antd"; | ||
import { useMemo } from "react"; | ||
|
||
const { Item } = Form; | ||
|
||
import DataUseInput from "../DataUseInput"; | ||
|
||
import { DATA_USE_PROP_TYPE_SHAPE, INITIAL_DATA_USE_VALUE } from "@/duo"; | ||
import { useDatsValidator } from "@/hooks"; | ||
import { useDiscoveryValidator } from "@/modules/metadata/hooks"; | ||
import { simpleDeepCopy } from "@/utils/misc"; | ||
import DropBoxJsonSelect from "../manager/dropBox/DropBoxJsonSelect"; | ||
|
||
const validateJson = (rule, value) => { | ||
try { | ||
JSON.parse(value); | ||
return Promise.resolve(); | ||
} catch (e) { | ||
return Promise.reject("Please enter valid JSON"); | ||
} | ||
}; | ||
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), | ||
}; | ||
}, [initialValue]); | ||
|
||
const DatasetForm = ({ initialValue, formRef }) => { | ||
return ( | ||
<Form ref={formRef} layout="vertical"> | ||
<Item | ||
label="Title" | ||
name="title" | ||
initialValue={initialValue?.title || ""} | ||
rules={[{ required: true }, { min: 3 }]} | ||
> | ||
<Form form={form} layout="vertical" initialValues={initialFormData}> | ||
<Item label="Title" name="title" rules={[{ required: true }, { min: 3 }]}> | ||
<Input placeholder="My Dataset" size="large" /> | ||
</Item> | ||
<Item | ||
label="Description" | ||
name="description" | ||
initialValue={initialValue?.description || ""} | ||
rules={[{ required: true }]} | ||
> | ||
<Item label="Description" name="description" rules={[{ required: true }]}> | ||
<Input.TextArea placeholder="This is a dataset" /> | ||
</Item> | ||
<Item label="Contact Information" name="contact_info" initialValue={initialValue?.contact_info ?? ""}> | ||
<Item label="Contact Information" name="contact_info"> | ||
<Input.TextArea placeholder={"Name\[email protected]"} /> | ||
</Item> | ||
<Item | ||
label="DATS File" | ||
name="dats_file" | ||
initialValue={initialValue?.dats_file ? JSON.stringify(initialValue.dats_file, null, 2) : ""} | ||
rules={[{ required: true }, { validator: validateJson }, { min: 2 }]} | ||
> | ||
<Input.TextArea /> | ||
<Item label="DATS File" name="dats_file" rules={[{ required: true }, { validator: datsValidator }]}> | ||
<DropBoxJsonSelect initialValue={initialFormData?.dats_file} /> | ||
</Item> | ||
<Item label="Discovery Configuration" name="discovery" rules={[{ validator: discoveryValidator }]}> | ||
<DropBoxJsonSelect initialValue={initialFormData?.discovery} nullable={true} /> | ||
</Item> | ||
<Item | ||
label="Consent Code and Data Use Requirements" | ||
name="data_use" | ||
initialValue={initialValue?.data_use ?? simpleDeepCopy(INITIAL_DATA_USE_VALUE)} | ||
rules={[ | ||
{ required: true }, | ||
(rule, value, callback) => { | ||
|
@@ -75,8 +68,9 @@ DatasetForm.propTypes = { | |
contact_info: PropTypes.string, | ||
data_use: DATA_USE_PROP_TYPE_SHAPE, // TODO: Shared shape for data use | ||
dats_file: PropTypes.object, | ||
discovery: PropTypes.object, | ||
}), | ||
formRef: PropTypes.object, | ||
form: PropTypes.object, | ||
}; | ||
|
||
export default DatasetForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.