@stoker-platform/web-app 0.5.104 → 0.5.106

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,19 @@
1
1
  # @stoker-platform/web-app
2
2
 
3
+ ## 0.5.106
4
+
5
+ ### Patch Changes
6
+
7
+ - @stoker-platform/node-client@0.5.59
8
+ - @stoker-platform/utils@0.5.50
9
+ - @stoker-platform/web-client@0.5.59
10
+
11
+ ## 0.5.105
12
+
13
+ ### Patch Changes
14
+
15
+ - fix: improve search all querying
16
+
3
17
  ## 0.5.104
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/web-app",
3
- "version": "0.5.104",
3
+ "version": "0.5.106",
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.50.0",
54
- "@stoker-platform/node-client": "0.5.58",
55
- "@stoker-platform/utils": "0.5.49",
56
- "@stoker-platform/web-client": "0.5.58",
54
+ "@stoker-platform/node-client": "0.5.59",
55
+ "@stoker-platform/utils": "0.5.50",
56
+ "@stoker-platform/web-client": "0.5.59",
57
57
  "@tanstack/react-table": "^8.21.3",
58
58
  "@types/react": "18.3.13",
59
59
  "@types/react-dom": "18.3.1",
@@ -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?.archivedField) {
68
- query.queries[0].constraints.push([softDelete.archivedField, "==", false])
69
- }
70
71
  } else {
71
72
  query.queries[0].constraints = [where("id", "in", objectIDs)]
72
- if (softDelete?.archivedField) {
73
- query.queries[0].constraints.push(where(softDelete.archivedField, "==", 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 () => {