@stoker-platform/web-app 0.5.159 → 0.5.160
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 +6 -0
- package/package.json +1 -1
- package/src/Filters.tsx +18 -2
- package/src/Form.tsx +29 -19
- package/src/PermissionPicker.tsx +15 -2
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/Filters.tsx
CHANGED
|
@@ -274,10 +274,12 @@ export function Filters({ collection, excluded, relationList }: FiltersProps) {
|
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
+
let searchObjectIDs: string[] | undefined
|
|
277
278
|
if (fullTextSearch && !isCollectionPreloadCacheEnabled && query) {
|
|
278
279
|
const disjunctions = getFilterDisjunctions(collectionSchema)
|
|
279
280
|
const hitsPerPage = disjunctions === 0 ? 10 : Math.min(10, Math.max(1, Math.floor(30 / disjunctions)))
|
|
280
281
|
const objectIDs = await performFullTextSearch(collectionSchema, query, hitsPerPage, constraints)
|
|
282
|
+
searchObjectIDs = objectIDs
|
|
281
283
|
if (objectIDs.length > 0) {
|
|
282
284
|
if (isCollectionServerReadOnly) {
|
|
283
285
|
newConstraints.push(["id", "in", objectIDs] as QueryConstraint & [string, string, unknown])
|
|
@@ -314,10 +316,24 @@ export function Filters({ collection, excluded, relationList }: FiltersProps) {
|
|
|
314
316
|
const numberOfResults = isCollectionPreloadCacheEnabled && isMobile ? 20 : 10
|
|
315
317
|
if (isCollectionPreloadCacheEnabled && query) {
|
|
316
318
|
const searchResults = localFullTextSearch(collectionSchema, query, data.records)
|
|
317
|
-
const
|
|
319
|
+
const recordsById = new Map(data.records.map((doc) => [doc.id, doc]))
|
|
320
|
+
const ordered = searchResults
|
|
321
|
+
.map((result) => recordsById.get(result.id))
|
|
322
|
+
.filter((doc): doc is StokerRecord => !!doc)
|
|
323
|
+
.slice(0, numberOfResults)
|
|
318
324
|
setData((prev) => ({
|
|
319
325
|
...prev,
|
|
320
|
-
[field]:
|
|
326
|
+
[field]: ordered,
|
|
327
|
+
}))
|
|
328
|
+
} else if (query && searchObjectIDs) {
|
|
329
|
+
const recordsById = new Map(data.records.map((doc) => [doc.id, doc]))
|
|
330
|
+
const ordered = searchObjectIDs
|
|
331
|
+
.map((id) => recordsById.get(id))
|
|
332
|
+
.filter((doc): doc is StokerRecord => !!doc)
|
|
333
|
+
.slice(0, numberOfResults)
|
|
334
|
+
setData((prev) => ({
|
|
335
|
+
...prev,
|
|
336
|
+
[field]: ordered,
|
|
321
337
|
}))
|
|
322
338
|
} else {
|
|
323
339
|
setData((prev) => ({
|
package/src/Form.tsx
CHANGED
|
@@ -1974,10 +1974,12 @@ function RelationField({
|
|
|
1974
1974
|
)
|
|
1975
1975
|
}
|
|
1976
1976
|
|
|
1977
|
+
let searchObjectIDs: string[] | undefined
|
|
1977
1978
|
if (fullTextSearch && !isCollectionPreloadCacheEnabled && query) {
|
|
1978
1979
|
const disjunctions = getFilterDisjunctions(relationCollection)
|
|
1979
1980
|
const hitsPerPage = disjunctions === 0 ? 10 : Math.min(10, Math.max(1, Math.floor(30 / disjunctions)))
|
|
1980
1981
|
const objectIDs = await performFullTextSearch(relationCollection, query, hitsPerPage, constraints)
|
|
1982
|
+
searchObjectIDs = objectIDs
|
|
1981
1983
|
if (objectIDs.length > 0) {
|
|
1982
1984
|
if (isCollectionServerReadOnly) {
|
|
1983
1985
|
newConstraints.push(["id", "in", objectIDs] as QueryConstraint &
|
|
@@ -1997,7 +1999,10 @@ function RelationField({
|
|
|
1997
1999
|
}
|
|
1998
2000
|
|
|
1999
2001
|
const orderData = async (data: StokerRecord[]) => {
|
|
2000
|
-
const defaultSort = await tryPromise(customization.admin?.defaultSort)
|
|
2002
|
+
const defaultSort = (await tryPromise(customization.admin?.defaultSort)) || {
|
|
2003
|
+
field: recordTitleField,
|
|
2004
|
+
direction: "asc",
|
|
2005
|
+
}
|
|
2001
2006
|
if (defaultSort) {
|
|
2002
2007
|
return sortList(
|
|
2003
2008
|
relationCollection,
|
|
@@ -2027,27 +2032,32 @@ function RelationField({
|
|
|
2027
2032
|
if (!fieldCustomization.admin?.filterResults) return true
|
|
2028
2033
|
return !!fieldCustomization.admin?.filterResults?.(result, collection, record)
|
|
2029
2034
|
})
|
|
2030
|
-
const
|
|
2031
|
-
|
|
2032
|
-
(
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
)
|
|
2035
|
+
const recordsById = new Map(data.records.map((doc) => [doc.id, doc]))
|
|
2036
|
+
const ordered = searchResults
|
|
2037
|
+
.map((result) => recordsById.get(result.id))
|
|
2038
|
+
.filter((doc): doc is StokerRecord => !!doc)
|
|
2039
|
+
.slice(0, numberOfResults)
|
|
2040
|
+
setData(ordered)
|
|
2041
|
+
} else if (query && searchObjectIDs) {
|
|
2042
|
+
const recordsById = new Map(data.records.map((doc) => [doc.id, doc]))
|
|
2043
|
+
const ordered = searchObjectIDs
|
|
2044
|
+
.map((id) => recordsById.get(id))
|
|
2045
|
+
.filter((doc): doc is StokerRecord => !!doc)
|
|
2046
|
+
.slice(0, numberOfResults)
|
|
2047
|
+
setData(ordered)
|
|
2036
2048
|
} else {
|
|
2037
2049
|
orderData(
|
|
2038
|
-
data.records
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
})
|
|
2048
|
-
.slice(0, numberOfResults),
|
|
2050
|
+
data.records.filter((doc) => {
|
|
2051
|
+
if (!isCollectionPreloadCacheEnabled) return true
|
|
2052
|
+
if (!fieldCustomization.admin?.filterResults) return true
|
|
2053
|
+
return !!fieldCustomization.admin?.filterResults?.(
|
|
2054
|
+
doc as unknown as SearchResult,
|
|
2055
|
+
collection,
|
|
2056
|
+
record,
|
|
2057
|
+
)
|
|
2058
|
+
}),
|
|
2049
2059
|
).then((data) => {
|
|
2050
|
-
setData(data)
|
|
2060
|
+
setData(data.slice(0, numberOfResults))
|
|
2051
2061
|
})
|
|
2052
2062
|
}
|
|
2053
2063
|
setIsLoadingImmediate(false)
|
package/src/PermissionPicker.tsx
CHANGED
|
@@ -108,10 +108,12 @@ export const PermissionPicker = ({
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
let searchObjectIDs: string[] | undefined
|
|
111
112
|
if (fullTextSearch && !isCollectionPreloadCacheEnabled && query) {
|
|
112
113
|
const disjunctions = getFilterDisjunctions(collection)
|
|
113
114
|
const hitsPerPage = disjunctions === 0 ? 10 : Math.min(10, Math.max(1, Math.floor(30 / disjunctions)))
|
|
114
115
|
const objectIDs = await performFullTextSearch(collection, query, hitsPerPage, constraints)
|
|
116
|
+
searchObjectIDs = objectIDs
|
|
115
117
|
if (objectIDs.length > 0) {
|
|
116
118
|
if (isCollectionServerReadOnly) {
|
|
117
119
|
newConstraints.push(["id", "in", objectIDs] as QueryConstraint &
|
|
@@ -142,8 +144,19 @@ export const PermissionPicker = ({
|
|
|
142
144
|
const numberOfResults = isCollectionPreloadCacheEnabled && isMobile ? 20 : 10
|
|
143
145
|
if (isCollectionPreloadCacheEnabled && query) {
|
|
144
146
|
const searchResults = localFullTextSearch(collection, query, data.records)
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
+
const recordsById = new Map(data.records.map((doc) => [doc.id, doc]))
|
|
148
|
+
const ordered = searchResults
|
|
149
|
+
.map((result) => recordsById.get(result.id))
|
|
150
|
+
.filter((doc): doc is StokerRecord => !!doc)
|
|
151
|
+
.slice(0, numberOfResults)
|
|
152
|
+
setData(ordered)
|
|
153
|
+
} else if (query && searchObjectIDs) {
|
|
154
|
+
const recordsById = new Map(data.records.map((doc) => [doc.id, doc]))
|
|
155
|
+
const ordered = searchObjectIDs
|
|
156
|
+
.map((id) => recordsById.get(id))
|
|
157
|
+
.filter((doc): doc is StokerRecord => !!doc)
|
|
158
|
+
.slice(0, numberOfResults)
|
|
159
|
+
setData(ordered)
|
|
147
160
|
} else {
|
|
148
161
|
setData(data.records.slice(0, numberOfResults))
|
|
149
162
|
}
|