Commit 95b8eac1 authored by Mohammad Nakhaee's avatar Mohammad Nakhaee
Browse files

Initialize the comment, references, and datasets correctly if the entries are partially selected

parent 78e5825c
Pipeline #135050 passed with stages
in 47 minutes and 51 seconds
......@@ -337,10 +337,27 @@ function EditMetaDataDialog({...props}) {
}
}, [api, user, raiseError, open, userDatasetsFetched, setUserDatasetsFetched])
const defaultComment = useMemo(() => entries?.length > 0 ? entries[0]?.entry_metadata?.comment || '' : '', [entries])
const defaultReferences = useMemo(() => entries?.length > 0 ? entries[0]?.entry_metadata?.references || [] : [], [entries])
const defaultDatasets = useMemo(() => entries?.length > 0 ? (entries[0]?.entry_metadata?.datasets ? userDatasets
.filter(datasetFullData => entries[0]?.entry_metadata?.datasets.map(dataset => dataset.dataset_id).includes(datasetFullData.dataset_id)) : []) : [], [entries, userDatasets])
const selectedEntriesObjects = useMemo(() => {
return selectedEntries.upload_id ? entries : entries.filter(entry => selectedEntries.entry_id.includes(entry?.entry_id))
}, [entries, selectedEntries.entry_id, selectedEntries.upload_id])
const defaultComment = useMemo(() => entries?.length > 0 ? selectedEntriesObjects[0]?.entry_metadata?.comment || '' : '', [entries])
const defaultReferences = useMemo(() => {
if (entries?.length < 0) {
return []
}
const referencesList = selectedEntriesObjects.map(entry => entry?.entry_metadata?.references).flat()
return referencesList.filter((value, index) => referencesList.indexOf(value) === index)
}, [entries.length, selectedEntriesObjects])
const defaultDatasets = useMemo(() => {
if (entries?.length < 0) {
return []
}
const datasetsList = selectedEntriesObjects.map(entry => entry?.entry_metadata?.datasets)
return userDatasets.filter(datasetFullData => datasetsList.flat().map(dataset => dataset.dataset_id).includes(datasetFullData.dataset_id))
}, [selectedEntriesObjects, entries.length, userDatasets])
const handleOpenDialog = useCallback(() => {
setActions([])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment