From d3109c4a1c945c837dacb36026916ca16a73bdbd Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Mon, 24 Jun 2024 08:28:51 +0000 Subject: [PATCH] feat(nc-gui): add custom date range filter support --- .../nc-gui/components/workspace/AuditLogs.vue | 118 ++++++++++++++++-- 1 file changed, 110 insertions(+), 8 deletions(-) diff --git a/packages/nc-gui/components/workspace/AuditLogs.vue b/packages/nc-gui/components/workspace/AuditLogs.vue index a11f5fd374..b46c1b9b89 100644 --- a/packages/nc-gui/components/workspace/AuditLogs.vue +++ b/packages/nc-gui/components/workspace/AuditLogs.vue @@ -198,6 +198,46 @@ const handleUpdateDateRange = (range?: AuditLogsDateRange, label?: string) => { loadAudits() } +const isEditEnabled = computed(() => true) + +// provide the following to override the default behavior and enable input fields like in form +provide(ActiveCellInj, ref(true)) +provide(EditModeInj, readonly(isEditEnabled)) + +provide(IsFormInj, ref(true)) + +const handleCustomDateRangeClick = () => { + if (auditLogsQuery.value.dateRange === AuditLogsDateRange.Custom) { + auditLogsQuery.value.dateRange = undefined + auditLogsQuery.value.dateRangeLabel = undefined + auditDropdowns.value.dateRange = false + } else { + auditLogsQuery.value.dateRange = AuditLogsDateRange.Custom + auditLogsQuery.value.dateRangeLabel = 'Custom Date Range' + } + + auditLogsQuery.value.startDate = undefined + auditLogsQuery.value.endDate = undefined + + loadAudits() +} + +const handleUpdateCustomDateRange = (value: string | null, field: 'startDate' | 'endDate') => { + if (field === 'startDate') { + auditLogsQuery.value[field] = value || undefined + } else if (value) { + const currentTime = dayjs() + + const now = dayjs(value, 'YYYY-MM-DD').hour(currentTime.hour()).minute(currentTime.minute()) + + auditLogsQuery.value[field] = now.utc().format('YYYY-MM-DD HH:mm:ssZ') + } else { + auditLogsQuery.value[field] = undefined + } + + loadAudits() +} + onMounted(async () => { if (audits.value === null) { await loadAudits(currentPage.value, currentLimit.value) @@ -221,7 +261,7 @@ onMounted(async () => {