Skip to content

Commit

Permalink
fix: Add WithAlerts.tsx to Dataset.stories.tsx and DatasetAlert.stori…
Browse files Browse the repository at this point in the history
…es.tsx
  • Loading branch information
ekraffmiller committed Nov 8, 2023
1 parent 390923a commit 3a5d7fe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/sections/dataset/DatasetAlertProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const DatasetAlertProvider = ({ children }: PropsWithChildren) => {
const [datasetAlerts, setDatasetAlerts] = useState<DatasetAlert[]>([])

const addDatasetAlert = (newAlert: DatasetAlert) => {
datasetAlerts.push(newAlert)
// Check if an alert with the same id already exists
const alertExists = datasetAlerts.some((alert) => alert.messageKey === newAlert.messageKey)

// If it doesn't exist, add it to the array
if (!alertExists) datasetAlerts.push(newAlert)
}

const removeDatasetAlert = (alertId: DatasetAlertMessageKey) => {
Expand Down
10 changes: 10 additions & 0 deletions src/stories/WithAlerts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StoryFn } from '@storybook/react'
import { DatasetAlertProvider } from '../sections/dataset/DatasetAlertProvider'

export const WithAlerts = (Story: StoryFn) => {
return (
<DatasetAlertProvider>
<Story />
</DatasetAlertProvider>
)
}
3 changes: 2 additions & 1 deletion src/stories/dataset/Dataset.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import { WithDatasetDraftAsOwner } from './WithDatasetDraftAsOwner'
import { WithDatasetNotFound } from './WithDatasetNotFound'
import { WithDatasetLoading } from './WithDatasetLoading'
import { WithLoggedInUser } from '../WithLoggedInUser'
import { WithAlerts } from '../WithAlerts'

const meta: Meta<typeof Dataset> = {
title: 'Pages/Dataset',
component: Dataset,
decorators: [WithI18next, WithCitationMetadataBlockInfo, WithSettings],
decorators: [WithI18next, WithCitationMetadataBlockInfo, WithSettings, WithAlerts],
parameters: {
// Sets the delay for all stories.
chromatic: { delay: 15000, pauseAnimationAtEnd: true }
Expand Down
11 changes: 2 additions & 9 deletions src/stories/dataset/dataset-alerts/DatasetAlert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@ import {
DatasetMother,
DatasetPermissionsMother
} from '../../../../tests/component/dataset/domain/models/DatasetMother'
import { DatasetAlertProvider } from '../../../sections/dataset/DatasetAlertProvider'
import { useAlertContext } from '../../../sections/dataset/DatasetAlertContext'
import { WithAlerts } from '../../WithAlerts'

const meta: Meta<typeof DatasetAlerts> = {
title: 'Sections/Dataset Page/DatasetAlerts',
component: DatasetAlerts,
decorators: [
WithI18next,
(Story) => (
<DatasetAlertProvider>
<Story />
</DatasetAlertProvider>
)
]
decorators: [WithI18next, WithAlerts]
}
const allUpdateAlerts: DatasetAlert[] = [
new DatasetAlert('success', DatasetAlertMessageKey.METADATA_UPDATED),
Expand Down

0 comments on commit 3a5d7fe

Please sign in to comment.