@@ -123,6 +123,24 @@ export const UploadFileDragAndDrop: React.FC<UploadFileDragAndDropProps> = (
123123 } ) ;
124124 } ;
125125
126+ const checkIfMetadataNeeded = ( ) => {
127+ // This function checks if Step 1 to upload metadata is needed when users upload new file
128+ let required = false ;
129+
130+ metadataDefinitionList . forEach ( ( val , _ ) => {
131+ if ( val . required_for_items . files ) {
132+ val . fields . forEach ( ( field ) => {
133+ if ( field . required ) {
134+ required = true ;
135+ return ;
136+ }
137+ } ) ;
138+ }
139+ } ) ;
140+
141+ return required ;
142+ } ;
143+
126144 // step 1
127145 const setMetadata = ( metadata : any ) => {
128146 // TODO wrap this in to a function
@@ -184,32 +202,37 @@ export const UploadFileDragAndDrop: React.FC<UploadFileDragAndDropProps> = (
184202 < Stepper activeStep = { activeStep } orientation = "vertical" >
185203 { /*<Stepper activeStep={activeStep}>*/ }
186204 { /*step 1 Metadata*/ }
187- < Step key = "fill-in-metadata" >
188- < StepLabel > Fill In Metadata</ StepLabel >
189- < StepContent TransitionProps = { { unmountOnExit : false } } >
190- < Typography > Provide us the metadata about your file.</ Typography >
191- < Box >
192- < CreateMetadata
193- setMetadata = { setMetadata }
194- sourceItem = { "files" }
195- />
196- </ Box >
197- { /*buttons*/ }
198- < Grid container >
199- < Grid xs = { 11 } >
200- < Button
201- variant = "contained"
202- onClick = { handleNext }
203- disabled = { ! checkIfFieldsAreRequired ( ) ? false : ! allFilled }
204- sx = { { display : "block" , marginLeft : "auto" } }
205- >
206- Next
207- </ Button >
205+ { checkIfMetadataNeeded ( ) && (
206+ < Step key = "fill-in-metadata" >
207+ < StepLabel > Fill In Metadata</ StepLabel >
208+ < StepContent TransitionProps = { { unmountOnExit : false } } >
209+ < Typography >
210+ Provide us the metadata about your file.
211+ </ Typography >
212+ < Box >
213+ < CreateMetadata
214+ setMetadata = { setAllFilled }
215+ sourceItem = { "files" }
216+ />
217+ </ Box >
218+ < Grid container >
219+ < Grid item xs = { 11 } >
220+ < Button
221+ variant = "contained"
222+ onClick = { handleNext }
223+ disabled = {
224+ ! checkIfFieldsAreRequired ( ) ? false : ! allFilled
225+ }
226+ sx = { { display : "block" , marginLeft : "auto" } }
227+ >
228+ Next
229+ </ Button >
230+ </ Grid >
231+ < Grid item xs = { 1 } />
208232 </ Grid >
209- < Grid xs = { 1 } />
210- </ Grid >
211- </ StepContent >
212- </ Step >
233+ </ StepContent >
234+ </ Step >
235+ ) }
213236 { /* step 2 attach files */ }
214237 < Step key = "attach-files" >
215238 < StepLabel > Attach Files</ StepLabel >
@@ -224,9 +247,11 @@ export const UploadFileDragAndDrop: React.FC<UploadFileDragAndDropProps> = (
224247 selectedFiles = { selectedFiles }
225248 />
226249 < Box className = "inputGroup" >
227- < Button onClick = { handleBack } sx = { { float : "right" } } >
228- Back
229- </ Button >
250+ { checkIfMetadataNeeded ( ) && (
251+ < Button onClick = { handleBack } sx = { { float : "right" } } >
252+ Back
253+ </ Button >
254+ ) }
230255 < Button
231256 variant = "contained"
232257 onClick = { handleFinishMultiple }
0 commit comments