@stoker-platform/web-app 0.5.192 → 0.5.193

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.193
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: improve Dashboard reminder sorting
8
+
3
9
  ## 0.5.192
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.192",
3
+ "version": "0.5.193",
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
@@ -198,26 +199,60 @@ export const DashboardReminder = ({ reminder, title, collection }: DashboardRemi
198
199
  </TableRow>
199
200
  ) : (
200
201
  results
201
- .slice(page * pages, (page + 1) * pages)
202
202
  .sort((a, b) => {
203
203
  if (!sorting) return 0
204
204
  const sortingField = getField(fields, sorting.field)
205
- const fieldCustomization = getFieldCustomization(
206
- sortingField,
205
+ const valueA = getSortingValue(
206
+ collectionSchema,
207
207
  customization,
208
+ sorting.field,
209
+ a,
208
210
  )
209
- let sortA = a[sorting.field]
210
- let sortB = b[sorting.field]
211
- if (fieldCustomization.admin?.sort) {
212
- sortA = tryFunction(fieldCustomization.admin?.sort, [a])
213
- sortB = tryFunction(fieldCustomization.admin?.sort, [b])
214
- }
215
- if (sorting.direction === "asc") {
216
- return sortA - sortB
211
+ const valueB = getSortingValue(
212
+ collectionSchema,
213
+ customization,
214
+ sorting.field,
215
+ b,
216
+ )
217
+ let result: number
218
+ if (sortingField.type === "String") {
219
+ const rawA = valueA?.toString().toLowerCase() ?? ""
220
+ const rawB = valueB?.toString().toLowerCase() ?? ""
221
+ result = rawA > rawB ? 1 : rawA < rawB ? -1 : 0
222
+ } else if (isRelationField(sortingField)) {
223
+ const titleField = sortingField.titleField
224
+ let rawA: string
225
+ let rawB: string
226
+ if (titleField) {
227
+ const recordA = Object.values(a[sortingField.name] ?? {})[0] as
228
+ | StokerRecord
229
+ | undefined
230
+ const recordB = Object.values(b[sortingField.name] ?? {})[0] as
231
+ | StokerRecord
232
+ | undefined
233
+ // eslint-disable-next-line security/detect-object-injection
234
+ rawA = recordA?.[titleField]?.toString().toLowerCase() ?? ""
235
+ // eslint-disable-next-line security/detect-object-injection
236
+ rawB = recordB?.[titleField]?.toString().toLowerCase() ?? ""
237
+ } else {
238
+ rawA = (
239
+ Object.keys(a[sortingField.name] ?? {})[0] ?? ""
240
+ ).toLowerCase()
241
+ rawB = (
242
+ Object.keys(b[sortingField.name] ?? {})[0] ?? ""
243
+ ).toLowerCase()
244
+ }
245
+ result = rawA > rawB ? 1 : rawA < rawB ? -1 : 0
246
+ } else if (sortingField.type === "Timestamp") {
247
+ const rawA = Number(valueA?.valueOf() || 0)
248
+ const rawB = Number(valueB?.valueOf() || 0)
249
+ result = rawA > rawB ? 1 : rawA < rawB ? -1 : 0
217
250
  } else {
218
- return sortB - sortA
251
+ result = valueA > valueB ? 1 : valueA < valueB ? -1 : 0
219
252
  }
253
+ return sorting.direction === "asc" ? result : -result
220
254
  })
255
+ .slice(page * pages, (page + 1) * pages)
221
256
  .map((result: StokerRecord) => (
222
257
  <TableRow
223
258
  key={result.id}