Skip to content

Commit 7e595e9

Browse files
authored
fix filters on reports and ngos (#159)
1 parent 0709c1d commit 7e595e9

11 files changed

Lines changed: 186 additions & 265 deletions

File tree

client/src/components/data-table/data-table-date-filter.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ro } from "date-fns/locale";
44
import { CalendarIcon, XCircle } from "lucide-react";
55
import * as React from "react";
66
import type { DateRange } from "react-day-picker";
7+
import { parse, isValid, format as formatISODate } from "date-fns";
78

89
import { Button } from "@/components/ui/button";
910
import { Calendar } from "@/components/ui/calendar";
@@ -21,12 +22,10 @@ function getIsDateRange(value: DateSelection): value is DateRange {
2122
return value && typeof value === "object" && !Array.isArray(value);
2223
}
2324

24-
function parseAsDate(timestamp: number | string | undefined): Date | undefined {
25-
if (!timestamp) return undefined;
26-
const numericTimestamp =
27-
typeof timestamp === "string" ? Number(timestamp) : timestamp;
28-
const date = new Date(numericTimestamp);
29-
return !Number.isNaN(date.getTime()) ? date : undefined;
25+
function parseAsDate(dateString: string | undefined): Date | undefined {
26+
if (!dateString) return undefined;
27+
const parsed = parse(dateString, "yyyy-MM-dd", new Date());
28+
return isValid(parsed) ? parsed : undefined;
3029
}
3130

3231
function parseColumnFilterValue(value: unknown) {
@@ -36,14 +35,11 @@ function parseColumnFilterValue(value: unknown) {
3635

3736
if (Array.isArray(value)) {
3837
return value.map((item) => {
39-
if (typeof item === "number" || typeof item === "string") {
40-
return item;
41-
}
42-
return undefined;
38+
return typeof item === "string" ? item : undefined;
4339
});
4440
}
4541

46-
if (typeof value === "string" || typeof value === "number") {
42+
if (typeof value === "string") {
4743
return [value];
4844
}
4945

@@ -89,11 +85,13 @@ export function DataTableDateFilter<TData>({
8985
}
9086

9187
if (multiple && !("getTime" in date)) {
92-
const from = date.from?.getTime();
93-
const to = date.to?.getTime();
88+
const from = date.from
89+
? formatISODate(date.from, "yyyy-MM-dd")
90+
: undefined;
91+
const to = date.to ? formatISODate(date.to, "yyyy-MM-dd") : undefined;
9492
column.setFilterValue(from || to ? [from, to] : undefined);
9593
} else if (!multiple && "getTime" in date) {
96-
column.setFilterValue(date.getTime());
94+
column.setFilterValue(formatISODate(date, "yyyy-MM-dd"));
9795
}
9896
},
9997
[column, multiple]
@@ -179,7 +177,7 @@ export function DataTableDateFilter<TData>({
179177
{hasValue ? (
180178
<div
181179
role="button"
182-
aria-label={`Sterge ${title}`}
180+
aria-label={`Șterge ${title}`}
183181
tabIndex={0}
184182
onClick={onReset}
185183
className="rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"

client/src/components/data-table/data-table-faceted-filter.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,24 @@ interface DataTableFacetedFilterProps<TData, TValue> {
2929
title?: string;
3030
options: Option[];
3131
multiple?: boolean;
32+
disabled?: boolean;
3233
}
3334

3435
export function DataTableFacetedFilter<TData, TValue>({
3536
column,
3637
title,
3738
options,
3839
multiple,
40+
disabled,
3941
}: DataTableFacetedFilterProps<TData, TValue>) {
4042
const [open, setOpen] = React.useState(false);
4143

44+
React.useEffect(() => {
45+
if (disabled && open) {
46+
setOpen(false);
47+
}
48+
}, [disabled, open]);
49+
4250
const columnFilterValue = column?.getFilterValue();
4351
const selectedValues = new Set(
4452
Array.isArray(columnFilterValue) ? columnFilterValue : []
@@ -76,7 +84,7 @@ export function DataTableFacetedFilter<TData, TValue>({
7684
return (
7785
<Popover open={open} onOpenChange={setOpen}>
7886
<PopoverTrigger asChild>
79-
<Button variant="outline" size="sm" className="border-dashed">
87+
<Button variant="outline" size="sm" className="border-dashed" disabled={disabled} aria-disabled={disabled}>
8088
{selectedValues?.size > 0 ? (
8189
<div
8290
role="button"
@@ -133,7 +141,7 @@ export function DataTableFacetedFilter<TData, TValue>({
133141
<Command>
134142
<CommandInput placeholder={title} />
135143
<CommandList className="max-h-full">
136-
<CommandEmpty>No results found.</CommandEmpty>
144+
<CommandEmpty>Nu există rezultate.</CommandEmpty>
137145
<CommandGroup className="max-h-[18.75rem] overflow-y-auto overflow-x-hidden">
138146
{options.map((option) => {
139147
const isSelected = selectedValues.has(option.value);
@@ -172,7 +180,7 @@ export function DataTableFacetedFilter<TData, TValue>({
172180
onSelect={() => onReset()}
173181
className="justify-center text-center"
174182
>
175-
Sterge filtre
183+
Șterge filtre
176184
</CommandItem>
177185
</CommandGroup>
178186
</>

client/src/components/data-table/data-table-slider-filter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export function DataTableSliderFilter<TData>({
134134
{columnFilterValue ? (
135135
<div
136136
role="button"
137-
aria-label={`Sterge ${title}`}
137+
aria-label={`Șterge ${title}`}
138138
tabIndex={0}
139139
className="rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
140140
onClick={onReset}
@@ -226,12 +226,12 @@ export function DataTableSliderFilter<TData>({
226226
/>
227227
</div>
228228
<Button
229-
aria-label={`Sterge ${title}`}
229+
aria-label={`Șterge ${title}`}
230230
variant="outline"
231231
size="sm"
232232
onClick={onReset}
233233
>
234-
Sterge
234+
Șterge
235235
</Button>
236236
</PopoverContent>
237237
</Popover>

client/src/components/data-table/data-table-toolbar.tsx

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)