Skip to content

Commit

Permalink
add first level unique validation to consent group names
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong committed Oct 20, 2023
1 parent dc98e14 commit ef2de93
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
13 changes: 10 additions & 3 deletions src/pages/StudyUpdateForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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({
Expand Down Expand Up @@ -243,7 +250,7 @@ export const StudyUpdateForm = (props) => {
<NihAnvilUse onChange={onChange} formData={formData} validation={formValidation} onValidationChange={onValidationChange} studyEditMode={studyEditMode}/>
<NIHAdministrativeInformation institutions={institutions} onChange={onChange} formData={formData} validation={formValidation} onValidationChange={onValidationChange} studyEditMode={studyEditMode}/>
<NIHDataManagement onChange={onChange} onFileChange={onFileChange} formData={formData} validation={formValidation} onValidationChange={onValidationChange} studyEditMode={studyEditMode}/>
<DataAccessGovernance onChange={onChange} onFileChange={onFileChange} setAllConsentGroupsSaved={setAllConsentGroupsSaved} datasets={datasets} validation={formValidation} onValidationChange={onValidationChange} studyEditMode={studyEditMode}/>
<DataAccessGovernance onChange={onChange} onFileChange={onFileChange} setAllConsentGroupsSaved={setAllConsentGroupsSaved} datasets={datasets} validation={formValidation} onValidationChange={onValidationChange} studyEditMode={studyEditMode} datasetNames={datasetNames}/>

<div className='flex flex-row' style={{justifyContent: 'flex-end', marginBottom: '2rem'}}>
<a className='button button-white' onClick={submit}>Submit</a>
Expand All @@ -252,4 +259,4 @@ export const StudyUpdateForm = (props) => {
</div>;
};

export default StudyUpdateForm;
export default StudyUpdateForm;
8 changes: 5 additions & 3 deletions src/pages/data_submission/DataAccessGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const DataAccessGovernance = (props) => {
validation,
datasets,
onValidationChange,
setAllConsentGroupsSaved
setAllConsentGroupsSaved,
datasetNames
} = props;

const [consentGroupsState, setConsentGroupsState] = useState([]);
Expand Down Expand Up @@ -248,7 +249,8 @@ export const DataAccessGovernance = (props) => {
validation: validation?.consentGroups?.at(idx) || {},
onValidationChange: (change) => {
onValidationChange({ ...change, ...{ key: `consentGroups[${idx}].` + change.key } });
}
},
datasetNames: datasetNames
})
]
);
Expand Down Expand Up @@ -276,4 +278,4 @@ export const DataAccessGovernance = (props) => {
]);
};

export default DataAccessGovernance;
export default DataAccessGovernance;
8 changes: 4 additions & 4 deletions src/pages/data_submission/DataSubmissionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const DataSubmissionForm = (props) => {
setInstitutions(institutions);
};

const getAllStudies = async() => {
const getAllStudyNames = async() => {
const studyNames = await Study.getStudyNames();
setStudyNames(studyNames);
};
Expand All @@ -54,7 +54,7 @@ export const DataSubmissionForm = (props) => {
try {
await getRegistrationSchema();
await getAllInstitutions();
await getAllStudies();
await getAllStudyNames();
await getAllDatasetNames();
} catch (error) {
setFailedInit(true);
Expand Down Expand Up @@ -204,7 +204,7 @@ export const DataSubmissionForm = (props) => {
<NihAnvilUse onChange={onChange} formData={formData} validation={formValidation} onValidationChange={onValidationChange} studyEditMode={studyEditMode}/>
<NIHAdministrativeInformation formData={formData} onChange={onChange} institutions={institutions} validation={formValidation} onValidationChange={onValidationChange} studyEditMode={studyEditMode}/>
<NIHDataManagement formData={formData} onChange={onChange} onFileChange={onFileChange} validation={formValidation} onValidationChange={onValidationChange} studyEditMode={studyEditMode}/>
<DataAccessGovernance onChange={onChange} onFileChange={onFileChange} validation={formValidation} onValidationChange={onValidationChange} setAllConsentGroupsSaved={setAllConsentGroupsSaved} studyEditMode={studyEditMode}/>
<DataAccessGovernance onChange={onChange} onFileChange={onFileChange} validation={formValidation} onValidationChange={onValidationChange} setAllConsentGroupsSaved={setAllConsentGroupsSaved} studyEditMode={studyEditMode} datasetNames={datasetNames}/>

<div className='flex flex-row' style={{justifyContent: 'flex-end', marginBottom: '2rem'}}>
<a className='button button-white' onClick={submit}>Submit</a>
Expand All @@ -215,4 +215,4 @@ export const DataSubmissionForm = (props) => {
</div>;
};

export default DataSubmissionForm;
export default DataSubmissionForm;
13 changes: 11 additions & 2 deletions src/pages/data_submission/consent_group/ConsentGroupErrors.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
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 = {
valid: false,
failed: ['required']
};

const uniqueError = {
valid: false,
failed: ['unique']
};

const invalidFormatError = (format) => {
return {
valid: false,
failed: [format]
};
};

export const computeConsentGroupValidationErrors = (consentGroup) => {
export const computeConsentGroupValidationErrors = (consentGroup, datasetNames = []) => {
const validation = {};

if (isNil(selectedPrimaryGroup(consentGroup))) {
Expand All @@ -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 === '') {
Expand Down
7 changes: 4 additions & 3 deletions src/pages/data_submission/consent_group/ConsentGroupForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const ConsentGroupForm = (props) => {
deleteConsentGroup,
disableDelete,
consentGroupsState,
studyEditMode
studyEditMode,
datasetNames
} = props;

const curConsentGroup = consentGroupsState[idx].consentGroup;
Expand Down Expand Up @@ -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);
Expand All @@ -161,4 +162,4 @@ export const ConsentGroupForm = (props) => {
]);
};

export default ConsentGroupForm;
export default ConsentGroupForm;

0 comments on commit ef2de93

Please sign in to comment.