Skip to content

Commit b45e999

Browse files
authored
Merge pull request #19 from danilo-css/master
Improve FilterDialog UX
2 parents dc4bae7 + 6d45c7e commit b45e999

File tree

5 files changed

+367
-24
lines changed

5 files changed

+367
-24
lines changed

components/FilterDialog.tsx

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ import {
77
DialogTrigger,
88
} from "@/components/ui/dialog";
99
import { useDuckDBStore } from "@/stores/useDuckDBStore";
10-
import { ChevronLeft, ChevronRight, Filter, Loader2 } from "lucide-react";
10+
import {
11+
ChevronLeft,
12+
ChevronRight,
13+
Filter,
14+
Loader2,
15+
ChevronsLeft,
16+
ChevronsRight,
17+
} from "lucide-react";
1118
import React, { useState } from "react";
1219
import { Button } from "./ui/button";
1320
import {
@@ -21,6 +28,13 @@ import { Input } from "@/components/ui/input";
2128
import { Checkbox } from "@/components/ui/checkbox";
2229
import { usePivotStore } from "@/stores/usePivotStore";
2330
import { Table as Arrow } from "apache-arrow";
31+
import {
32+
Collapsible,
33+
CollapsibleContent,
34+
CollapsibleTrigger,
35+
} from "@/components/ui/collapsible";
36+
import { ChevronDown, ChevronUp } from "lucide-react";
37+
import { Separator } from "./ui/separator";
2438

2539
export default function FilterDialog({
2640
table,
@@ -40,6 +54,7 @@ export default function FilterDialog({
4054
const [searchQuery, setSearchQuery] = useState("");
4155
const [currentPage, setCurrentPage] = useState(1);
4256
const [open, setOpen] = useState(false);
57+
const [isOpen, setIsOpen] = useState(true);
4358
const itemsPerPage = 10;
4459

4560
const fetchData = async () => {
@@ -113,7 +128,7 @@ export default function FilterDialog({
113128
<DialogTrigger>
114129
<Filter size={20} className="cursor-pointer hover:text-black" />
115130
</DialogTrigger>
116-
<DialogContent className="bg-gray-700">
131+
<DialogContent className="bg-gray-700 max-h-[90vh] overflow-y-auto">
117132
<DialogHeader>
118133
<DialogTitle>Add filter</DialogTitle>
119134
<DialogDescription className="text-white">
@@ -177,7 +192,13 @@ export default function FilterDialog({
177192
</TableBody>
178193
</Table>
179194
</div>
180-
<div className="flex justify-between items-center text-white">
195+
<div className="flex justify-between items-center text-white gap-2">
196+
<Button
197+
onClick={() => setCurrentPage(1)}
198+
disabled={currentPage === 1}
199+
>
200+
<ChevronsLeft />
201+
</Button>
181202
<Button
182203
onClick={() => setCurrentPage((prev) => Math.max(prev - 1, 1))}
183204
disabled={currentPage === 1}
@@ -195,13 +216,38 @@ export default function FilterDialog({
195216
>
196217
<ChevronRight />
197218
</Button>
219+
<Button
220+
onClick={() => setCurrentPage(totalPages)}
221+
disabled={currentPage === totalPages}
222+
>
223+
<ChevronsRight />
224+
</Button>
198225
</div>
199-
<p className="text-wrap break-all">
200-
Selected values: {`[${selectedValues}]`}
201-
</p>
202226
<Button onClick={handleSubmit} className="mt-4">
203227
Apply Filter
204228
</Button>
229+
<Collapsible open={isOpen} onOpenChange={setIsOpen} className="mt-4">
230+
<CollapsibleTrigger className="flex items-center justify-between w-full text-white p-2 hover:bg-gray-600 rounded-md">
231+
<span>Selected values ({selectedValues.length})</span>
232+
{isOpen ? <ChevronUp size={16} /> : <ChevronDown size={16} />}
233+
</CollapsibleTrigger>
234+
<CollapsibleContent className="mt-2">
235+
<ul className="space-y-1">
236+
{selectedValues.map((value, index) => (
237+
<>
238+
<Separator orientation="horizontal" />
239+
<li
240+
key={index}
241+
className="text-white px-2 py-1 w-full text-ellipsis break-all"
242+
title={value}
243+
>
244+
{value}
245+
</li>
246+
</>
247+
))}
248+
</ul>
249+
</CollapsibleContent>
250+
</Collapsible>
205251
</div>
206252
</DialogContent>
207253
</Dialog>

components/ui/collapsible.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use client"
2+
3+
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
4+
5+
const Collapsible = CollapsiblePrimitive.Root
6+
7+
const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger
8+
9+
const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent
10+
11+
export { Collapsible, CollapsibleTrigger, CollapsibleContent }

components/ui/separator.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use client"
2+
3+
import * as React from "react"
4+
import * as SeparatorPrimitive from "@radix-ui/react-separator"
5+
6+
import { cn } from "@/lib/utils"
7+
8+
const Separator = React.forwardRef<
9+
React.ElementRef<typeof SeparatorPrimitive.Root>,
10+
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
11+
>(
12+
(
13+
{ className, orientation = "horizontal", decorative = true, ...props },
14+
ref
15+
) => (
16+
<SeparatorPrimitive.Root
17+
ref={ref}
18+
decorative={decorative}
19+
orientation={orientation}
20+
className={cn(
21+
"shrink-0 bg-border",
22+
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
23+
className
24+
)}
25+
{...props}
26+
/>
27+
)
28+
)
29+
Separator.displayName = SeparatorPrimitive.Root.displayName
30+
31+
export { Separator }

0 commit comments

Comments
 (0)