From 6823ab50060d7bee2fcd2a521a748c161bacd034 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 11 Mar 2024 09:23:31 +0000 Subject: [PATCH] fix: support Date filter operations in where query params for Created/LastModified time fields --- packages/nc-gui/components/smartsheet/Form.vue | 10 ++++++++-- .../smartsheet/calendar/DayView/DateField.vue | 2 +- .../smartsheet/calendar/DayView/DateTimeField.vue | 2 +- .../components/smartsheet/calendar/MonthView.vue | 2 +- .../smartsheet/calendar/WeekView/DateField.vue | 2 +- .../smartsheet/calendar/WeekView/DateTimeField.vue | 2 +- packages/nc-gui/composables/useViewGroupBy.ts | 4 +++- packages/nocodb-sdk/src/lib/helperFunctions.ts | 9 ++++++++- packages/nocodb/src/db/BaseModelSqlv2.ts | 11 +++++++++-- 9 files changed, 33 insertions(+), 11 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Form.vue b/packages/nc-gui/components/smartsheet/Form.vue index d44cf5d982..b92c41185f 100644 --- a/packages/nc-gui/components/smartsheet/Form.vue +++ b/packages/nc-gui/components/smartsheet/Form.vue @@ -1088,7 +1088,10 @@ useEventListener( -
+
-
+
{ [calendarRange.value[0].fk_from_col!.title!]: selectedDate.value.format('YYYY-MM-DD HH:mm:ssZ'), }, } - emit('newRecord', record) + emit('new-record', record) } diff --git a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue index 7813421720..423f60798c 100644 --- a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue @@ -847,7 +847,7 @@ const newRecord = (hour: dayjs.Dayjs) => { [calendarRange.value[0].fk_from_col!.title!]: hour.format('YYYY-MM-DD HH:mm:ssZ'), }, } - emit('newRecord', record) + emit('new-record', record) } diff --git a/packages/nc-gui/components/smartsheet/calendar/MonthView.vue b/packages/nc-gui/components/smartsheet/calendar/MonthView.vue index e27cb73a8a..69d24059f7 100644 --- a/packages/nc-gui/components/smartsheet/calendar/MonthView.vue +++ b/packages/nc-gui/components/smartsheet/calendar/MonthView.vue @@ -635,7 +635,7 @@ const addRecord = (date: dayjs.Dayjs) => { [fromCol.title!]: date.format('YYYY-MM-DD HH:mm:ssZ'), }, } - emit('newRecord', newRecord) + emit('new-record', newRecord) } diff --git a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateField.vue b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateField.vue index 12c96c7d16..003b644b97 100644 --- a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateField.vue @@ -529,7 +529,7 @@ const addRecord = (date: dayjs.Dayjs) => { [fromCol.title!]: date.format('YYYY-MM-DD HH:mm:ssZ'), }, } - emits('newRecord', newRecord) + emits('new-record', newRecord) } diff --git a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue index e5ad4e23de..16c9060fd2 100644 --- a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue @@ -733,7 +733,7 @@ const addRecord = (date: dayjs.Dayjs) => { [fromCol.title!]: date.format('YYYY-MM-DD HH:mm:ssZ'), }, } - emits('newRecord', newRecord) + emits('new-record', newRecord) } diff --git a/packages/nc-gui/composables/useViewGroupBy.ts b/packages/nc-gui/composables/useViewGroupBy.ts index 8f3480e92d..37c38e6763 100644 --- a/packages/nc-gui/composables/useViewGroupBy.ts +++ b/packages/nc-gui/composables/useViewGroupBy.ts @@ -161,7 +161,9 @@ export const useViewGroupBy = (view: Ref, where?: Computed acc += `${acc.length ? '~and' : ''}(${curr.title},gb_null)` } else if (curr.column_uidt === UITypes.Checkbox) { acc += `${acc.length ? '~and' : ''}(${curr.title},${curr.key === GROUP_BY_VARS.TRUE ? 'checked' : 'notchecked'})` - } else if ([UITypes.Date, UITypes.DateTime].includes(curr.column_uidt as UITypes)) { + } else if ( + [UITypes.Date, UITypes.DateTime, UITypes.CreatedTime, UITypes.LastModifiedTime].includes(curr.column_uidt as UITypes) + ) { acc += `${acc.length ? '~and' : ''}(${curr.title},eq,exactDate,${curr.key})` } else if ([UITypes.User, UITypes.CreatedBy, UITypes.LastModifiedBy].includes(curr.column_uidt as UITypes)) { try { diff --git a/packages/nocodb-sdk/src/lib/helperFunctions.ts b/packages/nocodb-sdk/src/lib/helperFunctions.ts index 43a8d878ec..9831c4f9a6 100644 --- a/packages/nocodb-sdk/src/lib/helperFunctions.ts +++ b/packages/nocodb-sdk/src/lib/helperFunctions.ts @@ -70,7 +70,14 @@ const getAvailableRollupForUiType = (type: string) => { 'sumDistinct', 'avgDistinct', ]; - } else if ([UITypes.Date, UITypes.DateTime].includes(type as UITypes)) { + } else if ( + [ + UITypes.Date, + UITypes.DateTime, + UITypes.CreatedTime, + UITypes.LastModifiedTime, + ].includes(type as UITypes) + ) { return ['count', 'min', 'max', 'countDistinct']; } else if ( [ diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index c34a7ea961..720b57620a 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -6181,7 +6181,14 @@ function validateFilterComparison(uidt: UITypes, op: any, sub_op?: any) { } if (sub_op) { - if (![UITypes.Date, UITypes.DateTime].includes(uidt)) { + if ( + ![ + UITypes.Date, + UITypes.DateTime, + UITypes.CreatedTime, + UITypes.LastModifiedTime, + ].includes(uidt) + ) { NcError.badRequest(`'${sub_op}' is not supported for UI Type'${uidt}'.`); } if (!COMPARISON_SUB_OPS.includes(sub_op)) { @@ -6237,7 +6244,7 @@ export function extractCondition( if (aliasColObjMap[alias]) { if ( - [UITypes.Date, UITypes.DateTime].includes(aliasColObjMap[alias].uidt) + [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime].includes(aliasColObjMap[alias].uidt) ) { value = value?.split(','); // the first element would be sub_op