@stoker-platform/web-app 0.5.166 → 0.5.167

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,11 @@
1
1
  # @stoker-platform/web-app
2
2
 
3
+ ## 0.5.167
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: improve search all results sorting
8
+
3
9
  ## 0.5.166
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/web-app",
3
- "version": "0.5.166",
3
+ "version": "0.5.167",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
@@ -21,6 +21,7 @@ import { useGoToRecord } from "./utils/goToRecord"
21
21
  import { performFullTextSearch } from "./utils/performFullTextSearch"
22
22
  import { localFullTextSearch } from "./utils/localFullTextSearch"
23
23
  import { useConnection } from "./providers/ConnectionProvider"
24
+ import { SearchResult } from "minisearch"
24
25
 
25
26
  export function SearchAllResults({ collection, search }: { collection: CollectionSchema; search: string }) {
26
27
  const { labels, fullTextSearch, recordTitleField, softDelete } = collection
@@ -92,10 +93,15 @@ export function SearchAllResults({ collection, search }: { collection: Collectio
92
93
  const activeRecords = softDelete?.archivedField
93
94
  ? loadedDocs.filter((doc) => !doc[softDelete.archivedField])
94
95
  : loadedDocs
95
- const miniSearchResults = localFullTextSearch(collection, search, activeRecords)
96
- const searchRecords = activeRecords.filter((doc) =>
97
- miniSearchResults.map((result) => result.id).includes(doc.id),
96
+ const miniSearchResults: SearchResult[] = localFullTextSearch(
97
+ collection,
98
+ search,
99
+ activeRecords,
98
100
  )
101
+ const recordsById = new Map(activeRecords.map((record) => [record.id, record]))
102
+ const searchRecords = miniSearchResults
103
+ .map((result) => recordsById.get(result.id))
104
+ .filter((record): record is StokerRecord => record !== undefined)
99
105
  setResults(searchRecords.slice(0, MAX_RESULTS))
100
106
  setLoading(false)
101
107
  } else {