@stoker-platform/web-app 0.5.165 → 0.5.166

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.166
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: improve secondary sort feature
8
+
3
9
  ## 0.5.165
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.165",
3
+ "version": "0.5.166",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
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
- return [selectColumnDef, ...fieldColumns]
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
- const field = getField(fields, header.id)
1739
- const fieldCustomization = getFieldCustomization(
1740
- field,
1741
- customization,
1742
- )
1743
- const hidden = tryFunction(fieldCustomization.admin?.hidden)
1744
- if (hidden) {
1745
- switch (hidden) {
1746
- case "sm":
1747
- className = cn(className, "hidden", "sm:table-cell")
1748
- break
1749
- case "md":
1750
- className = cn(className, "hidden", "md:table-cell")
1751
- break
1752
- case "lg":
1753
- className = cn(className, "hidden", "lg:table-cell")
1754
- break
1755
- case "xl":
1756
- className = cn(className, "hidden", "xl:table-cell")
1757
- break
1758
- case "2xl":
1759
- className = cn(className, "hidden", "2xl:table-cell")
1760
- break
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
- const field = getField(fields, id)
1810
- const fieldCustomization = getFieldCustomization(
1811
- field,
1812
- customization,
1813
- )
1814
- const hidden = tryFunction(fieldCustomization.admin?.hidden)
1815
- if (hidden) {
1816
- switch (hidden) {
1817
- case "sm":
1818
- className = cn(
1819
- className,
1820
- "hidden",
1821
- "sm:table-cell",
1822
- )
1823
- break
1824
- case "md":
1825
- className = cn(
1826
- className,
1827
- "hidden",
1828
- "md:table-cell",
1829
- )
1830
- break
1831
- case "lg":
1832
- className = cn(
1833
- className,
1834
- "hidden",
1835
- "lg:table-cell",
1836
- )
1837
- break
1838
- case "xl":
1839
- className = cn(
1840
- className,
1841
- "hidden",
1842
- "xl:table-cell",
1843
- )
1844
- break
1845
- case "2xl":
1846
- className = cn(
1847
- className,
1848
- "hidden",
1849
- "2xl:table-cell",
1850
- )
1851
- break
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 (
@@ -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