From f09d50130b7becad1ce8499cdd4256ec403077a2 Mon Sep 17 00:00:00 2001 From: Stefano Ricci Date: Fri, 22 Sep 2023 14:49:32 +0200 Subject: [PATCH] code cleanup --- webapp/components/modal.js | 19 +++++++++++++++++-- .../ImportSummary/ImportSummary.js | 13 +++++++------ .../components/nodeDefEntitySelectorDialog.js | 11 +++++++---- .../components/nodeDefMultipleEditDialog.js | 6 ++---- webapp/views/App/JobMonitor/JobMonitor.js | 8 ++------ .../RecordsCloneModal/RecordsCloneModal.js | 8 ++------ .../Routes/DialogConfirm/DialogConfirm.js | 13 ++++++------- 7 files changed, 43 insertions(+), 35 deletions(-) diff --git a/webapp/components/modal.js b/webapp/components/modal.js index cc83824204..b70638d082 100644 --- a/webapp/components/modal.js +++ b/webapp/components/modal.js @@ -6,6 +6,7 @@ import MuiModal from '@mui/material/Modal' import Fade from '@mui/material/Fade' import { TestId } from '@webapp/utils/testId' +import { useI18n } from '@webapp/store/system' export const ModalClose = ({ _children, onClose }) => (
onClose()}> @@ -20,7 +21,9 @@ export const ModalBody = ({ children }) =>
{children export const ModalFooter = ({ children }) =>
{children}
export const Modal = (props) => { - const { children, className, closeOnEsc, onClose: onCloseProp } = props + const { children, className, closeOnEsc, onClose: onCloseProp, showCloseButton, title, titleParams } = props + + const i18n = useI18n() const onClose = useCallback( (event) => { @@ -38,7 +41,15 @@ export const Modal = (props) => { open > -
{children}
+
+ {(title || showCloseButton) && ( + + {title && {i18n.t(title, titleParams)}} + {showCloseButton && } + + )} + {children} +
) @@ -49,9 +60,13 @@ Modal.propTypes = { className: PropTypes.string, closeOnEsc: PropTypes.bool, onClose: PropTypes.func, + title: PropTypes.string, + titleParams: PropTypes.object, + showCloseButton: PropTypes.bool, } Modal.defaultProps = { className: '', closeOnEsc: true, + showCloseButton: false, } diff --git a/webapp/components/survey/CategoryDetails/ImportSummary/ImportSummary.js b/webapp/components/survey/CategoryDetails/ImportSummary/ImportSummary.js index 8c1cc6570d..6d3b378743 100644 --- a/webapp/components/survey/CategoryDetails/ImportSummary/ImportSummary.js +++ b/webapp/components/survey/CategoryDetails/ImportSummary/ImportSummary.js @@ -5,7 +5,7 @@ import PropTypes from 'prop-types' import * as CategoryImportSummary from '@core/survey/categoryImportSummary' -import { Modal, ModalBody, ModalClose, ModalFooter, ModalHeader } from '@webapp/components/modal' +import { Modal, ModalBody, ModalFooter } from '@webapp/components/modal' import { Button } from '@webapp/components/buttons' import { useI18n } from '@webapp/store/system' @@ -24,11 +24,12 @@ const ImportSummary = (props) => { const items = CategoryImportSummary.getItems(importSummary) return ( - - - {i18n.t('categoryEdit.importSummary.title')} - - +
diff --git a/webapp/components/survey/SurveyForm/nodeDefs/components/nodeDefEntitySelectorDialog.js b/webapp/components/survey/SurveyForm/nodeDefs/components/nodeDefEntitySelectorDialog.js index 21a53862bd..72f9e03f1a 100644 --- a/webapp/components/survey/SurveyForm/nodeDefs/components/nodeDefEntitySelectorDialog.js +++ b/webapp/components/survey/SurveyForm/nodeDefs/components/nodeDefEntitySelectorDialog.js @@ -8,7 +8,7 @@ import { useI18n } from '@webapp/store/system' import { useSurvey } from '@webapp/store/survey' import { Button } from '@webapp/components/buttons' -import { Modal, ModalBody, ModalFooter, ModalHeader } from '@webapp/components/modal' +import { Modal, ModalBody, ModalFooter } from '@webapp/components/modal' import { EntitySelector } from '@webapp/components/survey/NodeDefsSelector' import { FormItem } from '@webapp/components/form/Input' @@ -45,9 +45,12 @@ export const NodeDefEntitySelectorDialog = (props) => { !selectedEntityDefUuid || (isEntitySelectable && !isEntitySelectable?.(selectedEntityDefUuid)) return ( - - {i18n.t(title, { nodeDefName: NodeDef.getName(currentNodeDef) })} - + { const i18n = useI18n() return ( - - {label} - + {React.createElement(NodeDefUiProps.getComponent(nodeDef), props)} diff --git a/webapp/views/App/JobMonitor/JobMonitor.js b/webapp/views/App/JobMonitor/JobMonitor.js index 452a176cef..615ab5140b 100644 --- a/webapp/views/App/JobMonitor/JobMonitor.js +++ b/webapp/views/App/JobMonitor/JobMonitor.js @@ -5,11 +5,10 @@ import { useDispatch } from 'react-redux' import * as JobSerialized from '@common/job/jobSerialized' -import { useI18n } from '@webapp/store/system' import { useJob, JobActions } from '@webapp/store/app' import { Button } from '@webapp/components/buttons' -import { Modal, ModalBody, ModalFooter, ModalHeader } from '@webapp/components/modal' +import { Modal, ModalBody, ModalFooter } from '@webapp/components/modal' import InnerJobs from './InnerJobs' import JobErrors from './JobErrors' @@ -24,7 +23,6 @@ const getCustomCloseButtonComponent = ({ closeButton, job }) => { const JobMonitor = () => { const dispatch = useDispatch() - const i18n = useI18n() const { job, closeButton, errorKeyHeaderName, errorsExportFileName } = useJob() if (!job || JobSerialized.isCanceled(job)) return null @@ -34,9 +32,7 @@ const JobMonitor = () => { const jobEnded = JobSerialized.isEnded(job) return ( - - {i18n.t(`jobs.${JobSerialized.getType(job)}`)} - + { } return ( - - - {i18n.t('dataView.recordsClone.title')} - - + {cycleFromLabel} diff --git a/webapp/views/Arena/Routes/DialogConfirm/DialogConfirm.js b/webapp/views/Arena/Routes/DialogConfirm/DialogConfirm.js index c401f2dd50..eab26f8f75 100644 --- a/webapp/views/Arena/Routes/DialogConfirm/DialogConfirm.js +++ b/webapp/views/Arena/Routes/DialogConfirm/DialogConfirm.js @@ -6,7 +6,7 @@ import classNames from 'classnames' import { DialogConfirmActions, useDialogConfirm } from '@webapp/store/ui' -import { Modal, ModalBody, ModalFooter, ModalHeader } from '@webapp/components/modal' +import { Modal, ModalBody, ModalFooter } from '@webapp/components/modal' import { useI18n } from '@webapp/store/system' import Markdown from '@webapp/components/markdown' import { TestId } from '@webapp/utils/testId' @@ -29,12 +29,11 @@ const DialogConfirm = () => { } = useDialogConfirm() return key ? ( - dispatch(DialogConfirmActions.onDialogConfirmCancel())}> - {headerText && ( - -
{i18n.t(headerText)}
-
- )} + dispatch(DialogConfirmActions.onDialogConfirmCancel())} + title={headerText} + >