@graphcommerce/graphcms-ui 8.1.0-canary.8 → 9.0.0-canary.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -0
- package/components/Asset/Asset.graphql +1 -1
- package/components/Asset/Asset.tsx +3 -2
- package/graphql/HygraphPage.graphql +1 -1
- package/graphql/HygraphStaticPaths.graphql +11 -0
- package/graphql/PageLink.graphql +1 -1
- package/index.ts +0 -1
- package/lib/getAllHygraphPages.ts +4 -2
- package/lib/getHygraphPaths.ts +43 -0
- package/lib/index.ts +1 -0
- package/package.json +8 -7
- package/plugins/HygraphPreviewModeToolbar.tsx +80 -0
- package/plugins/hygraphGraphqlConfig.ts +12 -0
- package/plugins/hygraphPreviewModeDefaults.ts +12 -0
- package/links/createHygraphLink.ts +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,107 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 9.0.0-canary.54
|
|
4
|
+
|
|
5
|
+
## 8.1.0-canary.53
|
|
6
|
+
|
|
7
|
+
## 8.1.0-canary.52
|
|
8
|
+
|
|
9
|
+
## 8.1.0-canary.51
|
|
10
|
+
|
|
11
|
+
## 8.1.0-canary.50
|
|
12
|
+
|
|
13
|
+
## 8.1.0-canary.49
|
|
14
|
+
|
|
15
|
+
## 8.1.0-canary.48
|
|
16
|
+
|
|
17
|
+
## 8.1.0-canary.47
|
|
18
|
+
|
|
19
|
+
## 8.1.0-canary.46
|
|
20
|
+
|
|
21
|
+
## 8.1.0-canary.45
|
|
22
|
+
|
|
23
|
+
## 8.1.0-canary.44
|
|
24
|
+
|
|
25
|
+
## 8.1.0-canary.43
|
|
26
|
+
|
|
27
|
+
## 8.1.0-canary.42
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- [#2308](https://github.com/graphcommerce-org/graphcommerce/pull/2308) [`8faa5ac`](https://github.com/graphcommerce-org/graphcommerce/commit/8faa5ac618ecfdacd6d5eb751b4110c423aef97f) - Added Draft Mode support. When enabled it will be shown.
|
|
32
|
+
([@paales](https://github.com/paales))
|
|
33
|
+
|
|
34
|
+
## 8.1.0-canary.41
|
|
35
|
+
|
|
36
|
+
## 8.1.0-canary.40
|
|
37
|
+
|
|
38
|
+
## 8.1.0-canary.39
|
|
39
|
+
|
|
40
|
+
## 8.1.0-canary.38
|
|
41
|
+
|
|
42
|
+
## 8.1.0-canary.37
|
|
43
|
+
|
|
44
|
+
## 8.1.0-canary.36
|
|
45
|
+
|
|
46
|
+
## 8.1.0-canary.35
|
|
47
|
+
|
|
48
|
+
## 8.1.0-canary.34
|
|
49
|
+
|
|
50
|
+
## 8.1.0-canary.33
|
|
51
|
+
|
|
52
|
+
## 8.1.0-canary.32
|
|
53
|
+
|
|
54
|
+
## 8.1.0-canary.31
|
|
55
|
+
|
|
56
|
+
## 8.1.0-canary.30
|
|
57
|
+
|
|
58
|
+
## 8.1.0-canary.29
|
|
59
|
+
|
|
60
|
+
## 8.1.0-canary.28
|
|
61
|
+
|
|
62
|
+
## 8.1.0-canary.27
|
|
63
|
+
|
|
64
|
+
## 8.1.0-canary.26
|
|
65
|
+
|
|
66
|
+
## 8.1.0-canary.25
|
|
67
|
+
|
|
68
|
+
## 8.1.0-canary.24
|
|
69
|
+
|
|
70
|
+
## 8.1.0-canary.23
|
|
71
|
+
|
|
72
|
+
## 8.1.0-canary.22
|
|
73
|
+
|
|
74
|
+
## 8.1.0-canary.21
|
|
75
|
+
|
|
76
|
+
## 8.1.0-canary.20
|
|
77
|
+
|
|
78
|
+
## 8.1.0-canary.19
|
|
79
|
+
|
|
80
|
+
## 8.1.0-canary.18
|
|
81
|
+
|
|
82
|
+
## 8.1.0-canary.17
|
|
83
|
+
|
|
84
|
+
## 8.1.0-canary.16
|
|
85
|
+
|
|
86
|
+
## 8.1.0-canary.15
|
|
87
|
+
|
|
88
|
+
## 8.1.0-canary.14
|
|
89
|
+
|
|
90
|
+
## 8.1.0-canary.13
|
|
91
|
+
|
|
92
|
+
## 8.1.0-canary.12
|
|
93
|
+
|
|
94
|
+
## 8.1.0-canary.11
|
|
95
|
+
|
|
96
|
+
## 8.1.0-canary.10
|
|
97
|
+
|
|
98
|
+
## 8.1.0-canary.9
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- [#2223](https://github.com/graphcommerce-org/graphcommerce/pull/2223) [`0ccec63`](https://github.com/graphcommerce-org/graphcommerce/commit/0ccec630825d5fad398366beae90b3c90b2f84b8) - Added helper method to get Hygraph paths
|
|
103
|
+
([@bramvanderholst](https://github.com/bramvanderholst))
|
|
104
|
+
|
|
3
105
|
## 8.1.0-canary.8
|
|
4
106
|
|
|
5
107
|
## 8.1.0-canary.7
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Image, ImageProps } from '@graphcommerce/image'
|
|
2
2
|
import { styled, SxProps, Theme } from '@mui/material'
|
|
3
|
+
import { memo } from 'react'
|
|
3
4
|
import { AssetFragment } from './Asset.gql'
|
|
4
5
|
|
|
5
6
|
export type { AssetFragment } from './Asset.gql'
|
|
@@ -18,7 +19,7 @@ type AssetProps = {
|
|
|
18
19
|
sx?: SxProps<Theme>
|
|
19
20
|
} & Omit<ImageProps, 'src' | 'width' | 'height' | 'alt' | 'sx'>
|
|
20
21
|
|
|
21
|
-
export
|
|
22
|
+
export const Asset = memo<AssetProps>((props) => {
|
|
22
23
|
const { asset, sx = [], ...imgProps } = props
|
|
23
24
|
|
|
24
25
|
if (isImage(asset)) {
|
|
@@ -55,4 +56,4 @@ export function Asset(props: AssetProps) {
|
|
|
55
56
|
|
|
56
57
|
if (process.env.NODE_ENV !== 'production') return <div>{asset.mimeType} not supported</div>
|
|
57
58
|
return null
|
|
58
|
-
}
|
|
59
|
+
})
|
package/graphql/PageLink.graphql
CHANGED
package/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ApolloClient, NormalizedCacheObject, ApolloQueryResult } from '@apollo/client'
|
|
2
|
+
import { cacheFirst } from '@graphcommerce/graphql'
|
|
2
3
|
import { HygraphAllPagesDocument, HygraphAllPagesQuery } from '../graphql'
|
|
3
4
|
|
|
4
5
|
type Urls = { url: string }
|
|
@@ -8,10 +9,11 @@ export async function getAllHygraphPages(
|
|
|
8
9
|
options: { pageSize?: number } = {},
|
|
9
10
|
) {
|
|
10
11
|
const { pageSize = 100 } = options
|
|
12
|
+
|
|
11
13
|
const query = client.query({
|
|
12
14
|
query: HygraphAllPagesDocument,
|
|
13
15
|
variables: { first: pageSize },
|
|
14
|
-
fetchPolicy:
|
|
16
|
+
fetchPolicy: cacheFirst(client),
|
|
15
17
|
})
|
|
16
18
|
const pages: Promise<ApolloQueryResult<HygraphAllPagesQuery>>[] = [query]
|
|
17
19
|
|
|
@@ -24,7 +26,7 @@ export async function getAllHygraphPages(
|
|
|
24
26
|
client.query({
|
|
25
27
|
query: HygraphAllPagesDocument,
|
|
26
28
|
variables: { first: pageSize, skip: pageSize * (i - 1) },
|
|
27
|
-
fetchPolicy:
|
|
29
|
+
fetchPolicy: cacheFirst(client),
|
|
28
30
|
}),
|
|
29
31
|
)
|
|
30
32
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ApolloClient, NormalizedCacheObject, ApolloQueryResult } from '@apollo/client'
|
|
2
|
+
import type { PageWhereInput } from '@graphcommerce/graphql-mesh'
|
|
3
|
+
import { GetStaticPathsResult } from 'next'
|
|
4
|
+
import {
|
|
5
|
+
HygraphStaticPathsDocument,
|
|
6
|
+
HygraphStaticPathsQuery,
|
|
7
|
+
} from '../graphql/HygraphStaticPaths.gql'
|
|
8
|
+
|
|
9
|
+
type Return = GetStaticPathsResult<{ url: string }>
|
|
10
|
+
|
|
11
|
+
export async function getHygraphStaticPaths(
|
|
12
|
+
client: ApolloClient<NormalizedCacheObject>,
|
|
13
|
+
locale: string,
|
|
14
|
+
options: { pageSize?: number; filter?: PageWhereInput } = {},
|
|
15
|
+
) {
|
|
16
|
+
const { pageSize = 100, filter = {} } = options
|
|
17
|
+
const query = client.query({
|
|
18
|
+
query: HygraphStaticPathsDocument,
|
|
19
|
+
variables: { pageSize, where: filter },
|
|
20
|
+
})
|
|
21
|
+
const pages: Promise<ApolloQueryResult<HygraphStaticPathsQuery>>[] = [query]
|
|
22
|
+
|
|
23
|
+
const { data } = await query
|
|
24
|
+
const totalPages = Math.ceil(data.pagesConnection.aggregate.count / pageSize) ?? 1
|
|
25
|
+
|
|
26
|
+
if (totalPages > 1) {
|
|
27
|
+
for (let i = 2; i <= totalPages; i++) {
|
|
28
|
+
pages.push(
|
|
29
|
+
client.query({
|
|
30
|
+
query: HygraphStaticPathsDocument,
|
|
31
|
+
variables: { pageSize, skip: pageSize * (i - 1), where: filter },
|
|
32
|
+
}),
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const paths: Return['paths'] = (await Promise.all(pages))
|
|
38
|
+
.map((q) => q.data.pages)
|
|
39
|
+
.flat(1)
|
|
40
|
+
.map((page) => ({ params: page, locale }))
|
|
41
|
+
|
|
42
|
+
return paths
|
|
43
|
+
}
|
package/lib/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/graphcms-ui",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "9.0.0-canary.54",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,12 +12,13 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@graphcommerce/
|
|
16
|
-
"@graphcommerce/
|
|
17
|
-
"@graphcommerce/
|
|
18
|
-
"@graphcommerce/
|
|
19
|
-
"@graphcommerce/
|
|
20
|
-
"@graphcommerce/
|
|
15
|
+
"@graphcommerce/ecommerce-ui": "^9.0.0-canary.54",
|
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.54",
|
|
17
|
+
"@graphcommerce/graphql": "^9.0.0-canary.54",
|
|
18
|
+
"@graphcommerce/image": "^9.0.0-canary.54",
|
|
19
|
+
"@graphcommerce/next-ui": "^9.0.0-canary.54",
|
|
20
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.54",
|
|
21
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.54",
|
|
21
22
|
"@mui/material": "^5.10.16",
|
|
22
23
|
"next": "*",
|
|
23
24
|
"react": "^18.2.0",
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
usePreviewModeForm,
|
|
3
|
+
type PreviewModeToolbarProps,
|
|
4
|
+
SelectElement,
|
|
5
|
+
previewModeDefaults,
|
|
6
|
+
} from '@graphcommerce/ecommerce-ui'
|
|
7
|
+
import { TypedDocumentNode, gql, useQuery } from '@graphcommerce/graphql'
|
|
8
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
9
|
+
import { filterNonNullableKeys } from '@graphcommerce/next-ui'
|
|
10
|
+
import React, { useMemo } from 'react'
|
|
11
|
+
|
|
12
|
+
export const config: PluginConfig = {
|
|
13
|
+
type: 'component',
|
|
14
|
+
module: '@graphcommerce/ecommerce-ui',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ContentStages = gql`
|
|
18
|
+
query {
|
|
19
|
+
__type(name: "Stage") {
|
|
20
|
+
name
|
|
21
|
+
enumValues {
|
|
22
|
+
name
|
|
23
|
+
description
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
` as TypedDocumentNode<{
|
|
28
|
+
__type: {
|
|
29
|
+
name: 'Stage'
|
|
30
|
+
enumValues: {
|
|
31
|
+
name: string
|
|
32
|
+
description: string
|
|
33
|
+
}[]
|
|
34
|
+
}
|
|
35
|
+
}>
|
|
36
|
+
|
|
37
|
+
const HygraphConfig = React.memo(() => {
|
|
38
|
+
const form = usePreviewModeForm()
|
|
39
|
+
const { control } = form
|
|
40
|
+
|
|
41
|
+
const contentStages = useQuery(ContentStages)
|
|
42
|
+
|
|
43
|
+
const defaultValue = previewModeDefaults().hygraphStage ?? 'PUBLISHED'
|
|
44
|
+
|
|
45
|
+
return useMemo(
|
|
46
|
+
() => (
|
|
47
|
+
<SelectElement
|
|
48
|
+
control={control}
|
|
49
|
+
name='previewData.hygraphStage'
|
|
50
|
+
defaultValue={defaultValue}
|
|
51
|
+
color='secondary'
|
|
52
|
+
select
|
|
53
|
+
label='Hygraph Stage'
|
|
54
|
+
size='small'
|
|
55
|
+
sx={{ width: '150px' }}
|
|
56
|
+
SelectProps={{ MenuProps: { style: { zIndex: 20000 } } }}
|
|
57
|
+
onChange={() => {}}
|
|
58
|
+
options={
|
|
59
|
+
contentStages.loading
|
|
60
|
+
? [{ id: defaultValue, label: defaultValue }]
|
|
61
|
+
: filterNonNullableKeys(contentStages.data?.__type.enumValues).map(({ name }) => ({
|
|
62
|
+
id: name,
|
|
63
|
+
label: name,
|
|
64
|
+
}))
|
|
65
|
+
}
|
|
66
|
+
/>
|
|
67
|
+
),
|
|
68
|
+
[contentStages.data?.__type.enumValues, contentStages.loading, control],
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
export const PreviewModeToolbar = (props: PluginProps<PreviewModeToolbarProps>) => {
|
|
73
|
+
const { Prev, ...rest } = props
|
|
74
|
+
return (
|
|
75
|
+
<>
|
|
76
|
+
<Prev {...rest} />
|
|
77
|
+
<HygraphConfig />
|
|
78
|
+
</>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
@@ -4,6 +4,12 @@ import type { FunctionPlugin } from '@graphcommerce/next-config'
|
|
|
4
4
|
export const func = 'graphqlConfig'
|
|
5
5
|
export const exported = '@graphcommerce/graphql'
|
|
6
6
|
|
|
7
|
+
declare module '@graphcommerce/graphql/config' {
|
|
8
|
+
interface PreviewData {
|
|
9
|
+
hygraphStage?: string
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
const hygraphGraphqlConfig: FunctionPlugin<typeof graphqlConfig> = (prev, config) => {
|
|
8
14
|
const results = prev(config)
|
|
9
15
|
|
|
@@ -14,6 +20,12 @@ const hygraphGraphqlConfig: FunctionPlugin<typeof graphqlConfig> = (prev, config
|
|
|
14
20
|
const hygraphLink = setContext((_, context) => {
|
|
15
21
|
if (!context.headers) context.headers = {}
|
|
16
22
|
context.headers['gcms-locales'] = locales.join(',')
|
|
23
|
+
|
|
24
|
+
const stage = config.previewData?.hygraphStage ?? 'DRAFT'
|
|
25
|
+
if (config.preview) {
|
|
26
|
+
context.headers['gcms-stage'] = stage
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
return context
|
|
18
30
|
})
|
|
19
31
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { previewModeDefaults as base } from '@graphcommerce/ecommerce-ui'
|
|
2
|
+
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
3
|
+
|
|
4
|
+
export const config: PluginConfig = {
|
|
5
|
+
type: 'function',
|
|
6
|
+
module: '@graphcommerce/ecommerce-ui',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const previewModeDefaults: FunctionPlugin<typeof base> = (prev, ...args) => ({
|
|
10
|
+
...prev(...args),
|
|
11
|
+
hygraphStage: 'DRAFT',
|
|
12
|
+
})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { setContext } from '@graphcommerce/graphql'
|
|
2
|
-
import { storefrontConfig } from '@graphcommerce/next-ui'
|
|
3
|
-
|
|
4
|
-
/** Add a gcms-locales header to make sure queries return in a certain language. */
|
|
5
|
-
export const createHygraphLink = (locale?: string) =>
|
|
6
|
-
setContext((_, context) => {
|
|
7
|
-
if (!context.headers) context.headers = {}
|
|
8
|
-
|
|
9
|
-
const locales = storefrontConfig(locale)?.hygraphLocales
|
|
10
|
-
if (locales) context.headers['gcms-locales'] = locales.join(',')
|
|
11
|
-
|
|
12
|
-
return context
|
|
13
|
-
})
|