diff --git a/src/sections/dataset/DatasetAlertContext.ts b/src/sections/alerts/AlertContext.ts similarity index 74% rename from src/sections/dataset/DatasetAlertContext.ts rename to src/sections/alerts/AlertContext.ts index fae5aa2c2..48bcc8682 100644 --- a/src/sections/dataset/DatasetAlertContext.ts +++ b/src/sections/alerts/AlertContext.ts @@ -8,9 +8,9 @@ interface DatasetAlertContextProps { removeDatasetAlert: (alertId: AlertMessageKey) => void } -export const DatasetAlertContext = createContext({ +export const AlertContext = createContext({ datasetAlerts: [], addDatasetAlert: /* istanbul ignore next */ () => {}, removeDatasetAlert: /* istanbul ignore next */ () => {} }) -export const useAlertContext = () => useContext(DatasetAlertContext) +export const useAlertContext = () => useContext(AlertContext) diff --git a/src/sections/dataset/DatasetAlertProvider.tsx b/src/sections/alerts/AlertProvider.tsx similarity index 79% rename from src/sections/dataset/DatasetAlertProvider.tsx rename to src/sections/alerts/AlertProvider.tsx index 72d9a87a6..6504ff8e7 100644 --- a/src/sections/dataset/DatasetAlertProvider.tsx +++ b/src/sections/alerts/AlertProvider.tsx @@ -1,9 +1,9 @@ import { PropsWithChildren, useState } from 'react' -import { DatasetAlertContext } from './DatasetAlertContext' +import { AlertContext } from './AlertContext' import { Alert, AlertMessageKey } from '../../alert/domain/models/Alert' -export const DatasetAlertProvider = ({ children }: PropsWithChildren) => { +export const AlertProvider = ({ children }: PropsWithChildren) => { const [datasetAlerts, setDatasetAlerts] = useState([]) const addDatasetAlert = (newAlert: Alert) => { @@ -19,13 +19,13 @@ export const DatasetAlertProvider = ({ children }: PropsWithChildren) => { } return ( - {children} - + ) } diff --git a/src/sections/alerts/Alerts.tsx b/src/sections/alerts/Alerts.tsx index 19296b90d..e576b838b 100644 --- a/src/sections/alerts/Alerts.tsx +++ b/src/sections/alerts/Alerts.tsx @@ -3,7 +3,7 @@ import { Alert as AlertComponent } from '@iqss/dataverse-design-system' import { useTranslation } from 'react-i18next' import styles from './Alerts.module.scss' import parse from 'html-react-parser' -import { useAlertContext } from '../dataset/DatasetAlertContext' +import { useAlertContext } from './AlertContext' import { Alert } from '../../alert/domain/models/Alert' export function Alerts() { diff --git a/src/sections/dataset/DatasetFactory.tsx b/src/sections/dataset/DatasetFactory.tsx index 447bcb4cb..a256f892b 100644 --- a/src/sections/dataset/DatasetFactory.tsx +++ b/src/sections/dataset/DatasetFactory.tsx @@ -11,7 +11,7 @@ import { SettingJSDataverseRepository } from '../../settings/infrastructure/Sett import { FilePermissionsProvider } from '../file/file-permissions/FilePermissionsProvider' import { SettingsProvider } from '../settings/SettingsProvider' import { DatasetProvider } from './DatasetProvider' -import { DatasetAlertProvider } from './DatasetAlertProvider' +import { AlertProvider } from '../alerts/AlertProvider' const datasetRepository = new DatasetJSDataverseRepository() const fileRepository = new FileJSDataverseRepository() @@ -25,9 +25,9 @@ export class DatasetFactory { - + - + diff --git a/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx b/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx index 12f985d90..c10e60d6c 100644 --- a/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx +++ b/src/sections/dataset/dataset-alerts/DatasetAlerts.tsx @@ -1,4 +1,4 @@ -import { useAlertContext } from '../DatasetAlertContext' +import { useAlertContext } from '../../alerts/AlertContext' import { Alerts } from '../../alerts/Alerts' import { Alert } from '../../../alert/domain/models/Alert' diff --git a/src/stories/WithAlerts.tsx b/src/stories/WithAlerts.tsx index d6f70e92b..9225bd196 100644 --- a/src/stories/WithAlerts.tsx +++ b/src/stories/WithAlerts.tsx @@ -1,10 +1,10 @@ import { StoryFn } from '@storybook/react' -import { DatasetAlertProvider } from '../sections/dataset/DatasetAlertProvider' +import { AlertProvider } from '../sections/alerts/AlertProvider' export const WithAlerts = (Story: StoryFn) => { return ( - + - + ) } diff --git a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx index 58309a5e9..31de08bf7 100644 --- a/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx +++ b/src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx @@ -8,7 +8,7 @@ import { DatasetMother, DatasetPermissionsMother } from '../../../../tests/component/dataset/domain/models/DatasetMother' -import { useAlertContext } from '../../../sections/dataset/DatasetAlertContext' +import { useAlertContext } from '../../../sections/alerts/AlertContext' import { WithAlerts } from '../../WithAlerts' import { Alert, AlertMessageKey } from '../../../alert/domain/models/Alert' diff --git a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx index 876f37609..0ccf2c504 100644 --- a/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx +++ b/tests/component/sections/dataset/dataset-alerts/DatasetAlerts.spec.tsx @@ -7,7 +7,7 @@ import { DatasetVersionMother } from '../../../dataset/domain/models/DatasetMother' import { Alert, AlertMessageKey } from '../../../../../src/alert/domain/models/Alert' -import { DatasetAlertProvider } from '../../../../../src/sections/dataset/DatasetAlertProvider' +import { AlertProvider } from '../../../../../src/sections/alerts/AlertProvider' function removeMarkup(htmlString: string): string { // Use a regular expression to match HTML tags and replace them with an empty string @@ -48,9 +48,9 @@ it('renders the correct number of alerts', () => { ] cy.fixture('../../../public/locales/en/dataset.json').then((dataset: DatasetTranslation) => { cy.mount( - + - + ) const headingProps = [ dataset.alerts.draftVersion.heading, @@ -70,9 +70,9 @@ it('renders alerts with correct text', () => { cy.fixture('../../../public/locales/en/dataset.json').then((dataset: DatasetTranslation) => { cy.mount( - + - + ) const alertHeading = dataset.alerts[draftAlert.messageKey].heading const alertText = removeMarkup(dataset.alerts[draftAlert.messageKey].alertText) @@ -95,9 +95,9 @@ it('renders dynamic text', () => { dynamicFields ) cy.mount( - + - + ) cy.findByRole('alert').should('contain.text', dynamicFields.requestedVersion) @@ -110,9 +110,9 @@ it('shows draft alert if version is DRAFT', () => { }) cy.mount( - + - + ) cy.findByRole('alert').should('contain.text', 'draft') @@ -124,9 +124,9 @@ it('does not show draft alert if version is RELEASED', () => { }) cy.mount( - + - + ) cy.findByRole('alert').should('not.exist') }) @@ -142,9 +142,9 @@ it('shows draft & share private url message if privateUrl exists and user can ed } }) cy.mount( - + - + ) const expectedMessageKeys = [ AlertMessageKey.DRAFT_VERSION, @@ -169,9 +169,9 @@ it('shows private url message only if privateUrl exists and user cannot edit', } }) cy.mount( - + - + ) const expectedMessageKey = AlertMessageKey.UNPUBLISHED_DATASET