@stoker-platform/web-app 0.5.202 → 0.5.203

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,14 @@
1
1
  # @stoker-platform/web-app
2
2
 
3
+ ## 0.5.203
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: add filter condition method
8
+ - @stoker-platform/node-client@0.5.79
9
+ - @stoker-platform/utils@0.5.70
10
+ - @stoker-platform/web-client@0.5.83
11
+
3
12
  ## 0.5.202
4
13
 
5
14
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/web-app",
3
- "version": "0.5.202",
3
+ "version": "0.5.203",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
@@ -51,9 +51,9 @@
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.78",
55
- "@stoker-platform/utils": "0.5.69",
56
- "@stoker-platform/web-client": "0.5.82",
54
+ "@stoker-platform/node-client": "0.5.79",
55
+ "@stoker-platform/utils": "0.5.70",
56
+ "@stoker-platform/web-client": "0.5.83",
57
57
  "@tanstack/react-table": "^8.21.3",
58
58
  "@types/react": "18.3.13",
59
59
  "@types/react-dom": "18.3.1",
@@ -529,7 +529,7 @@ function Collection({
529
529
  : Math.min(itemsPerPage || 10, Math.max(1, Math.floor(30 / disjunctions)))
530
530
  let hitsPerPage = 0
531
531
  if (exactPhrase && !(hasEntityRestrictions.length > 0 || hasEntityParentFilters.length > 0)) {
532
- hitsPerPage = 1000
532
+ hitsPerPage = 500
533
533
  } else {
534
534
  hitsPerPage = batchSize
535
535
  }
@@ -2285,6 +2285,8 @@ function Collection({
2285
2285
  collection={collection}
2286
2286
  excluded={excludedFilters}
2287
2287
  relationList={relationList}
2288
+ relationCollection={relationCollection}
2289
+ relationParent={relationParent}
2288
2290
  assignable={assignable}
2289
2291
  isAssigning={displayIsAssigning}
2290
2292
  />
package/src/Filters.tsx CHANGED
@@ -54,11 +54,21 @@ interface FiltersProps {
54
54
  collection: CollectionSchema
55
55
  excluded: string[]
56
56
  relationList?: RelationList
57
+ relationCollection?: CollectionSchema
58
+ relationParent?: StokerRecord
57
59
  assignable?: Assignable
58
60
  isAssigning?: boolean
59
61
  }
60
62
 
61
- export function Filters({ collection, excluded, relationList, assignable, isAssigning }: FiltersProps) {
63
+ export function Filters({
64
+ collection,
65
+ excluded,
66
+ relationList,
67
+ relationCollection,
68
+ relationParent,
69
+ assignable,
70
+ isAssigning,
71
+ }: FiltersProps) {
62
72
  const { labels, fields } = collection
63
73
  const location = useLocation()
64
74
  const schema = getSchema()
@@ -446,6 +456,12 @@ export function Filters({ collection, excluded, relationList, assignable, isAssi
446
456
  return (
447
457
  <div className="flex flex-col gap-6">
448
458
  {filters.map((filter: Filter) => {
459
+ if (
460
+ "condition" in filter &&
461
+ filter.condition &&
462
+ filter.condition(relationCollection, relationParent, isAssigning) === false
463
+ )
464
+ return null
449
465
  if (filter.type === "relation" && !hasRelationFilterAccess(filter)) return
450
466
  if (filter.type === "status" || filter.type === "range") return
451
467
  const field = getField(fields, filter.field)
@@ -474,7 +490,7 @@ export function Filters({ collection, excluded, relationList, assignable, isAssi
474
490
  <Label htmlFor={title}>{title}:</Label>
475
491
  <RadioGroup defaultValue="no_selection" className="mt-2">
476
492
  {values.map((value: string) => {
477
- if (filter.condition && filter.condition(value) === false) return null
493
+ if (filter.filterValues && filter.filterValues(value) === false) return null
478
494
  return (
479
495
  <div key={value} className="flex items-center space-x-2">
480
496
  <RadioGroupItem
@@ -525,7 +541,7 @@ export function Filters({ collection, excluded, relationList, assignable, isAssi
525
541
  <Label htmlFor={title}>{title}:</Label>
526
542
  <div className="mt-2 flex flex-col gap-2">
527
543
  {values.map((value: string) => {
528
- if (filter.condition && filter.condition(value) === false) return null
544
+ if (filter.filterValues && filter.filterValues(value) === false) return null
529
545
  return (
530
546
  <Button
531
547
  key={value}
@@ -600,7 +616,7 @@ export function Filters({ collection, excluded, relationList, assignable, isAssi
600
616
  <SelectContent>
601
617
  <SelectItem value="no_selection">----</SelectItem>
602
618
  {values.map((value: string) => {
603
- if (filter.condition && filter.condition(value) === false) return
619
+ if (filter.filterValues && filter.filterValues(value) === false) return
604
620
  return (
605
621
  <SelectItem key={value} value={value}>
606
622
  {value}
@@ -135,6 +135,9 @@ export const FiltersProvider: React.FC<FiltersProviderProps> = ({
135
135
  }
136
136
  if (filter.type === "select") {
137
137
  const field = getField(fields, filter.field)
138
+ const includeValueInFilters = assignable?.includeValueInFilters?.find(
139
+ (include) => include.field === filter.field && include.values.includes(filter.value),
140
+ )
138
141
  if (field.type === "Boolean") {
139
142
  const fieldCustomization = getFieldCustomization(field, customization)
140
143
  const label = tryFunction(fieldCustomization.admin?.label) || field.name
@@ -145,13 +148,21 @@ export const FiltersProvider: React.FC<FiltersProviderProps> = ({
145
148
  } else if (field.type === "Number") {
146
149
  constraints.push(where(filter.field, "==", Number(filter.value)))
147
150
  } else if (includesAssigned(relationList, relationParent, assignable, isAssigning, filter)) {
151
+ const filterValues = [filter.value]
152
+ if (includeValueInFilters) {
153
+ filterValues.push(includeValueInFilters.includeValue as string | number)
154
+ }
148
155
  constraints.push(
149
156
  or(
150
- where(filter.field, "==", filter.value),
157
+ where(filter.field, "in", filterValues),
151
158
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
152
159
  where(`${relationList!.field}_Array`, "array-contains", relationParent!.id),
153
160
  ) as unknown as QueryConstraint,
154
161
  )
162
+ } else if (isAssigning && includeValueInFilters) {
163
+ constraints.push(
164
+ where(filter.field, "in", [filter.value, includeValueInFilters.includeValue]),
165
+ )
155
166
  } else {
156
167
  constraints.push(where(filter.field, "==", filter.value))
157
168
  }
@@ -312,6 +323,9 @@ export const FiltersProvider: React.FC<FiltersProviderProps> = ({
312
323
  }
313
324
  if (filter.type === "select") {
314
325
  const field = getField(fields, filter.field)
326
+ const includeValueInFilters = assignable?.includeValueInFilters?.find(
327
+ (include) => include.field === filter.field && include.values.includes(filter.value),
328
+ )
315
329
  if (field.type === "Boolean") {
316
330
  const fieldCustomization = getFieldCustomization(field, customization)
317
331
  const label = tryFunction(fieldCustomization.admin?.label) || field.name
@@ -327,6 +341,8 @@ export const FiltersProvider: React.FC<FiltersProviderProps> = ({
327
341
  (record[filter.field] === filter.value ||
328
342
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
329
343
  record[`${relationList!.field}_Array`]?.includes(relationParent!.id))
344
+ } else if (isAssigning && includeValueInFilters) {
345
+ show = show && [filter.value, includeValueInFilters.includeValue].includes(record[filter.field])
330
346
  } else {
331
347
  show = show && record[filter.field] === filter.value
332
348
  }