@stoker-platform/web-app 0.5.198 → 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,11 @@
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
+
3
9
  ## 0.5.198
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.198",
3
+ "version": "0.5.199",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
@@ -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
@@ -212,21 +213,55 @@ export const DashboardReminder = ({ reminder, title, collection }: DashboardRemi
212
213
  .sort((a, b) => {
213
214
  if (!sorting) return 0
214
215
  const sortingField = getField(fields, sorting.field)
215
- const fieldCustomization = getFieldCustomization(
216
- sortingField,
216
+ const valueA = getSortingValue(
217
+ collectionSchema,
217
218
  customization,
219
+ sorting.field,
220
+ a,
218
221
  )
219
- let sortA = a[sorting.field]
220
- let sortB = b[sorting.field]
221
- if (fieldCustomization.admin?.sort) {
222
- sortA = tryFunction(fieldCustomization.admin?.sort, [a])
223
- sortB = tryFunction(fieldCustomization.admin?.sort, [b])
224
- }
225
- if (sorting.direction === "asc") {
226
- 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
227
261
  } else {
228
- return sortB - sortA
262
+ result = valueA > valueB ? 1 : valueA < valueB ? -1 : 0
229
263
  }
264
+ return sorting.direction === "asc" ? result : -result
230
265
  })
231
266
  .slice(page * pages, (page + 1) * pages)
232
267
  .map((result: StokerRecord) => (