@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 +6 -0
- package/package.json +1 -1
- package/src/DashboardReminder.tsx +46 -11
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -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
|
|
216
|
-
|
|
216
|
+
const valueA = getSortingValue(
|
|
217
|
+
collectionSchema,
|
|
217
218
|
customization,
|
|
219
|
+
sorting.field,
|
|
220
|
+
a,
|
|
218
221
|
)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
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) => (
|