Skip to content

Commit f010391

Browse files
authored
CORE-1039: Route pages that do not have CMS page data (#2762)
[CORE-1039]
1 parent 27f69ba commit f010391

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

src/app/components/shell/router-helpers/page-routes.tsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export function DetailsRoutes() {
5656
export function OtherPageRoutes() {
5757
const dir = assertDefined(useParams().dir);
5858
const {'*': path} = useParams();
59+
const {layoutParameters, setLayoutParameters} = useLayoutContext();
5960

6061
if (['books', 'textbooks'].includes(dir)) {
6162
return (
@@ -76,26 +77,53 @@ export function OtherPageRoutes() {
7677
return <Navigate to="/" replace />;
7778
}
7879

80+
// Some pages have no page data in the CMS!
81+
if (
82+
[
83+
'adopters',
84+
'adoption',
85+
'blog',
86+
'campaign',
87+
'confirmation',
88+
'institutional-partnership-application',
89+
'interest',
90+
'renewal-form',
91+
'separatemap'
92+
].includes(dir)
93+
) {
94+
if (layoutParameters.name === null) {
95+
setLayoutParameters({name: 'default'});
96+
}
97+
return <ImportedPage name={dir} />;
98+
}
99+
79100
return <RouteAsPortalOrNot />;
80101
}
81102

82-
83103
// There are a couple of pages whose names in the CMS don't match their osweb urls
84104
const mismatch: Record<string, string> = {
85105
press: 'news',
86-
'edtech-partner-program': 'openstax-ally-technology-partner-program'
106+
'edtech-partner-program': 'openstax-ally-technology-partner-program',
107+
foundation: 'supporters'
87108
};
88109

89110
export function usePageDataFromRoute() {
90111
const {dir: name, '*': other} = useParams();
91-
const data = usePageData<PageData>(`pages/${mismatch[name as string] ?? name}`, true);
112+
const data = usePageData<PageData>(
113+
`pages/${mismatch[name as string] ?? name}`,
114+
true
115+
);
92116
const hasError = data && 'error' in data;
93117

94118
return {name, data, hasError, other};
95119
}
96120

97121
export function FlexPageUsingItsOwnLayout({data}: {data: FlexPageData}) {
98-
return <LayoutUsingData data={data}><FlexPage data={data} /></LayoutUsingData>;
122+
return (
123+
<LayoutUsingData data={data}>
124+
<FlexPage data={data} />
125+
</LayoutUsingData>
126+
);
99127
}
100128

101129
export function NonFlexPageUsingDefaultLayout({data}: {data: PageData}) {

src/app/pages/campaign/campaign.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/src/components/shell.test.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ describe('shell', () => {
6565
case 'pages/general-page':
6666
return camelCaseKeys(transformData(generalPage));
6767
default:
68-
if (path.startsWith('errata/') || path.startsWith('pages/')) {
68+
if (path.startsWith('errata/') || path.startsWith('pages/')
69+
|| path.startsWith('snippets/roles')) {
6970
return [];
7071
}
7172
console.info('*** Requested', path);
@@ -162,6 +163,15 @@ describe('shell', () => {
162163
render(AppElement);
163164
await screen.findByText('-/anything-');
164165
});
166+
it('routes adoption (no CMS page data) page', async () => {
167+
BrowserRouter.mockImplementationOnce(({children}) => (
168+
<MR initialEntries={['/adoption']} >{children}</MR>
169+
));
170+
171+
render(AppElement);
172+
await screen.findByText('Adoption Form', {exact: false});
173+
screen.getByRole('combobox');
174+
});
165175
it('routes "errata" paths', async () => {
166176
BrowserRouter.mockImplementationOnce(({children}) => (
167177
<MR initialEntries={['/errata']} >{children}</MR>

0 commit comments

Comments
 (0)