@stoker-platform/web-app 0.5.161 → 0.5.163
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 +15 -0
- package/package.json +4 -4
- package/src/Form.tsx +1 -6
- package/src/List.tsx +14 -4
- package/src/utils/localFullTextSearch.ts +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @stoker-platform/web-app
|
|
2
2
|
|
|
3
|
+
## 0.5.163
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix: improve list search results sorting
|
|
8
|
+
|
|
9
|
+
## 0.5.162
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- fix: improve local full text search filtering
|
|
14
|
+
- @stoker-platform/node-client@0.5.65
|
|
15
|
+
- @stoker-platform/utils@0.5.56
|
|
16
|
+
- @stoker-platform/web-client@0.5.66
|
|
17
|
+
|
|
3
18
|
## 0.5.161
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stoker-platform/web-app",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.163",
|
|
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.
|
|
55
|
-
"@stoker-platform/utils": "0.5.
|
|
56
|
-
"@stoker-platform/web-client": "0.5.
|
|
54
|
+
"@stoker-platform/node-client": "0.5.65",
|
|
55
|
+
"@stoker-platform/utils": "0.5.56",
|
|
56
|
+
"@stoker-platform/web-client": "0.5.66",
|
|
57
57
|
"@tanstack/react-table": "^8.21.3",
|
|
58
58
|
"@types/react": "18.3.13",
|
|
59
59
|
"@types/react-dom": "18.3.1",
|
package/src/Form.tsx
CHANGED
|
@@ -171,7 +171,6 @@ import {
|
|
|
171
171
|
import { FiltersProvider } from "./providers/FiltersProvider"
|
|
172
172
|
import Collection from "./Collection"
|
|
173
173
|
import { Separator } from "./components/ui/separator"
|
|
174
|
-
import { SearchResult } from "minisearch"
|
|
175
174
|
import { sortList } from "./utils/sortList"
|
|
176
175
|
import MonthPicker from "./components/ui/month-picker"
|
|
177
176
|
|
|
@@ -2050,11 +2049,7 @@ function RelationField({
|
|
|
2050
2049
|
data.records.filter((doc) => {
|
|
2051
2050
|
if (!isCollectionPreloadCacheEnabled) return true
|
|
2052
2051
|
if (!fieldCustomization.admin?.filterResults) return true
|
|
2053
|
-
return !!fieldCustomization.admin?.filterResults?.(
|
|
2054
|
-
doc as unknown as SearchResult,
|
|
2055
|
-
collection,
|
|
2056
|
-
record,
|
|
2057
|
-
)
|
|
2052
|
+
return !!fieldCustomization.admin?.filterResults?.(doc, collection, record)
|
|
2058
2053
|
}),
|
|
2059
2054
|
).then((data) => {
|
|
2060
2055
|
setData(data.slice(0, numberOfResults))
|
package/src/List.tsx
CHANGED
|
@@ -635,10 +635,19 @@ export function List({
|
|
|
635
635
|
return [selectColumnDef, ...fieldColumns]
|
|
636
636
|
}, [fields, isPreloadCacheEnabled, isServerReadOnly, recordTitleField, connectionStatus])
|
|
637
637
|
|
|
638
|
+
const isSearchRelevanceOrder = !!(search && isPreloadCacheEnabled)
|
|
639
|
+
|
|
638
640
|
const searchList = useMemo(() => {
|
|
639
641
|
if (search && (isPreloadCacheEnabled || isServerReadOnly)) {
|
|
640
|
-
const searchResults = localFullTextSearch(collection, search, list || [])
|
|
641
|
-
|
|
642
|
+
const searchResults = localFullTextSearch(collection, search, list || [])
|
|
643
|
+
if (isPreloadCacheEnabled) {
|
|
644
|
+
const recordsById = new Map((list || []).map((record) => [record.id, record]))
|
|
645
|
+
return searchResults
|
|
646
|
+
.map((result) => recordsById.get(result.id))
|
|
647
|
+
.filter((record): record is StokerRecord => record !== undefined)
|
|
648
|
+
}
|
|
649
|
+
const searchResultIds = searchResults.map((result) => result.id)
|
|
650
|
+
return list?.filter((record) => searchResultIds.includes(record.id)) || []
|
|
642
651
|
}
|
|
643
652
|
return list || []
|
|
644
653
|
}, [isPreloadCacheEnabled, isServerReadOnly, list, search])
|
|
@@ -658,6 +667,7 @@ export function List({
|
|
|
658
667
|
getCoreRowModel: getCoreRowModel(),
|
|
659
668
|
getPaginationRowModel: getPaginationRowModel(),
|
|
660
669
|
onSortingChange: (sortingUpdater) => {
|
|
670
|
+
if (isSearchRelevanceOrder) return
|
|
661
671
|
if (typeof sortingUpdater === "function") {
|
|
662
672
|
const newSorting = sortingUpdater(sorting)
|
|
663
673
|
const field = getField(fields, newSorting[0].id)
|
|
@@ -697,9 +707,9 @@ export function List({
|
|
|
697
707
|
onRowSelectionChange: setRowSelection,
|
|
698
708
|
pageCount,
|
|
699
709
|
autoResetPageIndex: false,
|
|
700
|
-
enableSorting:
|
|
710
|
+
enableSorting: !isSearchRelevanceOrder,
|
|
701
711
|
state: {
|
|
702
|
-
sorting,
|
|
712
|
+
sorting: isSearchRelevanceOrder ? [] : sorting,
|
|
703
713
|
columnFilters,
|
|
704
714
|
rowSelection,
|
|
705
715
|
pagination: {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CollectionSchema, StokerRecord } from "@stoker-platform/types"
|
|
2
|
-
import MiniSearch, { Options
|
|
2
|
+
import MiniSearch, { Options } from "minisearch"
|
|
3
3
|
|
|
4
4
|
export const localFullTextSearch = (
|
|
5
5
|
collection: CollectionSchema,
|
|
6
6
|
query: string,
|
|
7
7
|
list: StokerRecord[],
|
|
8
|
-
filter?: (result:
|
|
8
|
+
filter?: (result: StokerRecord) => boolean,
|
|
9
9
|
tokenize?: boolean,
|
|
10
10
|
) => {
|
|
11
11
|
const { recordTitleField, fullTextSearch } = collection
|
|
@@ -17,14 +17,15 @@ export const localFullTextSearch = (
|
|
|
17
17
|
fuzzy: 0.2,
|
|
18
18
|
prefix: true,
|
|
19
19
|
}),
|
|
20
|
-
filter,
|
|
21
20
|
},
|
|
22
21
|
}
|
|
22
|
+
if (filter) {
|
|
23
|
+
list = list.filter((record) => filter(record))
|
|
24
|
+
}
|
|
23
25
|
if (tokenize) {
|
|
24
26
|
miniSearchConfig.tokenize = (string) => [string]
|
|
25
27
|
}
|
|
26
28
|
const miniSearch = new MiniSearch(miniSearchConfig)
|
|
27
|
-
// eslint-disable-next-line security/detect-object-injection
|
|
28
29
|
miniSearch.addAll(list)
|
|
29
30
|
const results = miniSearch.search(query)
|
|
30
31
|
return results
|