-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Add support for nested web pages (#1923)
- @bigcommerce/create-catalyst@0.21.0
- @bigcommerce/catalyst-core@1.0.0-rc.10
- @bigcommerce/catalyst-core@1.0.0-rc.9
- @bigcommerce/catalyst-core@1.0.0-rc.8
- @bigcommerce/catalyst-core@1.0.0-rc.7
- @bigcommerce/catalyst-core@1.0.0-rc.6
- @bigcommerce/catalyst-core@1.0.0-rc.5
- @bigcommerce/catalyst-core@1.0.0-rc
- @bigcommerce/catalyst-core@makeswift-canary
- @bigcommerce/catalyst-core@makeswift-1.0.0-rc.10
- @bigcommerce/catalyst-core@makeswift-1.0.0-rc.9
- @bigcommerce/catalyst-core@makeswift-1.0.0-rc.8
- @bigcommerce/catalyst-core@makeswift-1.0.0-rc.7
- @bigcommerce/catalyst-core@makeswift-1.0.0-rc.6
- @bigcommerce/catalyst-core@makeswift-1.0.0-rc.5
- @bigcommerce/catalyst-core@canary
1 parent
c30a9d9
commit 62b891c
Showing
19 changed files
with
306 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": minor | ||
--- | ||
|
||
Adds support for nested web page children / trees. Restructure web page routing to support a layout file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { removeEdgesAndNodes } from '@bigcommerce/catalyst-client'; | ||
import { cache } from 'react'; | ||
|
||
import { SidebarMenu } from '@/vibes/soul/sections/sidebar-menu'; | ||
import { StickySidebarLayout } from '@/vibes/soul/sections/sticky-sidebar-layout'; | ||
import { client } from '~/client'; | ||
import { graphql } from '~/client/graphql'; | ||
import { revalidate } from '~/client/revalidate-target'; | ||
|
||
interface Props extends React.PropsWithChildren { | ||
params: Promise<{ id: string }>; | ||
} | ||
|
||
const WebPageChildrenQuery = graphql(` | ||
query WebPageChildren($id: ID!) { | ||
node(id: $id) { | ||
... on WebPage { | ||
children(first: 20) { | ||
edges { | ||
node { | ||
name | ||
... on NormalPage { | ||
path | ||
} | ||
... on ContactPage { | ||
path | ||
} | ||
... on RawHtmlPage { | ||
path | ||
} | ||
... on ExternalLinkPage { | ||
link | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
interface PageLink { | ||
label: string; | ||
href: string; | ||
} | ||
|
||
const getWebPageChildren = cache(async (id: string): Promise<PageLink[]> => { | ||
const { data } = await client.fetch({ | ||
document: WebPageChildrenQuery, | ||
variables: { id: decodeURIComponent(id) }, | ||
fetchOptions: { next: { revalidate } }, | ||
}); | ||
|
||
if (!data.node) { | ||
return []; | ||
} | ||
|
||
if (!('children' in data.node)) { | ||
return []; | ||
} | ||
|
||
const { children } = data.node; | ||
|
||
return removeEdgesAndNodes(children).reduce((acc: PageLink[], child) => { | ||
if ('path' in child) { | ||
return [...acc, { label: child.name, href: child.path }]; | ||
} | ||
|
||
if ('link' in child) { | ||
return [...acc, { label: child.name, href: child.link }]; | ||
} | ||
|
||
return acc; | ||
}, []); | ||
}); | ||
|
||
export default async function WebPageLayout({ params, children }: Props) { | ||
const { id } = await params; | ||
|
||
return ( | ||
<StickySidebarLayout | ||
sidebar={<SidebarMenu links={getWebPageChildren(id)} />} | ||
sidebarSize="small" | ||
> | ||
{children} | ||
</StickySidebarLayout> | ||
); | ||
} |
38 changes: 38 additions & 0 deletions
38
core/app/[locale]/(default)/webpages/[id]/normal/page-data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { cache } from 'react'; | ||
|
||
import { client } from '~/client'; | ||
import { graphql } from '~/client/graphql'; | ||
import { revalidate } from '~/client/revalidate-target'; | ||
import { BreadcrumbsWebPageFragment } from '~/components/breadcrumbs/fragment'; | ||
|
||
const NormalPageQuery = graphql( | ||
` | ||
query NormalPageQuery($id: ID!) { | ||
node(id: $id) { | ||
... on NormalPage { | ||
__typename | ||
name | ||
...BreadcrumbsFragment | ||
htmlBody | ||
entityId | ||
seo { | ||
pageTitle | ||
metaDescription | ||
metaKeywords | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
[BreadcrumbsWebPageFragment], | ||
); | ||
|
||
export const getWebpageData = cache(async (variables: { id: string }) => { | ||
const { data } = await client.fetch({ | ||
document: NormalPageQuery, | ||
variables, | ||
fetchOptions: { next: { revalidate } }, | ||
}); | ||
|
||
return data; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.