@stoker-platform/web-app 0.5.103 → 0.5.105

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,17 @@
1
1
  # @stoker-platform/web-app
2
2
 
3
+ ## 0.5.105
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: improve search all querying
8
+
9
+ ## 0.5.104
10
+
11
+ ### Patch Changes
12
+
13
+ - fix: use soft delete archivedField instead of literal field name
14
+
3
15
  ## 0.5.103
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/web-app",
3
- "version": "0.5.103",
3
+ "version": "0.5.105",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
@@ -63,8 +63,8 @@ export const DashboardChart = ({ chart, title, collection }: DashboardChartProps
63
63
 
64
64
  const constraints = useMemo(() => {
65
65
  const existingConstraints = [...(chart.constraints || [])]
66
- if (softDelete) {
67
- existingConstraints.push(["Archived", "==", false])
66
+ if (softDelete?.archivedField) {
67
+ existingConstraints.push([softDelete.archivedField, "==", false])
68
68
  }
69
69
  return existingConstraints
70
70
  }, [])
@@ -53,8 +53,8 @@ export const DashboardMetric = ({ metric, title, collection }: DashboardMetricPr
53
53
 
54
54
  const constraints = useMemo(() => {
55
55
  const existingConstraints = [...(metric.constraints || [])]
56
- if (softDelete) {
57
- existingConstraints.push(["Archived", "==", false])
56
+ if (softDelete?.archivedField) {
57
+ existingConstraints.push([softDelete.archivedField, "==", false])
58
58
  }
59
59
  return existingConstraints
60
60
  }, [])
@@ -68,8 +68,8 @@ export const DashboardReminder = ({ reminder, title, collection }: DashboardRemi
68
68
 
69
69
  const constraints = useMemo(() => {
70
70
  const existingConstraints = [...(reminder.constraints || [])]
71
- if (softDelete) {
72
- existingConstraints.push(["Archived", "==", false])
71
+ if (softDelete?.archivedField) {
72
+ existingConstraints.push([softDelete.archivedField, "==", false])
73
73
  }
74
74
  return existingConstraints
75
75
  }, [])
package/src/Filters.tsx CHANGED
@@ -254,12 +254,15 @@ export function Filters({ collection, excluded, relationList }: FiltersProps) {
254
254
  newConstraints = constraints.map((constraint) => where(constraint[0], constraint[1], constraint[2]))
255
255
  }
256
256
  if (isCollectionServerReadOnly) {
257
- if (softDelete) {
258
- newConstraints.push(["Archived", "==", false] as QueryConstraint & [string, string, unknown])
257
+ if (softDelete?.archivedField) {
258
+ newConstraints.push([softDelete.archivedField, "==", false] as QueryConstraint &
259
+ [string, string, unknown])
259
260
  }
260
261
  } else {
261
- if (softDelete) {
262
- newConstraints.push(where("Archived", "==", false) as QueryConstraint & [string, string, unknown])
262
+ if (softDelete?.archivedField) {
263
+ newConstraints.push(
264
+ where(softDelete.archivedField, "==", false) as QueryConstraint & [string, string, unknown],
265
+ )
263
266
  }
264
267
  }
265
268
 
package/src/Form.tsx CHANGED
@@ -1942,13 +1942,15 @@ function RelationField({
1942
1942
  newConstraints = constraints.map((constraint) => where(constraint[0], constraint[1], constraint[2]))
1943
1943
  }
1944
1944
  if (isCollectionServerReadOnly) {
1945
- if (softDelete) {
1946
- newConstraints.push(["Archived", "==", false] as QueryConstraint & [string, WhereFilterOp, unknown])
1945
+ if (softDelete?.archivedField) {
1946
+ newConstraints.push([softDelete.archivedField, "==", false] as QueryConstraint &
1947
+ [string, WhereFilterOp, unknown])
1947
1948
  }
1948
1949
  } else {
1949
- if (softDelete) {
1950
+ if (softDelete?.archivedField) {
1950
1951
  newConstraints.push(
1951
- where("Archived", "==", false) as QueryConstraint & [string, WhereFilterOp, unknown],
1952
+ where(softDelete.archivedField, "==", false) as QueryConstraint &
1953
+ [string, WhereFilterOp, unknown],
1952
1954
  )
1953
1955
  }
1954
1956
  }
@@ -90,13 +90,15 @@ export const PermissionPicker = ({
90
90
  newConstraints = constraints.map((constraint) => where(constraint[0], constraint[1], constraint[2]))
91
91
  }
92
92
  if (isCollectionServerReadOnly) {
93
- if (softDelete) {
94
- newConstraints.push(["Archived", "==", false] as QueryConstraint & [string, WhereFilterOp, unknown])
93
+ if (softDelete?.archivedField) {
94
+ newConstraints.push([softDelete.archivedField, "==", false] as QueryConstraint &
95
+ [string, WhereFilterOp, unknown])
95
96
  }
96
97
  } else {
97
- if (softDelete) {
98
+ if (softDelete?.archivedField) {
98
99
  newConstraints.push(
99
- where("Archived", "==", false) as QueryConstraint & [string, WhereFilterOp, unknown],
100
+ where(softDelete.archivedField, "==", false) as QueryConstraint &
101
+ [string, WhereFilterOp, unknown],
100
102
  )
101
103
  }
102
104
  }
@@ -1,6 +1,6 @@
1
1
  import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
2
2
  import { CollectionSchema, StokerRecord } from "@stoker-platform/types"
3
- import { createElement, Suspense, useCallback, useEffect, useRef, useState } from "react"
3
+ import { createElement, Suspense, useCallback, useEffect, useState } from "react"
4
4
  import { LoadingSpinner } from "./components/ui/loading-spinner"
5
5
  import { preloadCacheEnabled } from "./utils/preloadCacheEnabled"
6
6
  import { serverReadOnly } from "./utils/serverReadOnly"
@@ -37,10 +37,11 @@ export function SearchAllResults({ collection, search }: { collection: Collectio
37
37
  const [loading, setLoading] = useState(true)
38
38
  const [isCacheLoading, setIsCacheLoading] = useState(false)
39
39
  const [unsubscribe, setUnsubscribe] = useState<Unsubscribe[] | undefined>(undefined)
40
- const searchResults = useRef<string[] | undefined>(undefined)
41
40
  const [title, setTitle] = useState<string | undefined>(undefined)
42
41
  const [icon, setIcon] = useState<string | undefined>(undefined)
43
42
 
43
+ const MAX_RESULTS = 5
44
+
44
45
  const getData = useCallback(async () => {
45
46
  if (!isPreloadCacheEnabled) {
46
47
  setLoading(true)
@@ -59,19 +60,16 @@ export function SearchAllResults({ collection, search }: { collection: Collectio
59
60
  if (fullTextSearch && !isPreloadCacheEnabled) {
60
61
  const disjunctions = getFilterDisjunctions(collection)
61
62
  const hitsPerPage = disjunctions === 0 ? 5 : Math.min(5, Math.max(1, Math.floor(30 / disjunctions)))
62
- const objectIDs = await performFullTextSearch(collection, search, hitsPerPage)
63
- searchResults.current = objectIDs
63
+ const algoliaConstraints: [string, "==" | "in", unknown][] = []
64
+ if (softDelete?.archivedField) {
65
+ algoliaConstraints.push([softDelete.archivedField, "==", false])
66
+ }
67
+ const objectIDs = await performFullTextSearch(collection, search, hitsPerPage, algoliaConstraints)
64
68
  if (objectIDs.length > 0) {
65
69
  if (isServerReadOnly) {
66
70
  query.queries[0].constraints = [["id", "in", objectIDs]]
67
- if (softDelete) {
68
- query.queries[0].constraints.push(["Archived", "==", false])
69
- }
70
71
  } else {
71
72
  query.queries[0].constraints = [where("id", "in", objectIDs)]
72
- if (softDelete) {
73
- query.queries[0].constraints.push(where("Archived", "==", false))
74
- }
75
73
  }
76
74
  } else if (search) {
77
75
  setResults([])
@@ -91,11 +89,14 @@ export function SearchAllResults({ collection, search }: { collection: Collectio
91
89
 
92
90
  const load = () => {
93
91
  if (isPreloadCacheEnabled) {
94
- const searchResults = localFullTextSearch(collection, search, loadedDocs)
95
- const searchRecords = loadedDocs.filter((doc) =>
96
- searchResults.map((result) => result.id).includes(doc.id),
92
+ const activeRecords = softDelete?.archivedField
93
+ ? loadedDocs.filter((doc) => !doc[softDelete.archivedField])
94
+ : loadedDocs
95
+ const miniSearchResults = localFullTextSearch(collection, search, activeRecords)
96
+ const searchRecords = activeRecords.filter((doc) =>
97
+ miniSearchResults.map((result) => result.id).includes(doc.id),
97
98
  )
98
- setResults(searchRecords)
99
+ setResults(searchRecords.slice(0, MAX_RESULTS))
99
100
  setLoading(false)
100
101
  } else {
101
102
  setResults(loadedDocs)
@@ -127,9 +128,7 @@ export function SearchAllResults({ collection, search }: { collection: Collectio
127
128
  },
128
129
  {
129
130
  constraints: currentQuery.constraints as QueryConstraint[],
130
- pagination: {
131
- number: 5,
132
- },
131
+ pagination: isPreloadCacheEnabled ? undefined : { number: MAX_RESULTS },
133
132
  },
134
133
  )
135
134
  const { unsubscribe: newUnsubscribe } = result
@@ -149,7 +148,7 @@ export function SearchAllResults({ collection, search }: { collection: Collectio
149
148
  const data = await getSome([labels.collection], {
150
149
  constraints: query.queries[0].constraints as [string, WhereFilterOp, unknown][],
151
150
  pagination: {
152
- number: 5,
151
+ number: MAX_RESULTS,
153
152
  },
154
153
  })
155
154
  setResults(data.records)
@@ -163,7 +162,7 @@ export function SearchAllResults({ collection, search }: { collection: Collectio
163
162
  subscribe()
164
163
  }
165
164
  })
166
- }, [isPreloadCacheEnabled, isServerReadOnly, unsubscribe, location, search])
165
+ }, [isPreloadCacheEnabled, isServerReadOnly, unsubscribe, search])
167
166
 
168
167
  useEffect(() => {
169
168
  const initialize = async () => {