From d2142460b9a29a5518d45e3da12fee05020638d3 Mon Sep 17 00:00:00 2001 From: IvanPresmytky Date: Thu, 17 Oct 2024 13:04:20 +0300 Subject: [PATCH 1/2] fix filtering date ranges in demo table --- .../demo/tables/masterDetailedTable/MasterDetailedTable.tsx | 2 +- app/src/demo/tables/masterDetailedTable/filters.ts | 1 + server/helpers/getFilterPredicate.js | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/demo/tables/masterDetailedTable/MasterDetailedTable.tsx b/app/src/demo/tables/masterDetailedTable/MasterDetailedTable.tsx index 56e7aedcb2..91fc396f21 100644 --- a/app/src/demo/tables/masterDetailedTable/MasterDetailedTable.tsx +++ b/app/src/demo/tables/masterDetailedTable/MasterDetailedTable.tsx @@ -41,7 +41,7 @@ export function MasterDetailedTable() { ); const pin = useCallback( - ({ value: { __typename } }: DataRowProps) => + ({ value: { __typename } }: DataRowProps) => __typename !== 'Person', [], ); diff --git a/app/src/demo/tables/masterDetailedTable/filters.ts b/app/src/demo/tables/masterDetailedTable/filters.ts index 883df3ba54..0a5b865333 100644 --- a/app/src/demo/tables/masterDetailedTable/filters.ts +++ b/app/src/demo/tables/masterDetailedTable/filters.ts @@ -50,6 +50,7 @@ export const getFilters = >(): TableFiltersC columnKey: 'birthDate', title: 'Birth Date', type: 'rangeDatePicker', + format: 'YYYY-MM-DD', }, ]; }; diff --git a/server/helpers/getFilterPredicate.js b/server/helpers/getFilterPredicate.js index 7e1cc88322..8d56a9863c 100644 --- a/server/helpers/getFilterPredicate.js +++ b/server/helpers/getFilterPredicate.js @@ -19,6 +19,12 @@ function simplifyPredicates(filter) { var key = keys[n]; var condition = filter[key]; if (condition != null && typeof condition === "object") { + if ('from' in condition && 'to' in condition) { + result[key] = { + gte: condition.from, + lte: condition.to + }; + } if ('inRange' in condition) { var value = condition.inRange; result[key] = { From 35fb277ea040d746e63c8a1f5ea770b20af6cc15 Mon Sep 17 00:00:00 2001 From: IvanPresmytky Date: Thu, 17 Oct 2024 17:33:49 +0300 Subject: [PATCH 2/2] fix sorting for dates in demo tables --- server/helpers/getFilterPredicate.js | 3 +++ server/helpers/getOrderComparer.js | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/helpers/getFilterPredicate.js b/server/helpers/getFilterPredicate.js index 8d56a9863c..58761e1586 100644 --- a/server/helpers/getFilterPredicate.js +++ b/server/helpers/getFilterPredicate.js @@ -54,6 +54,9 @@ exports.simplifyPredicates = simplifyPredicates; function isDate(val) { return dayjs_1["default"](val).isValid(); } + +exports.isDate = isDate; + var truePredicate = function () { return true; }; function getFilterPredicate(filter) { filter = simplifyPredicates(filter); diff --git a/server/helpers/getOrderComparer.js b/server/helpers/getOrderComparer.js index ee4f844b80..58ca107870 100644 --- a/server/helpers/getOrderComparer.js +++ b/server/helpers/getOrderComparer.js @@ -1,4 +1,6 @@ exports.__esModule = true; +const { isDate } = require('./getFilterPredicate'); + const eqPredicate = function () { return 0; }; // Previous versions use this comparer. While it works great for human-readable strings, it's broken for dates. Also, we need a plain sort in case of 'order' fields. // const compareScalars = (new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'})).compare; @@ -22,7 +24,10 @@ function getOrderComparer(sorting) { const comparer = function (a, b) { for (let n = 0; n < sorting.length; n++) { const fieldName = sorting[n].field; - const compareResult = compareScalars(a[fieldName], b[fieldName], sortingOrders[n]); + const isDateField = isDate(a[fieldName]) && isDate(b[fieldName]); + const compareResult = isDateField + ? compareScalars(new Date(a[fieldName]), new Date(b[fieldName]), sortingOrders[n]) + : compareScalars(a[fieldName], b[fieldName], sortingOrders[n]); if (compareResult !== 0) { return compareResult; }