diff --git a/src/pages/StudyUpdateForm.js b/src/pages/StudyUpdateForm.js index 9c7710826..e1824b836 100644 --- a/src/pages/StudyUpdateForm.js +++ b/src/pages/StudyUpdateForm.js @@ -26,6 +26,7 @@ export const StudyUpdateForm = (props) => { const [institutions, setInstitutions] = useState([]); const [allConsentGroupsSaved, setAllConsentGroupsSaved] = useState(false); const [formFiles, setFormFiles] = useState({}); + const [datasetNames, setDatasetNames] = useState([]); const studyEditMode = true; useEffect(() => { @@ -34,9 +35,15 @@ export const StudyUpdateForm = (props) => { setInstitutions(institutions); }; + const getAllDatasetNames = async() => { + const datasetNames = await DataSet.getDatasetNames(); + setDatasetNames(datasetNames); + }; + const init = async () => { try { - getAllInstitutions(); + await getAllInstitutions(); + await getAllDatasetNames(); } catch (error) { setFailedInit(true); Notifications.showError({ @@ -243,7 +250,7 @@ export const StudyUpdateForm = (props) => { - +
Submit @@ -252,4 +259,4 @@ export const StudyUpdateForm = (props) => {
; }; -export default StudyUpdateForm; \ No newline at end of file +export default StudyUpdateForm; diff --git a/src/pages/data_submission/DataAccessGovernance.js b/src/pages/data_submission/DataAccessGovernance.js index 7c073fa22..655e9ba66 100644 --- a/src/pages/data_submission/DataAccessGovernance.js +++ b/src/pages/data_submission/DataAccessGovernance.js @@ -14,7 +14,8 @@ export const DataAccessGovernance = (props) => { validation, datasets, onValidationChange, - setAllConsentGroupsSaved + setAllConsentGroupsSaved, + datasetNames } = props; const [consentGroupsState, setConsentGroupsState] = useState([]); @@ -248,7 +249,8 @@ export const DataAccessGovernance = (props) => { validation: validation?.consentGroups?.at(idx) || {}, onValidationChange: (change) => { onValidationChange({ ...change, ...{ key: `consentGroups[${idx}].` + change.key } }); - } + }, + datasetNames: datasetNames }) ] ); @@ -276,4 +278,4 @@ export const DataAccessGovernance = (props) => { ]); }; -export default DataAccessGovernance; \ No newline at end of file +export default DataAccessGovernance; diff --git a/src/pages/data_submission/DataSubmissionForm.js b/src/pages/data_submission/DataSubmissionForm.js index f0f6c5c47..e5fbf3a0f 100644 --- a/src/pages/data_submission/DataSubmissionForm.js +++ b/src/pages/data_submission/DataSubmissionForm.js @@ -40,7 +40,7 @@ export const DataSubmissionForm = (props) => { setInstitutions(institutions); }; - const getAllStudies = async() => { + const getAllStudyNames = async() => { const studyNames = await Study.getStudyNames(); setStudyNames(studyNames); }; @@ -54,7 +54,7 @@ export const DataSubmissionForm = (props) => { try { await getRegistrationSchema(); await getAllInstitutions(); - await getAllStudies(); + await getAllStudyNames(); await getAllDatasetNames(); } catch (error) { setFailedInit(true); @@ -204,7 +204,7 @@ export const DataSubmissionForm = (props) => { - +
Submit @@ -215,4 +215,4 @@ export const DataSubmissionForm = (props) => {
; }; -export default DataSubmissionForm; \ No newline at end of file +export default DataSubmissionForm; diff --git a/src/pages/data_submission/consent_group/ConsentGroupErrors.js b/src/pages/data_submission/consent_group/ConsentGroupErrors.js index 4e0c33565..1dedcdce7 100644 --- a/src/pages/data_submission/consent_group/ConsentGroupErrors.js +++ b/src/pages/data_submission/consent_group/ConsentGroupErrors.js @@ -1,6 +1,6 @@ import { selectedPrimaryGroup } from './EditConsentGroup'; import { isNil, isEmpty } from 'lodash/fp'; -import { dateValidator } from '../../../components/forms/formValidation'; +import { dateValidator, uniqueValidator } from '../../../components/forms/formValidation'; import { FormValidators } from '../../../components/forms/forms'; const requiredError = { @@ -8,6 +8,11 @@ const requiredError = { failed: ['required'] }; +const uniqueError = { + valid: false, + failed: ['unique'] +}; + const invalidFormatError = (format) => { return { valid: false, @@ -15,7 +20,7 @@ const invalidFormatError = (format) => { }; }; -export const computeConsentGroupValidationErrors = (consentGroup) => { +export const computeConsentGroupValidationErrors = (consentGroup, datasetNames = []) => { const validation = {}; if (isNil(selectedPrimaryGroup(consentGroup))) { @@ -38,6 +43,10 @@ export const computeConsentGroupValidationErrors = (consentGroup) => { if (isNil(consentGroup.consentGroupName) || consentGroup.consentGroupName === '') { validation.consentGroupName = requiredError; + } else { + if (!uniqueValidator.isValid(consentGroup.consentGroupName, datasetNames)) { + validation.consentGroupName = uniqueError; + } } if (isNil(consentGroup.dataLocation) || consentGroup.dataLocation === '') { diff --git a/src/pages/data_submission/consent_group/ConsentGroupForm.js b/src/pages/data_submission/consent_group/ConsentGroupForm.js index d177dad85..b4a3b9659 100644 --- a/src/pages/data_submission/consent_group/ConsentGroupForm.js +++ b/src/pages/data_submission/consent_group/ConsentGroupForm.js @@ -13,7 +13,8 @@ export const ConsentGroupForm = (props) => { deleteConsentGroup, disableDelete, consentGroupsState, - studyEditMode + studyEditMode, + datasetNames } = props; const curConsentGroup = consentGroupsState[idx].consentGroup; @@ -144,7 +145,7 @@ export const ConsentGroupForm = (props) => { type: 'button', isRendered: editMode, onClick: () => { - const errors = computeConsentGroupValidationErrors(consentGroup); + const errors = computeConsentGroupValidationErrors(consentGroup, datasetNames); const valid = isEmpty(errors); setValidation(errors); @@ -161,4 +162,4 @@ export const ConsentGroupForm = (props) => { ]); }; -export default ConsentGroupForm; \ No newline at end of file +export default ConsentGroupForm;