@graphcommerce/hygraph-dynamic-rows 8.0.0-canary.80 → 8.0.0-canary.82
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 +4 -0
- package/graphql/DynamicRow.graphql +11 -0
- package/lib/hygraphDynamicRows.ts +10 -8
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -120,22 +120,24 @@ export async function hygraphDynamicRows(
|
|
|
120
120
|
const [pageResult, dynamicResult] = await Promise.all([pageQuery, dynamicRows])
|
|
121
121
|
|
|
122
122
|
// Create a copy of the content array.
|
|
123
|
-
const content =
|
|
123
|
+
const content = pageResult.data.pages[0]?.content ?? []
|
|
124
124
|
|
|
125
125
|
dynamicResult?.data.dynamicRows.forEach((dynamicRow) => {
|
|
126
|
-
const { placement, target, row } = dynamicRow
|
|
127
|
-
if (!row) return
|
|
126
|
+
const { placement, target, rows, row } = dynamicRow
|
|
127
|
+
if (!rows && !row) return
|
|
128
|
+
|
|
129
|
+
const rowsToMerge = rows.length > 0 ? rows : [row]
|
|
128
130
|
|
|
129
131
|
if (!target) {
|
|
130
|
-
if (placement === 'BEFORE') content.unshift(
|
|
131
|
-
else content.push(
|
|
132
|
+
if (placement === 'BEFORE') content.unshift(...rowsToMerge)
|
|
133
|
+
else content.push(...rowsToMerge)
|
|
132
134
|
return
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
const targetIdx = content.findIndex((c) => c.id === target.id)
|
|
136
|
-
if (placement === 'BEFORE') content.splice(targetIdx, 0,
|
|
137
|
-
if (placement === 'AFTER') content.splice(targetIdx + 1, 0,
|
|
138
|
-
if (placement === 'REPLACE') content.splice(targetIdx, 1,
|
|
138
|
+
if (placement === 'BEFORE') content.splice(targetIdx, 0, ...rowsToMerge)
|
|
139
|
+
if (placement === 'AFTER') content.splice(targetIdx + 1, 0, ...rowsToMerge)
|
|
140
|
+
if (placement === 'REPLACE') content.splice(targetIdx, 1, ...rowsToMerge)
|
|
139
141
|
})
|
|
140
142
|
|
|
141
143
|
if (!content.length) return pageResult
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/hygraph-dynamic-rows",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "8.0.0-canary.
|
|
5
|
+
"version": "8.0.0-canary.82",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@graphcommerce/eslint-config-pwa": "^8.0.0-canary.
|
|
16
|
-
"@graphcommerce/graphcms-ui": "^8.0.0-canary.
|
|
17
|
-
"@graphcommerce/graphql": "^8.0.0-canary.
|
|
18
|
-
"@graphcommerce/image": "^8.0.0-canary.
|
|
19
|
-
"@graphcommerce/next-ui": "^8.0.0-canary.
|
|
20
|
-
"@graphcommerce/prettier-config-pwa": "^8.0.0-canary.
|
|
21
|
-
"@graphcommerce/typescript-config-pwa": "^8.0.0-canary.
|
|
15
|
+
"@graphcommerce/eslint-config-pwa": "^8.0.0-canary.82",
|
|
16
|
+
"@graphcommerce/graphcms-ui": "^8.0.0-canary.82",
|
|
17
|
+
"@graphcommerce/graphql": "^8.0.0-canary.82",
|
|
18
|
+
"@graphcommerce/image": "^8.0.0-canary.82",
|
|
19
|
+
"@graphcommerce/next-ui": "^8.0.0-canary.82",
|
|
20
|
+
"@graphcommerce/prettier-config-pwa": "^8.0.0-canary.82",
|
|
21
|
+
"@graphcommerce/typescript-config-pwa": "^8.0.0-canary.82",
|
|
22
22
|
"@mui/material": "^5.10.16",
|
|
23
23
|
"next": "*",
|
|
24
24
|
"react": "^18.2.0",
|