Skip to content

Commit

Permalink
feat: refactor DatasetAlerts.tsx to call a generic Alerts component
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Nov 6, 2023
1 parent 417c300 commit 1b4edba
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/sections/alerts/Alerts.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.container > * {
margin-top: 1em;
margin-right: 0.5em;
}
34 changes: 34 additions & 0 deletions src/sections/alerts/Alerts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Alert } from '@iqss/dataverse-design-system'

import { useTranslation } from 'react-i18next'
import styles from './Alerts.module.scss'
import parse from 'html-react-parser'
import { DatasetAlert } from '../../dataset/domain/models/Dataset'

interface AlertsProps {
alerts: DatasetAlert[]
}

export function Alerts({ alerts }: AlertsProps) {
const { t } = useTranslation('dataset')
return (
<div className={styles.container}>
{alerts.map((alert: DatasetAlert, index) => {
const translatedMsg = alert.dynamicFields
? t(`alerts.${alert.messageKey}.alertText`, alert.dynamicFields)
: t(`alerts.${alert.messageKey}.alertText`)
const translatedHeading = t(`alerts.${alert.messageKey}.heading`)
const alertKey = `alert-${index}`
return (
<Alert
key={alertKey}
variant={alert.variant}
customHeading={translatedHeading}
dismissible={false}>
{parse(translatedMsg)}
</Alert>
)
})}
</div>
)
}
25 changes: 2 additions & 23 deletions src/sections/dataset/dataset-alerts/DatasetAlerts.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Alert } from '@iqss/dataverse-design-system'
import { DatasetAlert } from '../../../dataset/domain/models/Dataset'
import { useTranslation } from 'react-i18next'
import styles from './DatasetAlerts.module.scss'
import parse from 'html-react-parser'
import { useDatasetAlertContext } from '../DatasetAlertContext'
import { Alerts } from '../../alerts/Alerts'

interface DatasetAlertsProps {
alerts: DatasetAlert[]
Expand All @@ -13,24 +11,5 @@ export function DatasetAlerts({ alerts }: DatasetAlertsProps) {
const { t } = useTranslation('dataset')

Check warning on line 11 in src/sections/dataset/dataset-alerts/DatasetAlerts.tsx

View workflow job for this annotation

GitHub Actions / lint

't' is assigned a value but never used. Allowed unused vars must match /^_/u
const statusAlerts = useDatasetAlertContext()
alerts = alerts.concat(statusAlerts.datasetAlerts)
return (
<div className={styles.container}>
{alerts.map((alert: DatasetAlert, index) => {
const translatedMsg = alert.dynamicFields
? t(`alerts.${alert.messageKey}.alertText`, alert.dynamicFields)
: t(`alerts.${alert.messageKey}.alertText`)
const translatedHeading = t(`alerts.${alert.messageKey}.heading`)
const alertKey = `alert-${index}`
return (
<Alert
key={alertKey}
variant={alert.variant}
customHeading={translatedHeading}
dismissible={false}>
{parse(translatedMsg)}
</Alert>
)
})}
</div>
)
return <Alerts alerts={alerts}></Alerts>
}

0 comments on commit 1b4edba

Please sign in to comment.