Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SteRiccio committed Sep 22, 2023
1 parent 79f8b7d commit f09d501
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 35 deletions.
19 changes: 17 additions & 2 deletions webapp/components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
<div className="modal-close" onClick={() => onClose()}>
Expand All @@ -20,7 +21,9 @@ export const ModalBody = ({ children }) => <div className="modal-body">{children
export const ModalFooter = ({ children }) => <div className="modal-footer">{children}</div>

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) => {
Expand All @@ -38,7 +41,15 @@ export const Modal = (props) => {
open
>
<Fade in timeout={500}>
<div className="modal-content">{children}</div>
<div className="modal-content">
{(title || showCloseButton) && (
<ModalHeader>
{title && <span>{i18n.t(title, titleParams)}</span>}
{showCloseButton && <ModalClose onClose={onClose} />}
</ModalHeader>
)}
{children}
</div>
</Fade>
</MuiModal>
)
Expand All @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -24,11 +24,12 @@ const ImportSummary = (props) => {
const items = CategoryImportSummary.getItems(importSummary)

return (
<Modal className="category__import-summary" onClose={Actions.hideImportSummary}>
<ModalHeader>
<span>{i18n.t('categoryEdit.importSummary.title')}</span>
<ModalClose onClose={Actions.hideImportSummary} />
</ModalHeader>
<Modal
className="category__import-summary"
onClose={Actions.hideImportSummary}
showCloseButton
title="categoryEdit.importSummary.title"
>
<ModalBody>
<div className="table">
<div className="table__content">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -45,9 +45,12 @@ export const NodeDefEntitySelectorDialog = (props) => {
!selectedEntityDefUuid || (isEntitySelectable && !isEntitySelectable?.(selectedEntityDefUuid))

return (
<Modal className="survey-form__node-def-entity-selector-dialog" onClose={onClose}>
<ModalHeader>{i18n.t(title, { nodeDefName: NodeDef.getName(currentNodeDef) })}</ModalHeader>

<Modal
className="survey-form__node-def-entity-selector-dialog"
onClose={onClose}
title={title}
titleParams={{ nodeDefName: NodeDef.getName(currentNodeDef) }}
>
<ModalBody>
<FormItem label={i18n.t(entitySelectLabel)}>
<EntitySelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './nodeDefMultipleEditDialog.scss'
import React from 'react'

import { useI18n } from '@webapp/store/system'
import { Modal, ModalBody, ModalFooter, ModalHeader } from '@webapp/components/modal'
import { Modal, ModalBody, ModalFooter } from '@webapp/components/modal'

import * as NodeDefUiProps from '../nodeDefUIProps'

Expand All @@ -13,9 +13,7 @@ const NodeDefMultipleEditDialog = (props) => {
const i18n = useI18n()

return (
<Modal className="survey-form__node-def-multiple-edit-dialog" onClose={onClose}>
<ModalHeader>{label}</ModalHeader>

<Modal className="survey-form__node-def-multiple-edit-dialog" onClose={onClose} title={label}>
<ModalBody>{React.createElement(NodeDefUiProps.getComponent(nodeDef), props)}</ModalBody>

<ModalFooter>
Expand Down
8 changes: 2 additions & 6 deletions webapp/views/App/JobMonitor/JobMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -34,9 +32,7 @@ const JobMonitor = () => {
const jobEnded = JobSerialized.isEnded(job)

return (
<Modal className="app-job-monitor" closeOnEsc={false}>
<ModalHeader>{i18n.t(`jobs.${JobSerialized.getType(job)}`)}</ModalHeader>

<Modal className="app-job-monitor" closeOnEsc={false} title={`jobs.${JobSerialized.getType(job)}`}>
<ModalBody>
<JobProgress job={job} />
<JobErrors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Objects } from '@openforis/arena-core'

import { RecordCycle } from '@core/record/recordCycle'

import { Modal, ModalBody, ModalClose, ModalFooter, ModalHeader } from '@webapp/components/modal'
import { Modal, ModalBody, ModalFooter } from '@webapp/components/modal'
import { Button, RadioButtonGroup } from '@webapp/components'
import { FormItem } from '@webapp/components/form/Input'
import CycleSelector from '@webapp/components/survey/CycleSelector'
Expand Down Expand Up @@ -100,11 +100,7 @@ export const RecordsCloneModal = (props) => {
}

return (
<Modal className="records-clone" onClose={onClose}>
<ModalHeader>
<span>{i18n.t('dataView.recordsClone.title')}</span>
<ModalClose onClose={onClose} />
</ModalHeader>
<Modal className="records-clone" onClose={onClose} showCloseButton title="dataView.recordsClone.title">
<ModalBody>
<FormItem label={i18n.t('dataView.recordsClone.fromCycle')}>{cycleFromLabel}</FormItem>
<FormItem label={i18n.t('dataView.recordsClone.toCycle')}>
Expand Down
13 changes: 6 additions & 7 deletions webapp/views/Arena/Routes/DialogConfirm/DialogConfirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -29,12 +29,11 @@ const DialogConfirm = () => {
} = useDialogConfirm()

return key ? (
<Modal className="dialog-confirm" onClose={() => dispatch(DialogConfirmActions.onDialogConfirmCancel())}>
{headerText && (
<ModalHeader>
<h5 className="dialog-confirm__header">{i18n.t(headerText)}</h5>
</ModalHeader>
)}
<Modal
className="dialog-confirm"
onClose={() => dispatch(DialogConfirmActions.onDialogConfirmCancel())}
title={headerText}
>
<ModalBody>
<Markdown className={headerText ? 'highlight' : undefined} source={i18n.t(key, params)} />

Expand Down

0 comments on commit f09d501

Please sign in to comment.