@stoker-platform/web-app 0.5.226 → 0.5.228

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @stoker-platform/web-app
2
2
 
3
+ ## 0.5.228
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @stoker-platform/node-client@0.5.89
9
+
10
+ ## 0.5.227
11
+
12
+ ### Patch Changes
13
+
14
+ - feat: use equality filter for one-to relation filters
15
+
3
16
  ## 0.5.226
4
17
 
5
18
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/web-app",
3
- "version": "0.5.226",
3
+ "version": "0.5.228",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
@@ -51,7 +51,7 @@
51
51
  "@radix-ui/react-tooltip": "^1.2.8",
52
52
  "@react-google-maps/api": "^2.20.8",
53
53
  "@sentry/react": "^10.56.0",
54
- "@stoker-platform/node-client": "0.5.88",
54
+ "@stoker-platform/node-client": "0.5.89",
55
55
  "@stoker-platform/utils": "0.5.79",
56
56
  "@stoker-platform/web-client": "0.5.94",
57
57
  "@tanstack/react-table": "^8.21.3",
@@ -1541,9 +1541,14 @@ function Collection({
1541
1541
  }
1542
1542
  }
1543
1543
  if (relationList) {
1544
+ const relationListField = getField(fields, relationList.field)
1545
+ const relationListUsesArrayContains = ["ManyToOne", "ManyToMany"].includes(relationListField.type)
1544
1546
  filters.forEach((filter) => {
1545
1547
  if (filter.type === "relation") {
1546
- if (!isPreloadCacheEnabled || filter.field === relationList.field) {
1548
+ if (
1549
+ filter.field === relationList.field ||
1550
+ (!isPreloadCacheEnabled && relationListUsesArrayContains)
1551
+ ) {
1547
1552
  excluded.push(filter.field)
1548
1553
  }
1549
1554
  }
@@ -1553,7 +1558,7 @@ function Collection({
1553
1558
  }
1554
1559
  }
1555
1560
  return excluded
1556
- }, [isPreloadCacheEnabled, cardsConfig, statusField, tab, filters])
1561
+ }, [isPreloadCacheEnabled, cardsConfig, statusField, tab, filters, relationList, fields])
1557
1562
 
1558
1563
  const filtersActive = useMemo(() => {
1559
1564
  return (
package/src/Filters.tsx CHANGED
@@ -103,9 +103,12 @@ export function Filters({
103
103
 
104
104
  const preventChange = isRouteLoadingImmediate.has(location.pathname)
105
105
 
106
- const isArrayOrRelationFilter = useCallback(
106
+ const isArrayContainsFilter = useCallback(
107
107
  (filter: Filter): filter is SelectFilter | RelationFilter => {
108
- if (filter.type === "relation") return true
108
+ if (filter.type === "relation") {
109
+ const fieldSchema = getField(fields, filter.field)
110
+ return ["ManyToOne", "ManyToMany"].includes(fieldSchema.type)
111
+ }
109
112
  if (filter.type === "select") {
110
113
  const fieldSchema = getField(fields, filter.field)
111
114
  return fieldSchema.type === "Array"
@@ -116,11 +119,13 @@ export function Filters({
116
119
  )
117
120
 
118
121
  const isIncludeAssignedActive = useCallback(() => {
119
- if (!isAssigning || !assignable?.includeAssignedInFilters?.length) return false
122
+ if (!isAssigning || !assignable?.includeAssignedInFilters?.length || !relationList) return false
123
+ const relationField = getField(fields, relationList.field)
124
+ if (["OneToOne", "OneToMany"].includes(relationField.type)) return false
120
125
  return assignable.includeAssignedInFilters.some((field) =>
121
126
  filters.some((filter) => filter.type === "select" && filter.field === field && filter.value),
122
127
  )
123
- }, [isAssigning, assignable, filters])
128
+ }, [isAssigning, assignable, filters, relationList, fields])
124
129
 
125
130
  const isMobile = useIsMobile()
126
131
  const someFilterOpen = Object.values(open).some(Boolean)
@@ -213,14 +218,14 @@ export function Filters({
213
218
  }
214
219
  }
215
220
 
216
- const arrayOrRelationFilter = filters.find(
217
- (filter): filter is SelectFilter | RelationFilter => !!filter.value && isArrayOrRelationFilter(filter),
221
+ const arrayContainsFilter = filters.find(
222
+ (filter): filter is SelectFilter | RelationFilter => !!filter.value && isArrayContainsFilter(filter),
218
223
  )
219
- if (arrayOrRelationFilter) {
220
- arrayOrRelationField = arrayOrRelationFilter.field
224
+ if (arrayContainsFilter) {
225
+ arrayOrRelationField = arrayContainsFilter.field
221
226
  }
222
227
  setArrayContainsFilterSet(arrayOrRelationField)
223
- }, [filters, isAssigning, assignable, isPreloadCacheEnabled, isIncludeAssignedActive, isArrayOrRelationFilter])
228
+ }, [filters, isAssigning, assignable, isPreloadCacheEnabled, isIncludeAssignedActive, isArrayContainsFilter])
224
229
 
225
230
  const handleChange = useCallback(
226
231
  (filter: Filter, value: string, type: CollectionField["type"]) => {
@@ -454,19 +459,36 @@ export function Filters({
454
459
  (filter: Filter) => {
455
460
  if (filter.type === "range" || filter.type === "status") return false
456
461
  const fieldSchema = getField(fields, filter.field)
462
+ const relationField = relationList ? getField(fields, relationList.field) : undefined
463
+ const includeAssignedUsesArrayContains =
464
+ isAssigning &&
465
+ !!assignable?.includeAssignedInFilters?.includes(filter.field) &&
466
+ !!relationField &&
467
+ ["ManyToOne", "ManyToMany"].includes(relationField.type)
457
468
  return !!(
458
469
  (!isPreloadCacheEnabled &&
459
470
  arrayContainsFilterSet &&
460
471
  arrayContainsFilterSet !== filter.field &&
461
- (filter.type === "relation" ||
472
+ ((filter.type === "relation" && ["ManyToOne", "ManyToMany"].includes(fieldSchema.type)) ||
462
473
  fieldSchema.type === "Array" ||
463
- (isAssigning && assignable?.includeAssignedInFilters?.includes(filter.field)))) ||
474
+ includeAssignedUsesArrayContains)) ||
464
475
  (isRelationField(fieldSchema) &&
465
476
  connectionStatus === "offline" &&
466
477
  !preloadCacheEnabled(schema.collections[fieldSchema.collection]))
467
478
  )
468
479
  },
469
- [isPreloadCacheEnabled, arrayContainsFilterSet, isRouteLoading, location.pathname, fields],
480
+ [
481
+ isPreloadCacheEnabled,
482
+ arrayContainsFilterSet,
483
+ isRouteLoading,
484
+ location.pathname,
485
+ fields,
486
+ relationList,
487
+ isAssigning,
488
+ assignable,
489
+ connectionStatus,
490
+ schema,
491
+ ],
470
492
  )
471
493
 
472
494
  return (
@@ -152,11 +152,17 @@ export const FiltersProvider: React.FC<FiltersProviderProps> = ({
152
152
  if (includeValueInFilters) {
153
153
  filterValues.push(includeValueInFilters.includeValue as string | number)
154
154
  }
155
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
156
+ const relationField = getField(fields, relationList!.field)
157
+ const assignedConstraint = ["OneToOne", "OneToMany"].includes(relationField.type)
158
+ ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
159
+ where(`${relationList!.field}_Single.id`, "==", relationParent!.id)
160
+ : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
161
+ where(`${relationList!.field}_Array`, "array-contains", relationParent!.id)
155
162
  constraints.push(
156
163
  or(
157
164
  where(filter.field, "in", filterValues),
158
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
159
- where(`${relationList!.field}_Array`, "array-contains", relationParent!.id),
165
+ assignedConstraint,
160
166
  ) as unknown as QueryConstraint,
161
167
  )
162
168
  } else if (isAssigning && includeValueInFilters) {
@@ -169,7 +175,11 @@ export const FiltersProvider: React.FC<FiltersProviderProps> = ({
169
175
  }
170
176
  if (filter.type === "relation") {
171
177
  const field = getField(fields, filter.field)
172
- constraints.push(where(`${field.name}_Array`, "array-contains", filter.value))
178
+ if (["OneToOne", "OneToMany"].includes(field.type)) {
179
+ constraints.push(where(`${field.name}_Single.id`, "==", filter.value))
180
+ } else {
181
+ constraints.push(where(`${field.name}_Array`, "array-contains", filter.value))
182
+ }
173
183
  }
174
184
  })
175
185
  if (!isPreloadCacheEnabled) {
@@ -240,7 +250,11 @@ export const FiltersProvider: React.FC<FiltersProviderProps> = ({
240
250
  }
241
251
  if (filter.type === "relation") {
242
252
  const field = getField(fields, filter.field)
243
- constraints.push([`${field.name}_Array`, "array-contains", filter.value])
253
+ if (["OneToOne", "OneToMany"].includes(field.type)) {
254
+ constraints.push([`${field.name}_Single.id`, "==", filter.value])
255
+ } else {
256
+ constraints.push([`${field.name}_Array`, "array-contains", filter.value])
257
+ }
244
258
  }
245
259
  })
246
260
  if (!isPreloadCacheEnabled) {