@stoker-platform/web-app 0.5.197 → 0.5.199

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,19 @@
1
1
  # @stoker-platform/web-app
2
2
 
3
+ ## 0.5.199
4
+
5
+ ### Patch Changes
6
+
7
+ - chore: restore Dashboard reminder sorting improvements
8
+
9
+ ## 0.5.198
10
+
11
+ ### Patch Changes
12
+
13
+ - fix: fix Dashboard reminder sorting
14
+ - Updated dependencies
15
+ - @stoker-platform/web-client@0.5.80
16
+
3
17
  ## 0.5.197
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/web-app",
3
- "version": "0.5.197",
3
+ "version": "0.5.199",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
@@ -53,7 +53,7 @@
53
53
  "@sentry/react": "^10.56.0",
54
54
  "@stoker-platform/node-client": "0.5.77",
55
55
  "@stoker-platform/utils": "0.5.68",
56
- "@stoker-platform/web-client": "0.5.79",
56
+ "@stoker-platform/web-client": "0.5.80",
57
57
  "@tanstack/react-table": "^8.21.3",
58
58
  "@types/react": "18.3.13",
59
59
  "@types/react-dom": "18.3.1",
@@ -17,6 +17,7 @@ import { Card, CardContent } from "./components/ui/card"
17
17
  import { useConnection } from "./providers/ConnectionProvider"
18
18
  import { getField, getFieldCustomization, isRelationField, tryFunction } from "@stoker-platform/utils"
19
19
  import { getFormattedFieldValue } from "./utils/getFormattedFieldValue"
20
+ import { getSortingValue } from "./utils/getSortingValue"
20
21
 
21
22
  interface DashboardReminderProps {
22
23
  reminder: Reminder
@@ -209,26 +210,60 @@ export const DashboardReminder = ({ reminder, title, collection }: DashboardRemi
209
210
  </TableRow>
210
211
  ) : (
211
212
  results
212
- .slice(page * pages, (page + 1) * pages)
213
213
  .sort((a, b) => {
214
214
  if (!sorting) return 0
215
215
  const sortingField = getField(fields, sorting.field)
216
- const fieldCustomization = getFieldCustomization(
217
- sortingField,
216
+ const valueA = getSortingValue(
217
+ collectionSchema,
218
218
  customization,
219
+ sorting.field,
220
+ a,
219
221
  )
220
- let sortA = a[sorting.field]
221
- let sortB = b[sorting.field]
222
- if (fieldCustomization.admin?.sort) {
223
- sortA = tryFunction(fieldCustomization.admin?.sort, [a])
224
- sortB = tryFunction(fieldCustomization.admin?.sort, [b])
225
- }
226
- if (sorting.direction === "asc") {
227
- return sortA - sortB
222
+ const valueB = getSortingValue(
223
+ collectionSchema,
224
+ customization,
225
+ sorting.field,
226
+ b,
227
+ )
228
+ let result: number
229
+ if (sortingField.type === "String") {
230
+ const rawA = valueA?.toString().toLowerCase() ?? ""
231
+ const rawB = valueB?.toString().toLowerCase() ?? ""
232
+ result = rawA > rawB ? 1 : rawA < rawB ? -1 : 0
233
+ } else if (isRelationField(sortingField)) {
234
+ const titleField = sortingField.titleField
235
+ let rawA: string
236
+ let rawB: string
237
+ if (titleField) {
238
+ const recordA = Object.values(a[sortingField.name] ?? {})[0] as
239
+ | StokerRecord
240
+ | undefined
241
+ const recordB = Object.values(b[sortingField.name] ?? {})[0] as
242
+ | StokerRecord
243
+ | undefined
244
+ // eslint-disable-next-line security/detect-object-injection
245
+ rawA = recordA?.[titleField]?.toString().toLowerCase() ?? ""
246
+ // eslint-disable-next-line security/detect-object-injection
247
+ rawB = recordB?.[titleField]?.toString().toLowerCase() ?? ""
248
+ } else {
249
+ rawA = (
250
+ Object.keys(a[sortingField.name] ?? {})[0] ?? ""
251
+ ).toLowerCase()
252
+ rawB = (
253
+ Object.keys(b[sortingField.name] ?? {})[0] ?? ""
254
+ ).toLowerCase()
255
+ }
256
+ result = rawA > rawB ? 1 : rawA < rawB ? -1 : 0
257
+ } else if (sortingField.type === "Timestamp") {
258
+ const rawA = Number(valueA?.valueOf() || 0)
259
+ const rawB = Number(valueB?.valueOf() || 0)
260
+ result = rawA > rawB ? 1 : rawA < rawB ? -1 : 0
228
261
  } else {
229
- return sortB - sortA
262
+ result = valueA > valueB ? 1 : valueA < valueB ? -1 : 0
230
263
  }
264
+ return sorting.direction === "asc" ? result : -result
231
265
  })
266
+ .slice(page * pages, (page + 1) * pages)
232
267
  .map((result: StokerRecord) => (
233
268
  <TableRow
234
269
  key={result.id}