@graphcommerce/hygraph-dynamic-rows-ui 7.1.0-canary.57 → 7.1.0-canary.59
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 +8 -0
- package/components/PropertyPicker.tsx +22 -17
- package/components/Setup.tsx +24 -16
- package/next.config.js +8 -0
- package/package.json +5 -5
- package/pages/property-picker.tsx +1 -29
- package/pages/setup.tsx +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @graphcommerce/hygraph-dynamic-rows-ui
|
|
2
2
|
|
|
3
|
+
## 7.1.0-canary.59
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2126](https://github.com/graphcommerce-org/graphcommerce/pull/2126) [`bacb3c4f5`](https://github.com/graphcommerce-org/graphcommerce/commit/bacb3c4f5734f7606c5f7049c95d7d86a547641a) - Fix eslint errors in Dynamic Rows UI package ([@JoshuaS98](https://github.com/JoshuaS98))
|
|
8
|
+
|
|
9
|
+
## 7.1.0-canary.58
|
|
10
|
+
|
|
3
11
|
## 7.1.0-canary.57
|
|
4
12
|
|
|
5
13
|
## 7.1.0-canary.56
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
+
import { ApolloClient, InMemoryCache } from '@apollo/client'
|
|
1
2
|
import { useFieldExtension } from '@hygraph/app-sdk-react'
|
|
2
3
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
3
4
|
import { TextField } from '@mui/material'
|
|
4
5
|
import { useEffect, useMemo, useState } from 'react'
|
|
5
|
-
import { ApolloClient, InMemoryCache } from '@apollo/client'
|
|
6
|
-
import { fetchGraphQLInterface } from '../lib/fetchGraphQLInterface'
|
|
7
6
|
import { createOptionsFromInterfaceObject, objectifyGraphQLInterface } from '../lib'
|
|
7
|
+
import { fetchGraphQLInterface } from '../lib/fetchGraphQLInterface'
|
|
8
|
+
import { __Field } from '../types'
|
|
8
9
|
|
|
9
10
|
export function PropertyPicker() {
|
|
10
11
|
const { value, onChange, field, extension } = useFieldExtension()
|
|
11
12
|
const [localValue, setLocalValue] = useState<string | undefined | null>(
|
|
12
13
|
typeof value === 'string' ? value : undefined,
|
|
13
14
|
)
|
|
14
|
-
const [fields, setFields] = useState<
|
|
15
|
+
const [fields, setFields] = useState<__Field[] | null>(null)
|
|
15
16
|
|
|
16
17
|
useEffect(() => {
|
|
17
|
-
onChange(localValue).catch((err) =>
|
|
18
|
+
onChange(localValue).catch((err) => err)
|
|
18
19
|
}, [localValue, onChange])
|
|
19
20
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
const graphQLInterfaceQuery = useMemo(() => {
|
|
22
|
+
const client = new ApolloClient({
|
|
23
|
+
uri:
|
|
24
|
+
typeof extension.config.backend === 'string'
|
|
25
|
+
? extension.config.backend
|
|
26
|
+
: 'https://graphcommerce.vercel.app/api/graphql', // fallback on the standard GraphCommerce Schema
|
|
27
|
+
cache: new InMemoryCache(),
|
|
28
|
+
})
|
|
29
|
+
return fetchGraphQLInterface(client)
|
|
30
|
+
}, [extension.config.backend])
|
|
29
31
|
|
|
30
32
|
// Prepare options
|
|
31
33
|
const numberOptions = useMemo(
|
|
@@ -64,11 +66,14 @@ export function PropertyPicker() {
|
|
|
64
66
|
const options = fieldType === 'ConditionNumber' ? allOptions.number : allOptions.text
|
|
65
67
|
|
|
66
68
|
if (!fields) {
|
|
67
|
-
Promise.resolve(graphQLInterfaceQuery)
|
|
68
|
-
|
|
69
|
+
Promise.resolve(graphQLInterfaceQuery)
|
|
70
|
+
.then((res) => {
|
|
71
|
+
const newFields: __Field[] = res?.data.__type?.fields
|
|
72
|
+
|
|
73
|
+
setFields(newFields)
|
|
74
|
+
})
|
|
75
|
+
.catch((err) => err)
|
|
69
76
|
|
|
70
|
-
setFields(fields)
|
|
71
|
-
})
|
|
72
77
|
return <div>Loading fields...</div>
|
|
73
78
|
}
|
|
74
79
|
if (options.length < 1) return <div>No properties available</div>
|
package/components/Setup.tsx
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { useApp, Wrapper } from '@hygraph/app-sdk-react'
|
|
2
|
-
import styles from './setup.module.css'
|
|
3
2
|
import { useState } from 'react'
|
|
3
|
+
import styles from './setup.module.css'
|
|
4
4
|
|
|
5
5
|
function Install() {
|
|
6
|
-
// @ts-
|
|
6
|
+
// @ts-expect-error - outdated types from @hygraph/app-sdk-react
|
|
7
7
|
const { updateInstallation, installation, showToast, extension } = useApp()
|
|
8
8
|
const installed = installation.status === 'COMPLETED'
|
|
9
9
|
const [gqlUri, setGqlUri] = useState('')
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const changedUri = extension.config.backend !== gqlUri
|
|
12
|
+
|
|
13
|
+
const saveOnClick = () =>
|
|
12
14
|
updateInstallation({
|
|
13
15
|
config: { backend: gqlUri },
|
|
14
16
|
status: 'COMPLETED',
|
|
@@ -20,11 +22,8 @@ function Install() {
|
|
|
20
22
|
isClosable: true,
|
|
21
23
|
position: 'top-left',
|
|
22
24
|
variantColor: 'success',
|
|
23
|
-
}).catch((err) =>
|
|
25
|
+
}).catch((err) => err),
|
|
24
26
|
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const changedUri = extension.config.backend !== gqlUri
|
|
28
27
|
|
|
29
28
|
const installOnClick = () =>
|
|
30
29
|
updateInstallation({
|
|
@@ -38,10 +37,10 @@ function Install() {
|
|
|
38
37
|
isClosable: true,
|
|
39
38
|
position: 'top-left',
|
|
40
39
|
variantColor: 'success',
|
|
41
|
-
}).catch((err) =>
|
|
40
|
+
}).catch((err) => err),
|
|
42
41
|
)
|
|
43
42
|
|
|
44
|
-
const uninstallOnClick =
|
|
43
|
+
const uninstallOnClick = () => {
|
|
45
44
|
updateInstallation({
|
|
46
45
|
config: {},
|
|
47
46
|
status: 'DISABLED',
|
|
@@ -54,7 +53,7 @@ function Install() {
|
|
|
54
53
|
isClosable: true,
|
|
55
54
|
position: 'top-left',
|
|
56
55
|
variantColor: 'success',
|
|
57
|
-
})
|
|
56
|
+
}).catch((err) => err)
|
|
58
57
|
})
|
|
59
58
|
.catch((error) => {
|
|
60
59
|
console.error('Error updating installation', error)
|
|
@@ -63,6 +62,19 @@ function Install() {
|
|
|
63
62
|
return 0
|
|
64
63
|
}
|
|
65
64
|
|
|
65
|
+
let buttonText: string
|
|
66
|
+
let buttonAction: typeof uninstallOnClick | typeof installOnClick
|
|
67
|
+
if (changedUri) {
|
|
68
|
+
buttonText = 'Save'
|
|
69
|
+
buttonAction = saveOnClick
|
|
70
|
+
} else if (installed) {
|
|
71
|
+
buttonText = 'Disable app'
|
|
72
|
+
buttonAction = uninstallOnClick
|
|
73
|
+
} else {
|
|
74
|
+
buttonText = 'Enable app'
|
|
75
|
+
buttonAction = installOnClick
|
|
76
|
+
}
|
|
77
|
+
|
|
66
78
|
return (
|
|
67
79
|
<>
|
|
68
80
|
<>
|
|
@@ -74,12 +86,8 @@ function Install() {
|
|
|
74
86
|
/>
|
|
75
87
|
</>
|
|
76
88
|
|
|
77
|
-
<button
|
|
78
|
-
|
|
79
|
-
className={styles.button}
|
|
80
|
-
onClick={changedUri ? saveOnClick : installed ? uninstallOnClick : installOnClick}
|
|
81
|
-
>
|
|
82
|
-
{changedUri ? 'Save' : installed ? 'Disable app' : 'Enable app'}
|
|
89
|
+
<button type='button' className={styles.button} onClick={buttonAction}>
|
|
90
|
+
{buttonText}
|
|
83
91
|
</button>
|
|
84
92
|
</>
|
|
85
93
|
)
|
package/next.config.js
ADDED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/hygraph-dynamic-rows-ui",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "7.1.0-canary.
|
|
5
|
+
"version": "7.1.0-canary.59",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@apollo/client": "~3.8.7",
|
|
20
|
-
"@graphcommerce/next-config": "7.1.0-canary.
|
|
20
|
+
"@graphcommerce/next-config": "7.1.0-canary.59",
|
|
21
21
|
"@hygraph/app-sdk-react": "^0.0.2",
|
|
22
22
|
"@mui/material": "5.14.7",
|
|
23
23
|
"cross-env": "^7.0.3",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"webpack": "5.88.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@graphcommerce/eslint-config-pwa": "7.1.0-canary.
|
|
33
|
-
"@graphcommerce/prettier-config-pwa": "7.1.0-canary.
|
|
34
|
-
"@graphcommerce/typescript-config-pwa": "7.1.0-canary.
|
|
32
|
+
"@graphcommerce/eslint-config-pwa": "7.1.0-canary.59",
|
|
33
|
+
"@graphcommerce/prettier-config-pwa": "7.1.0-canary.59",
|
|
34
|
+
"@graphcommerce/typescript-config-pwa": "7.1.0-canary.59",
|
|
35
35
|
"@types/react-is": "^18.2.0",
|
|
36
36
|
"eslint": "8.53.0",
|
|
37
37
|
"typescript": "5.1.3"
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'
|
|
2
|
-
import { loadConfig } from '@graphcommerce/next-config'
|
|
3
1
|
import { Wrapper } from '@hygraph/app-sdk-react'
|
|
4
2
|
import React from 'react'
|
|
5
3
|
import { PropertyPicker } from '..'
|
|
6
|
-
import {
|
|
7
|
-
createOptionsFromInterfaceObject,
|
|
8
|
-
objectifyGraphQLInterface,
|
|
9
|
-
fetchGraphQLInterface,
|
|
10
|
-
} from '../lib'
|
|
11
|
-
import { Interface } from '../types'
|
|
12
4
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export default function DRPropertyPicker(props: PropertyPickerProps) {
|
|
5
|
+
export default function DRPropertyPicker() {
|
|
16
6
|
const fieldContainer = React.useRef<HTMLDivElement | null>(null)
|
|
17
7
|
|
|
18
8
|
React.useEffect(() => {
|
|
@@ -51,21 +41,3 @@ export default function DRPropertyPicker(props: PropertyPickerProps) {
|
|
|
51
41
|
</div>
|
|
52
42
|
)
|
|
53
43
|
}
|
|
54
|
-
|
|
55
|
-
export const getStaticProps = async () => {
|
|
56
|
-
const config = loadConfig(process.cwd())
|
|
57
|
-
const staticClient = new ApolloClient({
|
|
58
|
-
link: new HttpLink({
|
|
59
|
-
uri: config.magentoEndpoint,
|
|
60
|
-
fetch,
|
|
61
|
-
}),
|
|
62
|
-
cache: new InMemoryCache(),
|
|
63
|
-
})
|
|
64
|
-
const graphQLInterface = fetchGraphQLInterface(staticClient)
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
props: {
|
|
68
|
-
...(await graphQLInterface).data,
|
|
69
|
-
},
|
|
70
|
-
}
|
|
71
|
-
}
|
package/pages/setup.tsx
CHANGED