@stoker-platform/web-app 0.5.165 → 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 +12 -0
- package/package.json +1 -1
- package/src/List.tsx +111 -67
- package/src/SearchAllResults.tsx +9 -3
- package/src/utils/getSortingValue.ts +6 -1
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/List.tsx
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
getCachedConfigValue,
|
|
20
20
|
getField,
|
|
21
21
|
getFieldCustomization,
|
|
22
|
+
getSystemFieldsSchema,
|
|
22
23
|
isRelationField,
|
|
23
24
|
isSortingEnabled,
|
|
24
25
|
tryFunction,
|
|
@@ -253,6 +254,7 @@ export function List({
|
|
|
253
254
|
hasBreadcrumbs,
|
|
254
255
|
}: ListProps) {
|
|
255
256
|
const { labels, fields, access, recordTitleField, softDelete, fullTextSearch } = collection
|
|
257
|
+
const systemFields = getSystemFieldsSchema()
|
|
256
258
|
const { serverWriteOnly } = access
|
|
257
259
|
const softDeleteField = softDelete?.archivedField
|
|
258
260
|
const softDeleteTimestampField = softDelete?.timestampField
|
|
@@ -639,7 +641,31 @@ export function List({
|
|
|
639
641
|
})
|
|
640
642
|
.filter(Boolean) as ColumnDef<StokerRecord>[]
|
|
641
643
|
|
|
642
|
-
|
|
644
|
+
const allColumns = [selectColumnDef, ...fieldColumns]
|
|
645
|
+
|
|
646
|
+
if (secondarySort && !allColumns.some((column) => column.id === secondarySort.field)) {
|
|
647
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
648
|
+
const hiddenColumn: any = {
|
|
649
|
+
id: secondarySort.field,
|
|
650
|
+
accessorKey: secondarySort.field,
|
|
651
|
+
header: () => null,
|
|
652
|
+
cell: () => null,
|
|
653
|
+
enableHiding: true,
|
|
654
|
+
}
|
|
655
|
+
const field = getField(fields.concat(systemFields), secondarySort.field)
|
|
656
|
+
if (field.type === "String") {
|
|
657
|
+
hiddenColumn.sortingFn = "stringSortingFn"
|
|
658
|
+
} else if (isRelationField(field)) {
|
|
659
|
+
hiddenColumn.sortingFn = "relationSortingFn"
|
|
660
|
+
} else if (field.type === "Timestamp") {
|
|
661
|
+
hiddenColumn.sortingFn = "dateSortingFn"
|
|
662
|
+
} else {
|
|
663
|
+
hiddenColumn.sortingFn = "rawSortingFn"
|
|
664
|
+
}
|
|
665
|
+
allColumns.push(hiddenColumn as ColumnDef<StokerRecord>)
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
return allColumns
|
|
643
669
|
}, [fields, isPreloadCacheEnabled, isServerReadOnly, recordTitleField, connectionStatus])
|
|
644
670
|
|
|
645
671
|
const isSearchRelevanceOrder = !!(search && isPreloadCacheEnabled)
|
|
@@ -1735,29 +1761,39 @@ export function List({
|
|
|
1735
1761
|
{headerGroup.headers.map((header) => {
|
|
1736
1762
|
let className = ""
|
|
1737
1763
|
if (header.id !== "select") {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
)
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1764
|
+
if (
|
|
1765
|
+
!systemFields.some(
|
|
1766
|
+
(systemField) => systemField.name === header.id,
|
|
1767
|
+
)
|
|
1768
|
+
) {
|
|
1769
|
+
const field = getField(fields, header.id)
|
|
1770
|
+
const fieldCustomization = getFieldCustomization(
|
|
1771
|
+
field,
|
|
1772
|
+
customization,
|
|
1773
|
+
)
|
|
1774
|
+
const hidden = tryFunction(fieldCustomization.admin?.hidden)
|
|
1775
|
+
if (hidden) {
|
|
1776
|
+
switch (hidden) {
|
|
1777
|
+
case "sm":
|
|
1778
|
+
className = cn(className, "hidden", "sm:table-cell")
|
|
1779
|
+
break
|
|
1780
|
+
case "md":
|
|
1781
|
+
className = cn(className, "hidden", "md:table-cell")
|
|
1782
|
+
break
|
|
1783
|
+
case "lg":
|
|
1784
|
+
className = cn(className, "hidden", "lg:table-cell")
|
|
1785
|
+
break
|
|
1786
|
+
case "xl":
|
|
1787
|
+
className = cn(className, "hidden", "xl:table-cell")
|
|
1788
|
+
break
|
|
1789
|
+
case "2xl":
|
|
1790
|
+
className = cn(
|
|
1791
|
+
className,
|
|
1792
|
+
"hidden",
|
|
1793
|
+
"2xl:table-cell",
|
|
1794
|
+
)
|
|
1795
|
+
break
|
|
1796
|
+
}
|
|
1761
1797
|
}
|
|
1762
1798
|
}
|
|
1763
1799
|
} else {
|
|
@@ -1805,50 +1841,58 @@ export function List({
|
|
|
1805
1841
|
{row.getVisibleCells().map((cell: Cell<unknown, unknown>) => {
|
|
1806
1842
|
let className = "p-0"
|
|
1807
1843
|
const id = cell.column.columnDef.id
|
|
1844
|
+
const field = getField(fields.concat(systemFields), id)
|
|
1808
1845
|
if (id !== "select") {
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
)
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1846
|
+
if (
|
|
1847
|
+
!systemFields.some(
|
|
1848
|
+
(systemField) => systemField.name === id,
|
|
1849
|
+
)
|
|
1850
|
+
) {
|
|
1851
|
+
const fieldCustomization = getFieldCustomization(
|
|
1852
|
+
field,
|
|
1853
|
+
customization,
|
|
1854
|
+
)
|
|
1855
|
+
const hidden = tryFunction(
|
|
1856
|
+
fieldCustomization.admin?.hidden,
|
|
1857
|
+
)
|
|
1858
|
+
if (hidden) {
|
|
1859
|
+
switch (hidden) {
|
|
1860
|
+
case "sm":
|
|
1861
|
+
className = cn(
|
|
1862
|
+
className,
|
|
1863
|
+
"hidden",
|
|
1864
|
+
"sm:table-cell",
|
|
1865
|
+
)
|
|
1866
|
+
break
|
|
1867
|
+
case "md":
|
|
1868
|
+
className = cn(
|
|
1869
|
+
className,
|
|
1870
|
+
"hidden",
|
|
1871
|
+
"md:table-cell",
|
|
1872
|
+
)
|
|
1873
|
+
break
|
|
1874
|
+
case "lg":
|
|
1875
|
+
className = cn(
|
|
1876
|
+
className,
|
|
1877
|
+
"hidden",
|
|
1878
|
+
"lg:table-cell",
|
|
1879
|
+
)
|
|
1880
|
+
break
|
|
1881
|
+
case "xl":
|
|
1882
|
+
className = cn(
|
|
1883
|
+
className,
|
|
1884
|
+
"hidden",
|
|
1885
|
+
"xl:table-cell",
|
|
1886
|
+
)
|
|
1887
|
+
break
|
|
1888
|
+
case "2xl":
|
|
1889
|
+
className = cn(
|
|
1890
|
+
className,
|
|
1891
|
+
"hidden",
|
|
1892
|
+
"2xl:table-cell",
|
|
1893
|
+
)
|
|
1894
|
+
break
|
|
1895
|
+
}
|
|
1852
1896
|
}
|
|
1853
1897
|
}
|
|
1854
1898
|
if (
|
package/src/SearchAllResults.tsx
CHANGED
|
@@ -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(
|
|
96
|
-
|
|
97
|
-
|
|
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 {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getField, getFieldCustomization, tryFunction } from "@stoker-platform/utils"
|
|
1
|
+
import { getField, getFieldCustomization, getSystemFieldsSchema, tryFunction } from "@stoker-platform/utils"
|
|
2
2
|
import { CollectionCustomization, CollectionSchema, StokerRecord } from "@stoker-platform/types"
|
|
3
3
|
|
|
4
4
|
export const getSortingValue = (
|
|
@@ -10,6 +10,11 @@ export const getSortingValue = (
|
|
|
10
10
|
parentRecord?: StokerRecord,
|
|
11
11
|
) => {
|
|
12
12
|
const { fields } = collection
|
|
13
|
+
const systemFields = getSystemFieldsSchema()
|
|
14
|
+
if (systemFields.some((systemField) => systemField.name === field)) {
|
|
15
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
16
|
+
return record[field]
|
|
17
|
+
}
|
|
13
18
|
const fieldSchema = getField(fields, field)
|
|
14
19
|
const fieldCustomization = getFieldCustomization(fieldSchema, customization)
|
|
15
20
|
// eslint-disable-next-line security/detect-object-injection
|