feat: add date presets, assign default operators, and unify formatting across dashboard, query builder, and chart - #1210
Conversation
|
Tick the box to add this pull request to the merge queue (same as
|
Confidence Score: 5/5Safe to merge — all changes are frontend-only Vue components and utilities with no backend or security-sensitive paths touched. The change is a well-scoped frontend feature addition. Logic for preset evaluation, date formatting, and model binding is internally consistent. The only gaps are missing translation wrappers on a handful of newly added strings. frontend/src2/query/components/AbsoluteDatePickerControl.vue and RelativeDatePickerControl.vue — both new files are missing __() imports and wrappers for their hardcoded strings. Reviews (2): Last reviewed commit: "chore: remove unused dayjs import" | Re-trigger Greptile |
|
@AdnanQuazi we should use frappe-ui's new date picker component, https://ui.frappe.io/docs/components/datepicker I'll update frappe-ui soon, maybe you can refactor it after that? |
|
@nextchamp-saqib sure! |
Overview
This PR adds date range presets for absolute and relative dates (
betweenandwithinoperator), introduces a<PresetWrapper>component, and unifies date filtering UI and label formatting across Dashboard, Query Builder, and Chart filters for consistency across the application.Previously, absolute date range (
between) filters and relative date range (within) did not have preset options, requiring users to select ranges on the calendar manually or select from the dropdown components in within. In addition, custom date selections displayed raw ISO strings, and Dashboard filters used a separate implementation from the Query Builder and Chart filters.Key Changes
1. Added Date Range Presets (
between&within)Today,Yesterday,This Month,Last Month,This Quarter,Last Year, etc.) for both absolute (between) and relative (within) date filters.Presettype structure (value: () => string | string[]). This ensures dynamic date ranges (like This Month) are evaluated fresh when selected, preventing dates from becoming stale if the application stays open across day boundaries.2. Created Shared UI Wrapper (
<PresetWrapper>)<PresetWrapper.vue>to handle dropdown preset selection above custom calendar or relative form controls.3. Unified Formatting Across Dashboard, Query, and Charts
formatDateFilterValue()andformatDateRangeDescription()to serve as the single source of truth for date labels across the frontend.Jan 1 - Dec 31Jan 1, 2024 - Dec 31, 20242025-01-01,2025-12-31) with clean, formatted date spans (Jan 1 - Dec 31, 2025) across filter button labels.Component & Architectural Breakdown
Core Types & Utilities (
query/components/)query.types.ts: Added thePresettype to use consistent function returns (label: string,value: () => string | string[],description?: () => string).filter_utils.ts: AddedgetDatePresets(operator), andfindPresetByValue().formatting_utils.ts: AddedformatDateFilterValue()andformatDateRangeDescription()to handle date label formatting centrally.Shared Pickers & Wrappers (
query/components/)PresetWrapper.vue(NEW): Built the shared wrapper component that manages dropdown selection and custom override state.AbsoluteDatePicker.vue(NEW): Created a shared component combining<PresetWrapper>with<DateRangePicker>.AbsoluteDatePickerControl.vue(NEW): Created a popover-wrapped input trigger for both Query Builder rows and Chart sidebar filter rules.RelativeDatePicker.vue&RelativeDatePickerControl.vue: Wrapped these components in<PresetWrapper>so they share the exact same preset dropdown and automatic "Custom" detection as the absolute date pickers.Query Builder & Chart Filters (
query/components/)FilterRule.vue: Integrated<AbsoluteDatePickerControl>forbetweenoperators and<RelativeDatePickerControl>forwithinoperators so Chart sidebar filters and Query Builder rules share the exact same UI.Dashboard Filters (
dashboard/)DashboardFilter.vue: Updated button label formatting to use centralizedformatFilterValue()calls for consistency.DashboardFilterEditor.vue: Replaced standard<DateRangePicker>with<AbsoluteDatePicker>, making presets available when setting default dashboard filters.Filter.vue: Updated popover rendering to use<AbsoluteDatePicker>for absolute date ranges.1. Dashboard Filter Presets
dash-filter-preset.mp4
2. Chart Filter Presets
chart-filter-presets.mp4