-
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 #437 from bento-platform/style/drop-box-json-input
refact: new drop box JSON select form input + fixed JSON type
- Loading branch information
Showing
13 changed files
with
194 additions
and
179 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -10,9 +10,9 @@ 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/DropBoxTreeSelect"; | ||
import DropBoxJsonSelect from "../manager/dropBox/DropBoxJsonSelect"; | ||
|
||
const DatasetForm = ({ initialValue, form, updateMode }) => { | ||
const DatasetForm = ({ initialValue, form }) => { | ||
const discoveryValidator = useDiscoveryValidator(); | ||
const datsValidator = useDatsValidator(); | ||
if (initialValue && !initialValue?.data_use) { | ||
|
@@ -29,28 +29,12 @@ const DatasetForm = ({ initialValue, form, updateMode }) => { | |
<Item label="Contact Information" name="contact_info"> | ||
<Input.TextArea placeholder={"Name\[email protected]"} /> | ||
</Item> | ||
<DropBoxJsonSelect | ||
name="dats_file" | ||
initialValue={initialValue?.dats_file} | ||
labels={{ | ||
parent: "DATS", | ||
select: "DATS file", | ||
defaultContent: "DATS data", | ||
updatedContent: updateMode ? "New DATS data" : "DATS data", | ||
}} | ||
rules={[{ required: true }, { validator: datsValidator }]} | ||
/> | ||
<DropBoxJsonSelect | ||
name="discovery" | ||
initialValue={initialValue?.discovery} | ||
labels={{ | ||
parent: "Public Discovery Configuration", | ||
select: "Config file", | ||
defaultContent: "Discovery config", | ||
updatedContent: updateMode ? "New discovery config" : "Discovery config", | ||
}} | ||
rules={[{ validator: discoveryValidator }]} | ||
/> | ||
<Item label="DATS File" name="dats_file" rules={[{ required: true }, { validator: datsValidator }]}> | ||
<DropBoxJsonSelect initialValue={initialValue?.dats_file} /> | ||
</Item> | ||
<Item label="Discovery Configuration" name="discovery" rules={[{ validator: discoveryValidator }]}> | ||
<DropBoxJsonSelect initialValue={initialValue?.discovery} /> | ||
</Item> | ||
<Item | ||
label="Consent Code and Data Use Requirements" | ||
name="data_use" | ||
|
@@ -81,7 +65,6 @@ DatasetForm.propTypes = { | |
discovery: PropTypes.object, | ||
}), | ||
form: PropTypes.object, | ||
updateMode: PropTypes.bool, | ||
}; | ||
|
||
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useEffect, useState } from "react"; | ||
import { Radio } from "antd"; | ||
|
||
import { BENTO_DROP_BOX_FS_BASE_PATH } from "@/config"; | ||
import { useDropBoxJsonContent } from "@/modules/dropBox/hooks"; | ||
import { dropBoxTreeNodeEnabledJson } from "@/utils/files"; | ||
|
||
import DropBoxTreeSelect from "./DropBoxTreeSelect"; | ||
import JsonDisplay from "@/components/display/JsonDisplay"; | ||
import type { JSONType } from "@/types/json"; | ||
|
||
const InnerDropBoxJsonSelect = ({ | ||
selectedFile, | ||
setSelectedFile, | ||
}: { | ||
selectedFile?: string; | ||
setSelectedFile: (x: string) => void; | ||
}) => { | ||
return ( | ||
<DropBoxTreeSelect | ||
basePrefix={BENTO_DROP_BOX_FS_BASE_PATH} | ||
multiple={false} | ||
nodeEnabled={dropBoxTreeNodeEnabledJson} | ||
allowClear={true} | ||
value={selectedFile} | ||
onChange={(v) => setSelectedFile(v)} | ||
/> | ||
); | ||
}; | ||
|
||
export type DropBoxJsonSelectProps = { | ||
initialValue?: JSONType; | ||
value?: JSONType; | ||
onChange?: (x: JSONType) => void; | ||
}; | ||
|
||
/** A form input component for DropBox JSON file selection. */ | ||
const DropBoxJsonSelect = ({ initialValue, onChange }: DropBoxJsonSelectProps) => { | ||
const editing = initialValue !== undefined; | ||
|
||
const [radioValue, setRadioValue] = useState<"existing" | "new">(editing ? "existing" : "new"); | ||
const [selectedFile, setSelectedFile] = useState<string | undefined>(undefined); | ||
|
||
const currentFieldData = useDropBoxJsonContent(selectedFile, null); | ||
|
||
useEffect(() => { | ||
if (onChange) { | ||
onChange(radioValue === "new" ? currentFieldData : initialValue ?? null); | ||
} | ||
}, [currentFieldData, initialValue, onChange, radioValue]); | ||
|
||
return ( | ||
<div style={{ display: "flex", flexDirection: "column", gap: 6 }}> | ||
{editing && ( | ||
<Radio.Group value={radioValue} onChange={(e) => setRadioValue(e.target.value)}> | ||
<Radio value="existing">Existing value</Radio> | ||
<Radio value="new">New value from file</Radio> | ||
</Radio.Group> | ||
)} | ||
|
||
{radioValue === "new" && <InnerDropBoxJsonSelect selectedFile={selectedFile} setSelectedFile={setSelectedFile} />} | ||
|
||
{(radioValue !== "new" || selectedFile) && ( | ||
<JsonDisplay | ||
showObjectWithReactJson={true} | ||
jsonSrc={radioValue === "new" ? currentFieldData : initialValue} | ||
showArrayTitle={false} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default DropBoxJsonSelect; |
Oops, something went wrong.