From 908c95639dea23bc2820cd945352eda0515ba42c Mon Sep 17 00:00:00 2001 From: Rida Abou-Haidar Date: Mon, 16 Dec 2024 12:18:37 -0500 Subject: [PATCH] add form element to modal added changes from lack of rebase updated formelement props modify uses of modal to avoid form nesting resolving lint --- jsx/Form.d.ts | 18 +-- jsx/Modal.tsx | 29 ++-- .../data_release/jsx/managePermissionsForm.js | 131 ++++++++-------- .../jsx/definefilters.importcsvmodal.tsx | 142 +++++++++--------- .../dataquery/jsx/welcome.adminquerymodal.tsx | 68 ++++----- .../dataquery/jsx/welcome.namequerymodal.tsx | 22 ++- 6 files changed, 203 insertions(+), 207 deletions(-) diff --git a/jsx/Form.d.ts b/jsx/Form.d.ts index 4b34465e99a..8c9ecd596c1 100644 --- a/jsx/Form.d.ts +++ b/jsx/Form.d.ts @@ -5,17 +5,17 @@ type formElement = { type: string }; type formElementProps = { - name: string - id: string - method: 'POST' | 'GET', - action: string - class: string - columns: number - formElements: {[elementName: string]: formElement} + name?: string + id?: string + method?: 'POST' | 'GET' = 'POST', + action?: string = '', + class?: string + columns?: number + formElements?: {[elementName: string]: formElement} onSubmit: (FormEvent) => void - onUserInput : (name: string, value: string) => void + onUserInput?: (name: string, value: string) => void children: ReactNode - fieUpload: boolean + fileUpload?: boolean = false }; /** * FormElement class. See Form.js diff --git a/jsx/Modal.tsx b/jsx/Modal.tsx index f21fb9e35a3..af283baea2d 100644 --- a/jsx/Modal.tsx +++ b/jsx/Modal.tsx @@ -3,6 +3,7 @@ import Swal from 'sweetalert2'; import Loader from './Loader'; import { ButtonElement, + FormElement, } from 'jsx/Form'; export type ModalProps = PropsWithChildren<{ @@ -88,11 +89,7 @@ const Modal = ({ */ const submitButton = () => { if (onSubmit && !(loading || success)) { // Show button if conditions met - return ( -
- -
- ); + return
; } }; @@ -195,6 +192,17 @@ const Modal = ({ ); + const content = ( + <> +
{show && children}
+
+ {loader} + {successDisplay} + {submitButton()} +
+ + ); + return (
e.stopPropagation()}> @@ -203,12 +211,11 @@ const Modal = ({ ×
-
{show && children}
-
- {loader} - {successDisplay} - {submitButton()} -
+ {onSubmit ? ( + + {content} + + ) : content}
diff --git a/modules/data_release/jsx/managePermissionsForm.js b/modules/data_release/jsx/managePermissionsForm.js index d98602a8856..59423c4fce8 100644 --- a/modules/data_release/jsx/managePermissionsForm.js +++ b/modules/data_release/jsx/managePermissionsForm.js @@ -4,7 +4,6 @@ import Loader from 'jsx/Loader'; import swal from 'sweetalert2'; import Modal from 'Modal'; import { - FormElement, CheckboxElement, StaticElement, SearchableDropdown, @@ -89,74 +88,72 @@ class ManagePermissionsForm extends Component { onClose={this.props.onClose} onSubmit={this.handleSubmit} > - - - {this.state.user && -
- - this.setFormData( - 'versionsByUser', { - userId: this.state.user, version, checked, - } - ) - } - />
-
- )} - /> - } - - {this.state.version && - { - if (user.versions.includes(this.state.version)) { - return
- - this.setFormData( - 'usersByVersion', - { - userId: user.id, - checked, - version: this.state.version, - } - ) - } - />
-
; + + {this.state.user && +
+ + this.setFormData( + 'versionsByUser', { + userId: this.state.user, version, checked, + } + ) } + />
+
+ )} + /> + } + + {this.state.version && + { + if (user.versions.includes(this.state.version)) { + return
+ + this.setFormData( + 'usersByVersion', + { + userId: user.id, + checked, + version: this.state.version, + } + ) + } + />
+
; } - )} - /> - } -
+ } + )} + /> + } ); } diff --git a/modules/dataquery/jsx/definefilters.importcsvmodal.tsx b/modules/dataquery/jsx/definefilters.importcsvmodal.tsx index f3bf52a8c70..56642d56174 100644 --- a/modules/dataquery/jsx/definefilters.importcsvmodal.tsx +++ b/modules/dataquery/jsx/definefilters.importcsvmodal.tsx @@ -127,80 +127,76 @@ function ImportCSVModal(props: { throwWarning={true} onClose={props.closeModal} onSubmit={submitPromise}> -
-
-
-
-
-
CSV containing list of
-
- setCSVType('candidate')} - /> Candidates - setCSVType('session')} - /> Sessions -
-
Candidate identifier type
-
setIdType('CandID')} - /> DCC ID - setIdType('PSCID')} - /> PSCID -
-
- Does CSV contain a header line? -
-
setCSVHeader(true)} - /> Yes - setCSVHeader(false)} - /> No -
-
CSV File
-
{ - setCSVFile(file); - const papaparseConfig: - Papa.ParseConfig = { - skipEmptyLines: true, - complete: csvParsed, - // Setting this to try would cause - // papaparse to return an object - // instead of string. We just skip - // the first row if the user says - // they have a header when parsing - // results. - header: false, - }; - // Only 1 column, papaparse can't detect - // the delimiter if it's not explicitly - // specified. - if (csvType == 'candidate') { - papaparseConfig.delimiter = ','; - } - Papa.parse(file, papaparseConfig); - } +
+
+
+
CSV containing list of
+
+ setCSVType('candidate')} + /> Candidates + setCSVType('session')} + /> Sessions +
+
Candidate identifier type
+
setIdType('CandID')} + /> DCC ID + setIdType('PSCID')} + /> PSCID +
+
+ Does CSV contain a header line? +
+
setCSVHeader(true)} + /> Yes + setCSVHeader(false)} + /> No +
+
CSV File
+
{ + setCSVFile(file); + const papaparseConfig: + Papa.ParseConfig = { + skipEmptyLines: true, + complete: csvParsed, + // Setting this to try would cause + // papaparse to return an object + // instead of string. We just skip + // the first row if the user says + // they have a header when parsing + // results. + header: false, + }; + // Only 1 column, papaparse can't detect + // the delimiter if it's not explicitly + // specified. + if (csvType == 'candidate') { + papaparseConfig.delimiter = ','; } - />
-
-
-
- -
+ Papa.parse(file, papaparseConfig); + } + } + /> + +
+ ; } diff --git a/modules/dataquery/jsx/welcome.adminquerymodal.tsx b/modules/dataquery/jsx/welcome.adminquerymodal.tsx index ff45d1c4bb4..ea7a839c5b9 100644 --- a/modules/dataquery/jsx/welcome.adminquerymodal.tsx +++ b/modules/dataquery/jsx/welcome.adminquerymodal.tsx @@ -68,41 +68,39 @@ function AdminQueryModal(props: { throwWarning={true} onClose={props.closeModal} onSubmit={submitPromise}> -
- - setQueryName(value) - } - /> - setTopQuery(value) - } - label='Pin Study Query' - /> - - setDashboardQuery(value) - } - /> - - setLoginQuery(value) - } - /> - -
+ + setQueryName(value) + } + /> + setTopQuery(value) + } + label='Pin Study Query' + /> + + setDashboardQuery(value) + } + /> + + setLoginQuery(value) + } + /> + ; } diff --git a/modules/dataquery/jsx/welcome.namequerymodal.tsx b/modules/dataquery/jsx/welcome.namequerymodal.tsx index 138ee981459..189e5ac880e 100644 --- a/modules/dataquery/jsx/welcome.namequerymodal.tsx +++ b/modules/dataquery/jsx/welcome.namequerymodal.tsx @@ -47,18 +47,16 @@ function NameQueryModal(props: { throwWarning={true} onClose={props.closeModal} onSubmit={submitPromise}> -
- - setQueryName(value) - } - /> - -
+ + setQueryName(value) + } + /> + ; }