@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 +6 -0
- package/package.json +1 -1
- package/src/DashboardReminder.tsx +47 -12
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
|
|
@@ -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
|
|
206
|
-
|
|
205
|
+
const valueA = getSortingValue(
|
|
206
|
+
collectionSchema,
|
|
207
207
|
customization,
|
|
208
|
+
sorting.field,
|
|
209
|
+
a,
|
|
208
210
|
)
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
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}
|