From ea5fb35762bdc4348bf72e4077d0c99303ee480f Mon Sep 17 00:00:00 2001 From: Esdras Renan Date: Tue, 18 Nov 2025 23:02:58 -0300 Subject: [PATCH] Adjust reports filters layout and date range picker --- reports-machines-filters-issue.svg | 18 +++++++++ src/components/date-range-button.tsx | 40 ++++++++++++++----- .../reports/machine-category-report.tsx | 1 + .../reports/report-filter-toolbar.tsx | 4 +- 4 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 reports-machines-filters-issue.svg diff --git a/reports-machines-filters-issue.svg b/reports-machines-filters-issue.svg new file mode 100644 index 0000000..ef94d26 --- /dev/null +++ b/reports-machines-filters-issue.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + Filtros com scroll horizontal + Máquinas x categorias - barra com largura fixa + Precisamos remover o overflow e ajustar a largura para corresponder ao layout de categorias. + diff --git a/src/components/date-range-button.tsx b/src/components/date-range-button.tsx index eab5c23..fbe11fe 100644 --- a/src/components/date-range-button.tsx +++ b/src/components/date-range-button.tsx @@ -76,14 +76,36 @@ export function DateRangeButton({ from, to, onChange, className, clearLabel = "L return } - setDraftRange(next) - - if (next?.from && next?.to) { - const nextFrom = dateToStr(next.from) - const nextTo = dateToStr(next.to) ?? nextFrom - onChange({ from: nextFrom, to: nextTo }) - setOpen(false) + if (!draftRange?.from || draftRange?.to) { + setDraftRange(next?.from ? { from: next.from, to: undefined } : undefined) + return } + + if (!draftRange.from) { + setDraftRange(undefined) + return + } + + const start = draftRange.from + const rawSecond = + next?.to && next.to.getTime() !== start.getTime() + ? next.to + : next?.from ?? next?.to ?? start + + if (!rawSecond) { + setDraftRange({ from: start, to: undefined }) + return + } + + const fromDate = rawSecond < start ? rawSecond : start + const toDate = rawSecond < start ? start : rawSecond + const finalRange: DateRange = { from: fromDate, to: toDate } + setDraftRange(finalRange) + + const nextFrom = dateToStr(finalRange.from) + const nextTo = dateToStr(finalRange.to) ?? nextFrom + onChange({ from: nextFrom, to: nextTo }) + setOpen(false) } return ( @@ -111,8 +133,8 @@ export function DateRangeButton({ from, to, onChange, className, clearLabel = "L setCompanyId(value)} companyOptions={companyOptions} diff --git a/src/components/reports/report-filter-toolbar.tsx b/src/components/reports/report-filter-toolbar.tsx index ed440f1..7855ec9 100644 --- a/src/components/reports/report-filter-toolbar.tsx +++ b/src/components/reports/report-filter-toolbar.tsx @@ -30,6 +30,7 @@ type ReportsFilterToolbarProps = { dateFrom?: string | null dateTo?: string | null onDateRangeChange?: (next: { from: string | null; to: string | null }) => void + className?: string } const BILLING_TOGGLE_ITEM = @@ -54,9 +55,10 @@ export function ReportsFilterToolbar({ dateFrom, dateTo, onDateRangeChange, + className, }: ReportsFilterToolbarProps) { return ( -
+