Skip to content

Commit

Permalink
Merge pull request #1481 from nickgros/storybook-routing
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros authored Jan 6, 2025
2 parents 375f244 + b5fab74 commit 46d69b9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const meta: Meta<typeof ChangePassword> = {
component: ChangePassword,
parameters: {
stack: 'mock',
withRouter: true,
},
decorators: [
Story => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { Meta, StoryObj } from '@storybook/react'
import RecentPublicationsGrid from './RecentPublicationsGrid'
import { BrowserRouter } from 'react-router-dom'

const meta = {
title: 'Home Page/RecentPublicationsGrid',
component: RecentPublicationsGrid,
parameters: {
chromatic: { viewports: [600, 1200] },
withRouter: true,
},
} satisfies Meta

export default meta
type Story = StoryObj<typeof meta>

export const Demo: Story = {
render: args => (
<BrowserRouter>
<RecentPublicationsGrid {...args} />
</BrowserRouter>
),
render: args => <RecentPublicationsGrid {...args} />,
args: {
sql: 'SELECT * FROM syn51407023',
buttonLink: 'Explore/Publications',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import dayjs from 'dayjs'
import { ReactNode, Suspense, useEffect, useMemo, useState } from 'react'
import { createMemoryRouter, RouterProvider } from 'react-router-dom'
import SynapseClient, {
getAccessTokenFromCookie,
getAuthenticatedOn,
Expand Down Expand Up @@ -72,6 +73,7 @@ export function StorybookComponentWrapper(props: {
}
parameters: {
stack?: SynapseStack
withRouter?: boolean
}
}
}) {
Expand Down Expand Up @@ -119,7 +121,7 @@ export function StorybookComponentWrapper(props: {
[accessToken, currentStack, storybookContext.args.isAuthenticated],
)

return (
const wrappedStory = (
<Suspense fallback={'global suspense loading...'}>
<QueryClientProvider client={storybookQueryClient}>
<SynapseContextProvider
Expand All @@ -135,6 +137,19 @@ export function StorybookComponentWrapper(props: {
</QueryClientProvider>
</Suspense>
)

if (!storybookContext.parameters.withRouter) {
return wrappedStory
}

const router = createMemoryRouter([
{
path: '/',
element: wrappedStory,
},
])

return <RouterProvider router={router} />
}

export default StorybookComponentWrapper

0 comments on commit 46d69b9

Please sign in to comment.