diff --git a/apps/admin-x-framework/src/providers/FrameworkProvider.tsx b/apps/admin-x-framework/src/providers/FrameworkProvider.tsx index 3a04d1d817..89b0f33115 100644 --- a/apps/admin-x-framework/src/providers/FrameworkProvider.tsx +++ b/apps/admin-x-framework/src/providers/FrameworkProvider.tsx @@ -2,13 +2,11 @@ import {ErrorBoundary as SentryErrorBoundary} from '@sentry/react'; import {QueryClientProvider} from '@tanstack/react-query'; import {ReactNode, createContext, useContext} from 'react'; import queryClient from '../utils/queryClient'; -import RoutingProvider, {RoutingProviderProps} from './RoutingProvider'; +import {ExternalLink} from './RoutingProvider'; export interface FrameworkProviderProps { - basePath: string; ghostVersion: string; - externalNavigate: RoutingProviderProps['externalNavigate']; - modals: RoutingProviderProps['modals']; + externalNavigate: (link: ExternalLink) => void; unsplashConfig: { Authorization: string; 'Accept-Version': string; @@ -24,10 +22,11 @@ export interface FrameworkProviderProps { children: ReactNode; } -export type FrameworkContextType = Omit; +export type FrameworkContextType = Omit; const FrameworkContext = createContext({ ghostVersion: '', + externalNavigate: () => {}, unsplashConfig: { Authorization: '', 'Accept-Version': '', @@ -41,14 +40,12 @@ const FrameworkContext = createContext({ onDelete: () => {} }); -function FrameworkProvider({externalNavigate, basePath, modals, children, ...props}: FrameworkProviderProps) { +function FrameworkProvider({children, ...props}: FrameworkProviderProps) { return ( - - {children} - + {children} diff --git a/apps/admin-x-framework/src/providers/RoutingProvider.tsx b/apps/admin-x-framework/src/providers/RoutingProvider.tsx index 84af39f483..58baf92bcf 100644 --- a/apps/admin-x-framework/src/providers/RoutingProvider.tsx +++ b/apps/admin-x-framework/src/providers/RoutingProvider.tsx @@ -1,5 +1,6 @@ import NiceModal, {NiceModalHocProps} from '@ebay/nice-modal-react'; import React, {createContext, useCallback, useContext, useEffect, useState} from 'react'; +import {useFramework} from './FrameworkProvider'; export type RouteParams = Record @@ -92,12 +93,12 @@ const matchRoute = (pathname: string, routeDefinition: string) => { export interface RoutingProviderProps { basePath: string; - externalNavigate: (link: ExternalLink) => void; modals?: {paths: Record, load: () => Promise} children: React.ReactNode; } -const RoutingProvider: React.FC = ({basePath, externalNavigate, modals, children}) => { +const RoutingProvider: React.FC = ({basePath, modals, children}) => { + const {externalNavigate} = useFramework(); const [route, setRoute] = useState(undefined); const [loadingModal, setLoadingModal] = useState(false); const [eventTarget] = useState(new EventTarget()); diff --git a/apps/admin-x-framework/src/routing.ts b/apps/admin-x-framework/src/routing.ts index 7dc623213f..bbb5544922 100644 --- a/apps/admin-x-framework/src/routing.ts +++ b/apps/admin-x-framework/src/routing.ts @@ -1,3 +1,3 @@ -export {useRouteChangeCallback, useRouting} from './providers/RoutingProvider'; +export {default as RoutingProvider, useRouteChangeCallback, useRouting} from './providers/RoutingProvider'; export type {ExternalLink, InternalLink, RoutingModalProps} from './providers/RoutingProvider'; diff --git a/apps/admin-x-settings/src/App.tsx b/apps/admin-x-settings/src/App.tsx index 19049d79ba..1ef591fce3 100644 --- a/apps/admin-x-settings/src/App.tsx +++ b/apps/admin-x-settings/src/App.tsx @@ -3,6 +3,7 @@ import SettingsAppProvider, {OfficialTheme, UpgradeStatusType} from './component import SettingsRouter, {loadModals, modalPaths} from './components/providers/SettingsRouter'; import {DesignSystemApp, FetchKoenigLexical} from '@tryghost/admin-x-design-system'; import {FrameworkProvider, FrameworkProviderProps} from '@tryghost/admin-x-framework'; +import {RoutingProvider} from '@tryghost/admin-x-framework/routing'; import {ZapierTemplate} from './components/settings/advanced/integrations/ZapierModal'; interface AppProps extends Omit { @@ -15,12 +16,14 @@ interface AppProps extends Omit + - - - - + + + + + + ); diff --git a/apps/admin-x-settings/test/acceptance/routing.test.ts b/apps/admin-x-settings/test/acceptance/routing.test.ts new file mode 100644 index 0000000000..fe680c5849 --- /dev/null +++ b/apps/admin-x-settings/test/acceptance/routing.test.ts @@ -0,0 +1,23 @@ +import {expect, test} from '@playwright/test'; +import {globalDataRequests, mockApi} from '../utils/acceptance'; + +test.describe('Routing', async () => { + test('Reopens the opened modal when refreshing the page', async ({page}) => { + await mockApi({page, requests: globalDataRequests}); + + await page.goto('/'); + + const section = page.getByTestId('portal'); + await section.getByRole('button', {name: 'Customize'}).click(); + + await page.waitForSelector('[data-testid="portal-modal"]'); + + expect(page.url()).toMatch(/\/portal\/edit$/); + + await page.reload(); + + await page.waitForSelector('[data-testid="portal-modal"]'); + + expect(page.url()).toMatch(/\/portal\/edit$/); + }); +});