@teleporthq/teleport-plugin-next-data-source 0.43.57 → 0.43.60
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/__tests__/_helpers/pagination-widget-fixture.ts +230 -0
- package/__tests__/ecommerce-product-allow-backorders.test.ts +156 -0
- package/__tests__/ecommerce-product-discounts.test.ts +196 -0
- package/__tests__/ecommerce-product-model.test.ts +179 -0
- package/__tests__/infinite-scroll.test.ts +143 -0
- package/__tests__/numbered-pagination.test.ts +113 -0
- package/__tests__/page-reset-on-filter-sort.test.ts +182 -0
- package/__tests__/page-url-sync.test.ts +208 -0
- package/__tests__/product-price-sort.ts +313 -0
- package/__tests__/search-url-sync.test.ts +7 -3
- package/dist/cjs/array-mapper-pagination.d.ts +9 -0
- package/dist/cjs/array-mapper-pagination.d.ts.map +1 -1
- package/dist/cjs/array-mapper-pagination.js.map +1 -1
- package/dist/cjs/count-effect.d.ts +42 -0
- package/dist/cjs/count-effect.d.ts.map +1 -0
- package/dist/cjs/count-effect.js +81 -0
- package/dist/cjs/count-effect.js.map +1 -0
- package/dist/cjs/fetchers/postgresql.d.ts.map +1 -1
- package/dist/cjs/fetchers/postgresql.js +2 -1
- package/dist/cjs/fetchers/postgresql.js.map +1 -1
- package/dist/cjs/fetchers/teleport.d.ts.map +1 -1
- package/dist/cjs/fetchers/teleport.js +3 -2
- package/dist/cjs/fetchers/teleport.js.map +1 -1
- package/dist/cjs/infinite-scroll.d.ts +65 -0
- package/dist/cjs/infinite-scroll.d.ts.map +1 -0
- package/dist/cjs/infinite-scroll.js +190 -0
- package/dist/cjs/infinite-scroll.js.map +1 -0
- package/dist/cjs/numbered-pagination.d.ts +42 -0
- package/dist/cjs/numbered-pagination.d.ts.map +1 -0
- package/dist/cjs/numbered-pagination.js +167 -0
- package/dist/cjs/numbered-pagination.js.map +1 -0
- package/dist/cjs/page-reset.d.ts +42 -0
- package/dist/cjs/page-reset.d.ts.map +1 -0
- package/dist/cjs/page-reset.js +116 -0
- package/dist/cjs/page-reset.js.map +1 -0
- package/dist/cjs/page-url-sync.d.ts +42 -0
- package/dist/cjs/page-url-sync.d.ts.map +1 -0
- package/dist/cjs/page-url-sync.js +180 -0
- package/dist/cjs/page-url-sync.js.map +1 -0
- package/dist/cjs/pagination-controls.d.ts +55 -0
- package/dist/cjs/pagination-controls.d.ts.map +1 -0
- package/dist/cjs/pagination-controls.js +159 -0
- package/dist/cjs/pagination-controls.js.map +1 -0
- package/dist/cjs/pagination-plugin.d.ts.map +1 -1
- package/dist/cjs/pagination-plugin.js +506 -160
- package/dist/cjs/pagination-plugin.js.map +1 -1
- package/dist/cjs/product-price-sort.d.ts +116 -0
- package/dist/cjs/product-price-sort.d.ts.map +1 -0
- package/dist/cjs/product-price-sort.js +169 -0
- package/dist/cjs/product-price-sort.js.map +1 -0
- package/dist/cjs/transformations/ecommerce-product.d.ts +12 -0
- package/dist/cjs/transformations/ecommerce-product.d.ts.map +1 -1
- package/dist/cjs/transformations/ecommerce-product.js +2 -1
- package/dist/cjs/transformations/ecommerce-product.js.map +1 -1
- package/dist/cjs/transformations/index.d.ts +2 -1
- package/dist/cjs/transformations/index.d.ts.map +1 -1
- package/dist/cjs/transformations/index.js +17 -1
- package/dist/cjs/transformations/index.js.map +1 -1
- package/dist/cjs/transformations/shared-utils.d.ts.map +1 -1
- package/dist/cjs/transformations/shared-utils.js +1 -1
- package/dist/cjs/transformations/shared-utils.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/array-mapper-pagination.d.ts +9 -0
- package/dist/esm/array-mapper-pagination.d.ts.map +1 -1
- package/dist/esm/array-mapper-pagination.js.map +1 -1
- package/dist/esm/count-effect.d.ts +42 -0
- package/dist/esm/count-effect.d.ts.map +1 -0
- package/dist/esm/count-effect.js +53 -0
- package/dist/esm/count-effect.js.map +1 -0
- package/dist/esm/fetchers/postgresql.d.ts.map +1 -1
- package/dist/esm/fetchers/postgresql.js +2 -1
- package/dist/esm/fetchers/postgresql.js.map +1 -1
- package/dist/esm/fetchers/teleport.d.ts.map +1 -1
- package/dist/esm/fetchers/teleport.js +3 -2
- package/dist/esm/fetchers/teleport.js.map +1 -1
- package/dist/esm/infinite-scroll.d.ts +65 -0
- package/dist/esm/infinite-scroll.d.ts.map +1 -0
- package/dist/esm/infinite-scroll.js +159 -0
- package/dist/esm/infinite-scroll.js.map +1 -0
- package/dist/esm/numbered-pagination.d.ts +42 -0
- package/dist/esm/numbered-pagination.d.ts.map +1 -0
- package/dist/esm/numbered-pagination.js +138 -0
- package/dist/esm/numbered-pagination.js.map +1 -0
- package/dist/esm/page-reset.d.ts +42 -0
- package/dist/esm/page-reset.d.ts.map +1 -0
- package/dist/esm/page-reset.js +87 -0
- package/dist/esm/page-reset.js.map +1 -0
- package/dist/esm/page-url-sync.d.ts +42 -0
- package/dist/esm/page-url-sync.d.ts.map +1 -0
- package/dist/esm/page-url-sync.js +152 -0
- package/dist/esm/page-url-sync.js.map +1 -0
- package/dist/esm/pagination-controls.d.ts +55 -0
- package/dist/esm/pagination-controls.d.ts.map +1 -0
- package/dist/esm/pagination-controls.js +126 -0
- package/dist/esm/pagination-controls.js.map +1 -0
- package/dist/esm/pagination-plugin.d.ts.map +1 -1
- package/dist/esm/pagination-plugin.js +507 -161
- package/dist/esm/pagination-plugin.js.map +1 -1
- package/dist/esm/product-price-sort.d.ts +116 -0
- package/dist/esm/product-price-sort.d.ts.map +1 -0
- package/dist/esm/product-price-sort.js +160 -0
- package/dist/esm/product-price-sort.js.map +1 -0
- package/dist/esm/transformations/ecommerce-product.d.ts +12 -0
- package/dist/esm/transformations/ecommerce-product.d.ts.map +1 -1
- package/dist/esm/transformations/ecommerce-product.js +3 -2
- package/dist/esm/transformations/ecommerce-product.js.map +1 -1
- package/dist/esm/transformations/index.d.ts +2 -1
- package/dist/esm/transformations/index.d.ts.map +1 -1
- package/dist/esm/transformations/index.js +17 -1
- package/dist/esm/transformations/index.js.map +1 -1
- package/dist/esm/transformations/shared-utils.d.ts.map +1 -1
- package/dist/esm/transformations/shared-utils.js +1 -1
- package/dist/esm/transformations/shared-utils.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/array-mapper-pagination.ts +10 -0
- package/src/count-effect.ts +137 -0
- package/src/fetchers/postgresql.ts +52 -13
- package/src/fetchers/teleport.ts +53 -13
- package/src/infinite-scroll.ts +401 -0
- package/src/numbered-pagination.ts +292 -0
- package/src/page-reset.ts +162 -0
- package/src/page-url-sync.ts +241 -0
- package/src/pagination-controls.ts +176 -0
- package/src/pagination-plugin.ts +755 -346
- package/src/product-price-sort.ts +204 -0
- package/src/transformations/ecommerce-product.ts +141 -10
- package/src/transformations/index.ts +19 -1
- package/src/transformations/shared-utils.ts +14 -0
- package/dist/cjs/array-mapper-registry.d.ts +0 -85
- package/dist/cjs/array-mapper-registry.d.ts.map +0 -1
- package/dist/cjs/array-mapper-registry.js +0 -296
- package/dist/cjs/array-mapper-registry.js.map +0 -1
- package/dist/cjs/pagination-with-count.d.ts +0 -6
- package/dist/cjs/pagination-with-count.d.ts.map +0 -1
- package/dist/cjs/pagination-with-count.js +0 -63
- package/dist/cjs/pagination-with-count.js.map +0 -1
- package/dist/esm/array-mapper-registry.d.ts +0 -85
- package/dist/esm/array-mapper-registry.d.ts.map +0 -1
- package/dist/esm/array-mapper-registry.js +0 -292
- package/dist/esm/array-mapper-registry.js.map +0 -1
- package/dist/esm/pagination-with-count.d.ts +0 -6
- package/dist/esm/pagination-with-count.d.ts.map +0 -1
- package/dist/esm/pagination-with-count.js +0 -34
- package/dist/esm/pagination-with-count.js.map +0 -1
- package/src/array-mapper-registry.ts +0 -416
- package/src/pagination-with-count.ts +0 -89
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ArrayMapperRegistry - Centralized registry for managing array mappers,
|
|
3
|
-
* their associated states, search inputs, and pagination buttons.
|
|
4
|
-
*
|
|
5
|
-
* This ensures consistent index usage across:
|
|
6
|
-
* - Component state declarations
|
|
7
|
-
* - DataProvider params
|
|
8
|
-
* - getStaticProps fetch calls and prop names
|
|
9
|
-
* - Search input bindings
|
|
10
|
-
* - Pagination button bindings
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export type MapperType = 'paginated' | 'pagination-only' | 'search-only' | 'plain'
|
|
14
|
-
|
|
15
|
-
export interface ArrayMapperRegistryEntry {
|
|
16
|
-
registryIndex: number
|
|
17
|
-
type: MapperType
|
|
18
|
-
dataSourceIdentifier: string
|
|
19
|
-
arrayMapperRenderProp: string
|
|
20
|
-
uidlGlobalIndex: number
|
|
21
|
-
|
|
22
|
-
paginated: boolean
|
|
23
|
-
searchEnabled: boolean
|
|
24
|
-
perPage: number
|
|
25
|
-
searchDebounce: number
|
|
26
|
-
searchDefaultValue?: string
|
|
27
|
-
queryColumns: string[]
|
|
28
|
-
|
|
29
|
-
stateVarPrefix: string
|
|
30
|
-
pageStateVar?: string
|
|
31
|
-
setPageStateVar?: string
|
|
32
|
-
maxPagesStateVar?: string
|
|
33
|
-
setMaxPagesStateVar?: string
|
|
34
|
-
combinedStateVar?: string
|
|
35
|
-
setCombinedStateVar?: string
|
|
36
|
-
searchQueryVar?: string
|
|
37
|
-
setSearchQueryVar?: string
|
|
38
|
-
debouncedSearchQueryVar?: string
|
|
39
|
-
setDebouncedSearchQueryVar?: string
|
|
40
|
-
skipDebounceRefVar?: string
|
|
41
|
-
|
|
42
|
-
getStaticPropsDataVar: string
|
|
43
|
-
getStaticPropsMaxPagesVar: string
|
|
44
|
-
getStaticPropsPropName: string
|
|
45
|
-
getStaticPropsMaxPagesPropName: string
|
|
46
|
-
|
|
47
|
-
searchInputClass?: string
|
|
48
|
-
paginationNodeClass?: string
|
|
49
|
-
prevButtonClass?: string
|
|
50
|
-
nextButtonClass?: string
|
|
51
|
-
|
|
52
|
-
dataProviderJSX?: any
|
|
53
|
-
searchInputJSX?: any
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class ArrayMapperRegistry {
|
|
57
|
-
private entries: ArrayMapperRegistryEntry[] = []
|
|
58
|
-
private paginatedCount = 0
|
|
59
|
-
private paginationOnlyCount = 0
|
|
60
|
-
private searchOnlyCount = 0
|
|
61
|
-
private plainCount = 0
|
|
62
|
-
|
|
63
|
-
registerFromUIDL(config: {
|
|
64
|
-
dataSourceIdentifier: string
|
|
65
|
-
arrayMapperRenderProp: string
|
|
66
|
-
uidlGlobalIndex: number
|
|
67
|
-
paginated: boolean
|
|
68
|
-
searchEnabled: boolean
|
|
69
|
-
perPage?: number
|
|
70
|
-
searchDebounce?: number
|
|
71
|
-
searchDefaultValue?: string
|
|
72
|
-
queryColumns?: string[]
|
|
73
|
-
}): ArrayMapperRegistryEntry {
|
|
74
|
-
const type = this.determineType(config.paginated, config.searchEnabled)
|
|
75
|
-
const typeIndex = this.getTypeIndex(type)
|
|
76
|
-
const registryIndex = this.entries.length
|
|
77
|
-
|
|
78
|
-
const stateVarPrefix = this.generateStateVarPrefix(type, typeIndex)
|
|
79
|
-
|
|
80
|
-
const entry: ArrayMapperRegistryEntry = {
|
|
81
|
-
registryIndex,
|
|
82
|
-
type,
|
|
83
|
-
dataSourceIdentifier: config.dataSourceIdentifier,
|
|
84
|
-
arrayMapperRenderProp: config.arrayMapperRenderProp,
|
|
85
|
-
uidlGlobalIndex: config.uidlGlobalIndex,
|
|
86
|
-
|
|
87
|
-
paginated: config.paginated,
|
|
88
|
-
searchEnabled: config.searchEnabled,
|
|
89
|
-
perPage: config.perPage || 10,
|
|
90
|
-
searchDebounce: config.searchDebounce || 300,
|
|
91
|
-
searchDefaultValue: config.searchDefaultValue,
|
|
92
|
-
queryColumns: config.queryColumns || [],
|
|
93
|
-
|
|
94
|
-
stateVarPrefix,
|
|
95
|
-
...this.generateStateVarNames(stateVarPrefix, config.paginated, config.searchEnabled),
|
|
96
|
-
...this.generateGetStaticPropsVarNames(config.dataSourceIdentifier, type, typeIndex),
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
this.entries.push(entry)
|
|
100
|
-
this.incrementTypeCount(type)
|
|
101
|
-
|
|
102
|
-
return entry
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
getEntry(registryIndex: number): ArrayMapperRegistryEntry | undefined {
|
|
106
|
-
return this.entries[registryIndex]
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
getEntryByUIDLIndex(uidlGlobalIndex: number): ArrayMapperRegistryEntry | undefined {
|
|
110
|
-
return this.entries.find((e) => e.uidlGlobalIndex === uidlGlobalIndex)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
getEntriesByType(type: MapperType): ArrayMapperRegistryEntry[] {
|
|
114
|
-
return this.entries.filter((e) => e.type === type)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
getAllEntries(): ArrayMapperRegistryEntry[] {
|
|
118
|
-
return [...this.entries]
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
getPaginatedEntries(): ArrayMapperRegistryEntry[] {
|
|
122
|
-
return this.getEntriesByType('paginated')
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
getPaginationOnlyEntries(): ArrayMapperRegistryEntry[] {
|
|
126
|
-
return this.getEntriesByType('pagination-only')
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
getSearchOnlyEntries(): ArrayMapperRegistryEntry[] {
|
|
130
|
-
return this.getEntriesByType('search-only')
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
getPlainEntries(): ArrayMapperRegistryEntry[] {
|
|
134
|
-
return this.getEntriesByType('plain')
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
updateJSXReferences(
|
|
138
|
-
registryIndex: number,
|
|
139
|
-
updates: Partial<
|
|
140
|
-
Pick<
|
|
141
|
-
ArrayMapperRegistryEntry,
|
|
142
|
-
| 'dataProviderJSX'
|
|
143
|
-
| 'searchInputJSX'
|
|
144
|
-
| 'searchInputClass'
|
|
145
|
-
| 'paginationNodeClass'
|
|
146
|
-
| 'prevButtonClass'
|
|
147
|
-
| 'nextButtonClass'
|
|
148
|
-
>
|
|
149
|
-
>
|
|
150
|
-
): void {
|
|
151
|
-
const entry = this.entries[registryIndex]
|
|
152
|
-
if (entry) {
|
|
153
|
-
Object.assign(entry, updates)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
getStateInitializationMaxPagesPropName(entry: ArrayMapperRegistryEntry): string {
|
|
158
|
-
return entry.getStaticPropsMaxPagesPropName
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
toDebugSummary(): string {
|
|
162
|
-
return JSON.stringify(
|
|
163
|
-
this.entries.map((e) => ({
|
|
164
|
-
registryIndex: e.registryIndex,
|
|
165
|
-
type: e.type,
|
|
166
|
-
dataSource: e.dataSourceIdentifier,
|
|
167
|
-
renderProp: e.arrayMapperRenderProp,
|
|
168
|
-
uidlIndex: e.uidlGlobalIndex,
|
|
169
|
-
statePrefix: e.stateVarPrefix,
|
|
170
|
-
getStaticPropsProp: e.getStaticPropsPropName,
|
|
171
|
-
})),
|
|
172
|
-
null,
|
|
173
|
-
2
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
private determineType(paginated: boolean, searchEnabled: boolean): MapperType {
|
|
178
|
-
if (paginated && searchEnabled) {
|
|
179
|
-
return 'paginated'
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (paginated && !searchEnabled) {
|
|
183
|
-
return 'pagination-only'
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (!paginated && searchEnabled) {
|
|
187
|
-
return 'search-only'
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return 'plain'
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
private getTypeIndex(type: MapperType): number {
|
|
194
|
-
switch (type) {
|
|
195
|
-
case 'paginated':
|
|
196
|
-
return this.paginatedCount
|
|
197
|
-
case 'pagination-only':
|
|
198
|
-
return this.paginationOnlyCount
|
|
199
|
-
case 'search-only':
|
|
200
|
-
return this.searchOnlyCount
|
|
201
|
-
case 'plain':
|
|
202
|
-
return this.plainCount
|
|
203
|
-
default:
|
|
204
|
-
return 0
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
private incrementTypeCount(type: MapperType): void {
|
|
209
|
-
switch (type) {
|
|
210
|
-
case 'paginated':
|
|
211
|
-
this.paginatedCount++
|
|
212
|
-
break
|
|
213
|
-
case 'pagination-only':
|
|
214
|
-
this.paginationOnlyCount++
|
|
215
|
-
break
|
|
216
|
-
case 'search-only':
|
|
217
|
-
this.searchOnlyCount++
|
|
218
|
-
break
|
|
219
|
-
case 'plain':
|
|
220
|
-
this.plainCount++
|
|
221
|
-
break
|
|
222
|
-
default:
|
|
223
|
-
break
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
private generateStateVarPrefix(type: MapperType, typeIndex: number): string {
|
|
228
|
-
switch (type) {
|
|
229
|
-
case 'paginated':
|
|
230
|
-
return `pg_${typeIndex}`
|
|
231
|
-
case 'pagination-only':
|
|
232
|
-
return `paginationOnly_${typeIndex}`
|
|
233
|
-
case 'search-only':
|
|
234
|
-
return `searchOnly_${typeIndex}`
|
|
235
|
-
case 'plain':
|
|
236
|
-
return `plain_${typeIndex}`
|
|
237
|
-
default:
|
|
238
|
-
return ''
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
private generateStateVarNames(
|
|
243
|
-
prefix: string,
|
|
244
|
-
paginated: boolean,
|
|
245
|
-
searchEnabled: boolean
|
|
246
|
-
): Partial<ArrayMapperRegistryEntry> {
|
|
247
|
-
const result: Partial<ArrayMapperRegistryEntry> = {}
|
|
248
|
-
|
|
249
|
-
if (paginated) {
|
|
250
|
-
if (searchEnabled) {
|
|
251
|
-
result.combinedStateVar = `paginationState_${prefix}`
|
|
252
|
-
result.setCombinedStateVar = `setPaginationState_${prefix}`
|
|
253
|
-
result.pageStateVar = `paginationState_${prefix}.page`
|
|
254
|
-
result.setPageStateVar = `setPaginationState_${prefix}`
|
|
255
|
-
} else {
|
|
256
|
-
result.pageStateVar = `${prefix}_page`
|
|
257
|
-
result.setPageStateVar = `set${this.capitalize(prefix)}_page`
|
|
258
|
-
}
|
|
259
|
-
result.maxPagesStateVar = `pagination_${prefix}_maxPages`
|
|
260
|
-
result.setMaxPagesStateVar = `setPagination_${prefix}_maxPages`
|
|
261
|
-
} else {
|
|
262
|
-
result.pageStateVar = ''
|
|
263
|
-
result.setPageStateVar = ''
|
|
264
|
-
result.maxPagesStateVar = ''
|
|
265
|
-
result.setMaxPagesStateVar = ''
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (searchEnabled) {
|
|
269
|
-
result.searchQueryVar = `search_${prefix}_query`
|
|
270
|
-
result.setSearchQueryVar = `setSearch_${prefix}_query`
|
|
271
|
-
result.debouncedSearchQueryVar = `debouncedSearch_${prefix}_query`
|
|
272
|
-
result.setDebouncedSearchQueryVar = `setDebouncedSearch_${prefix}_query`
|
|
273
|
-
result.skipDebounceRefVar = `skipDebounceOnMount_${prefix}`
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
return result
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
private generateGetStaticPropsVarNames(
|
|
280
|
-
dataSourceIdentifier: string,
|
|
281
|
-
type: MapperType,
|
|
282
|
-
typeIndex: number
|
|
283
|
-
): Pick<
|
|
284
|
-
ArrayMapperRegistryEntry,
|
|
285
|
-
| 'getStaticPropsDataVar'
|
|
286
|
-
| 'getStaticPropsMaxPagesVar'
|
|
287
|
-
| 'getStaticPropsPropName'
|
|
288
|
-
| 'getStaticPropsMaxPagesPropName'
|
|
289
|
-
> {
|
|
290
|
-
let suffix: string
|
|
291
|
-
switch (type) {
|
|
292
|
-
case 'paginated':
|
|
293
|
-
suffix = `pg_${typeIndex}`
|
|
294
|
-
break
|
|
295
|
-
case 'pagination-only':
|
|
296
|
-
suffix = `paginationOnly_${typeIndex}`
|
|
297
|
-
break
|
|
298
|
-
case 'search-only':
|
|
299
|
-
suffix = `searchOnly_${typeIndex}`
|
|
300
|
-
break
|
|
301
|
-
case 'plain':
|
|
302
|
-
suffix = `plain_${typeIndex}`
|
|
303
|
-
break
|
|
304
|
-
default:
|
|
305
|
-
suffix = `plain_${typeIndex}`
|
|
306
|
-
break
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const dataVar = `${dataSourceIdentifier}_${suffix}`
|
|
310
|
-
const maxPagesVar = `${dataSourceIdentifier}_${suffix}_maxPages`
|
|
311
|
-
|
|
312
|
-
return {
|
|
313
|
-
getStaticPropsDataVar: dataVar,
|
|
314
|
-
getStaticPropsMaxPagesVar: maxPagesVar,
|
|
315
|
-
getStaticPropsPropName: dataVar,
|
|
316
|
-
getStaticPropsMaxPagesPropName: maxPagesVar,
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
private capitalize(str: string): string {
|
|
321
|
-
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export function createRegistryFromUIDL(uidlNode: any, allResources: any): ArrayMapperRegistry {
|
|
326
|
-
const registry = new ArrayMapperRegistry()
|
|
327
|
-
|
|
328
|
-
const visitedRepeaterKeys = new Set<string>()
|
|
329
|
-
let uidlGlobalIndex = 0
|
|
330
|
-
|
|
331
|
-
const findQueryColumns = (
|
|
332
|
-
resourceId: string,
|
|
333
|
-
nodeResource: any,
|
|
334
|
-
registryResources: any
|
|
335
|
-
): string[] | undefined => {
|
|
336
|
-
if (nodeResource?.params?.queryColumns) {
|
|
337
|
-
const val = nodeResource.params.queryColumns
|
|
338
|
-
if (val.type === 'static' && Array.isArray(val.content)) {
|
|
339
|
-
return val.content
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
if (registryResources?.items?.[resourceId]?.params?.queryColumns) {
|
|
343
|
-
const val = registryResources.items[resourceId].params.queryColumns
|
|
344
|
-
if (val.type === 'static' && Array.isArray(val.content)) {
|
|
345
|
-
return val.content
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
return undefined
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const traverse = (node: any, currentDataSourceId?: string): void => {
|
|
352
|
-
if (!node || typeof node !== 'object') {
|
|
353
|
-
return
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
if (node.type === 'data-source-list' && node.content?.renderPropIdentifier) {
|
|
357
|
-
currentDataSourceId = node.content.renderPropIdentifier
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (node.type === 'cms-list-repeater' && node.content?.renderPropIdentifier) {
|
|
361
|
-
const c = node.content
|
|
362
|
-
const repeaterKey = `${c.renderPropIdentifier}|${c.paginated}|${c.searchEnabled}|${
|
|
363
|
-
c.perPage || 'default'
|
|
364
|
-
}|${c.source || ''}`
|
|
365
|
-
|
|
366
|
-
if (visitedRepeaterKeys.has(repeaterKey)) {
|
|
367
|
-
return
|
|
368
|
-
}
|
|
369
|
-
visitedRepeaterKeys.add(repeaterKey)
|
|
370
|
-
|
|
371
|
-
const resourceId = c.resource?.id
|
|
372
|
-
let queryColumns: string[] | undefined
|
|
373
|
-
if (resourceId) {
|
|
374
|
-
queryColumns = findQueryColumns(resourceId, c.resource, allResources)
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const rawDefault = c.searchDefaultValue
|
|
378
|
-
const searchDefaultValue =
|
|
379
|
-
rawDefault &&
|
|
380
|
-
rawDefault.type === 'static' &&
|
|
381
|
-
typeof rawDefault.content === 'string' &&
|
|
382
|
-
rawDefault.content.length > 0
|
|
383
|
-
? rawDefault.content
|
|
384
|
-
: undefined
|
|
385
|
-
|
|
386
|
-
registry.registerFromUIDL({
|
|
387
|
-
dataSourceIdentifier: currentDataSourceId || 'unknown',
|
|
388
|
-
arrayMapperRenderProp: c.renderPropIdentifier,
|
|
389
|
-
uidlGlobalIndex: uidlGlobalIndex++,
|
|
390
|
-
paginated: !!c.paginated,
|
|
391
|
-
searchEnabled: !!c.searchEnabled,
|
|
392
|
-
perPage: c.perPage,
|
|
393
|
-
searchDebounce: c.searchDebounce,
|
|
394
|
-
searchDefaultValue,
|
|
395
|
-
queryColumns,
|
|
396
|
-
})
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
if (node.content?.children && Array.isArray(node.content.children)) {
|
|
400
|
-
node.content.children.forEach((child: any) => traverse(child, currentDataSourceId))
|
|
401
|
-
}
|
|
402
|
-
if (node.content?.node) {
|
|
403
|
-
traverse(node.content.node, currentDataSourceId)
|
|
404
|
-
}
|
|
405
|
-
if (node.content?.nodes) {
|
|
406
|
-
Object.values(node.content.nodes).forEach((n: any) => traverse(n, currentDataSourceId))
|
|
407
|
-
}
|
|
408
|
-
if (Array.isArray(node.children)) {
|
|
409
|
-
node.children.forEach((child: any) => traverse(child, currentDataSourceId))
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
traverse(uidlNode)
|
|
414
|
-
|
|
415
|
-
return registry
|
|
416
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import * as types from '@babel/types'
|
|
2
|
-
import { ArrayMapperPaginationInfo } from './array-mapper-pagination'
|
|
3
|
-
|
|
4
|
-
export function generateTotalPagesState(
|
|
5
|
-
info: ArrayMapperPaginationInfo
|
|
6
|
-
): types.VariableDeclaration {
|
|
7
|
-
const totalStateVar = `pagination_${info.paginationNodeId}_total`
|
|
8
|
-
const setTotalStateVar = `setPagination_${info.paginationNodeId}_total`
|
|
9
|
-
|
|
10
|
-
return types.variableDeclaration('const', [
|
|
11
|
-
types.variableDeclarator(
|
|
12
|
-
types.arrayPattern([types.identifier(totalStateVar), types.identifier(setTotalStateVar)]),
|
|
13
|
-
types.callExpression(types.identifier('useState'), [types.numericLiteral(0)])
|
|
14
|
-
),
|
|
15
|
-
])
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function generateTotalPagesCalculation(
|
|
19
|
-
info: ArrayMapperPaginationInfo
|
|
20
|
-
): types.VariableDeclaration {
|
|
21
|
-
const totalStateVar = `pagination_${info.paginationNodeId}_total`
|
|
22
|
-
const totalPagesVar = `pagination_${info.paginationNodeId}_totalPages`
|
|
23
|
-
|
|
24
|
-
return types.variableDeclaration('const', [
|
|
25
|
-
types.variableDeclarator(
|
|
26
|
-
types.identifier(totalPagesVar),
|
|
27
|
-
types.callExpression(
|
|
28
|
-
types.memberExpression(types.identifier('Math'), types.identifier('ceil')),
|
|
29
|
-
[
|
|
30
|
-
types.binaryExpression(
|
|
31
|
-
'/',
|
|
32
|
-
types.identifier(totalStateVar),
|
|
33
|
-
types.numericLiteral(info.perPage)
|
|
34
|
-
),
|
|
35
|
-
]
|
|
36
|
-
)
|
|
37
|
-
),
|
|
38
|
-
])
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function wrapFetchDataWithTotalExtraction(
|
|
42
|
-
fetchDataExpr: types.ArrowFunctionExpression,
|
|
43
|
-
setTotalStateVar: string
|
|
44
|
-
): types.ArrowFunctionExpression {
|
|
45
|
-
// Wrap the existing fetchData to extract total from response
|
|
46
|
-
const wrappedBody = types.blockStatement([
|
|
47
|
-
types.returnStatement(
|
|
48
|
-
types.callExpression(
|
|
49
|
-
types.memberExpression(
|
|
50
|
-
types.callExpression(fetchDataExpr.body as types.Expression, []),
|
|
51
|
-
types.identifier('then')
|
|
52
|
-
),
|
|
53
|
-
[
|
|
54
|
-
types.arrowFunctionExpression(
|
|
55
|
-
[types.identifier('response')],
|
|
56
|
-
types.blockStatement([
|
|
57
|
-
types.ifStatement(
|
|
58
|
-
types.logicalExpression(
|
|
59
|
-
'&&',
|
|
60
|
-
types.identifier('response'),
|
|
61
|
-
types.memberExpression(types.identifier('response'), types.identifier('total'))
|
|
62
|
-
),
|
|
63
|
-
types.blockStatement([
|
|
64
|
-
types.expressionStatement(
|
|
65
|
-
types.callExpression(types.identifier(setTotalStateVar), [
|
|
66
|
-
types.memberExpression(
|
|
67
|
-
types.identifier('response'),
|
|
68
|
-
types.identifier('total')
|
|
69
|
-
),
|
|
70
|
-
])
|
|
71
|
-
),
|
|
72
|
-
])
|
|
73
|
-
),
|
|
74
|
-
types.returnStatement(
|
|
75
|
-
types.conditionalExpression(
|
|
76
|
-
types.memberExpression(types.identifier('response'), types.identifier('data')),
|
|
77
|
-
types.memberExpression(types.identifier('response'), types.identifier('data')),
|
|
78
|
-
types.identifier('response')
|
|
79
|
-
)
|
|
80
|
-
),
|
|
81
|
-
])
|
|
82
|
-
),
|
|
83
|
-
]
|
|
84
|
-
)
|
|
85
|
-
),
|
|
86
|
-
])
|
|
87
|
-
|
|
88
|
-
return types.arrowFunctionExpression(fetchDataExpr.params, wrappedBody)
|
|
89
|
-
}
|