Skip to content

Commit ce8232a

Browse files
Filter panel visual fixes (#105)
* Make filter panel full page height * Fix filter items text when the filter items were cutoff, the text would break onto multiple lines and the count would overlap with the text --------- Co-authored-by: Brendan Kellam <bshizzle1234@gmail.com>
1 parent 7915af8 commit ce8232a

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

packages/web/src/app/search/components/filterPanel/entry.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,30 @@ export const Entry = ({
2525
},
2626
onClicked,
2727
}: EntryProps) => {
28-
28+
let countText = count.toString();
29+
if (count > 999) {
30+
countText = "999+";
31+
}
2932
return (
3033
<div
31-
className={clsx("flex flex-row items-center justify-between py-0.5 px-2 cursor-pointer rounded-md gap-2 select-none",
34+
className={clsx(
35+
"flex flex-row items-center justify-between py-0.5 px-2 cursor-pointer rounded-md gap-2 select-none",
3236
{
3337
"hover:bg-gray-200 dark:hover:bg-gray-700": !isSelected,
3438
"bg-blue-200 dark:bg-blue-400": isSelected,
3539
}
3640
)}
3741
onClick={() => onClicked()}
3842
>
39-
<div className="flex flex-row items-center gap-1">
43+
<div className="flex flex-row items-center gap-1 overflow-hidden">
4044
{Icon ? Icon : (
4145
<QuestionMarkCircledIcon className="w-4 h-4 flex-shrink-0" />
4246
)}
43-
<p className="text-wrap">{displayName}</p>
47+
<p className="overflow-hidden text-ellipsis whitespace-nowrap">{displayName}</p>
48+
</div>
49+
<div className="px-2 py-0.5 bg-gray-100 dark:bg-gray-800 text-sm rounded-md">
50+
{countText}
4451
</div>
45-
<p>{count}</p>
4652
</div>
4753
);
4854
}
@@ -53,4 +59,4 @@ export const compareEntries = (a: Entry, b: Entry) => {
5359
}
5460

5561
return a.count - b.count;
56-
}
62+
}

packages/web/src/app/search/components/filterPanel/filter.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ import { compareEntries, Entry } from "./entry";
55
import { Input } from "@/components/ui/input";
66
import { ScrollArea } from "@/components/ui/scroll-area";
77
import Fuse from "fuse.js";
8+
import { cn } from "@/lib/utils"
89

910
interface FilterProps {
1011
title: string,
1112
searchPlaceholder: string,
1213
entries: Entry[],
1314
onEntryClicked: (key: string) => void,
15+
className?: string,
1416
}
1517

1618
export const Filter = ({
1719
title,
1820
searchPlaceholder,
1921
entries,
2022
onEntryClicked,
23+
className,
2124
}: FilterProps) => {
2225
const [searchFilter, setSearchFilter] = useState<string>("");
2326

@@ -36,19 +39,20 @@ export const Filter = ({
3639
}, [entries, searchFilter]);
3740

3841
return (
39-
<div className="flex flex-col gap-2 p-1">
42+
<div className={cn(
43+
"flex flex-col gap-2 p-1",
44+
className
45+
)}>
4046
<h2 className="text-sm font-semibold">{title}</h2>
4147
<Input
4248
placeholder={searchPlaceholder}
4349
className="h-8"
4450
onChange={(event) => setSearchFilter(event.target.value)}
4551
/>
4652

47-
<ScrollArea
48-
className="overflow-hidden"
49-
>
53+
<ScrollArea>
5054
<div
51-
className="flex flex-col gap-0.5 text-sm h-full max-h-80 px-0.5"
55+
className="flex flex-col gap-0.5 text-sm px-0.5"
5256
>
5357
{filteredEntries
5458
.sort((entryA, entryB) => compareEntries(entryB, entryA))
@@ -63,4 +67,4 @@ export const Filter = ({
6367
</ScrollArea>
6468
</div>
6569
)
66-
}
70+
}

packages/web/src/app/search/components/filterPanel/index.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,23 @@ export const FilterPanel = ({
118118
onFilterChanged(filteredMatches);
119119
}, [matches, repos, languages, onFilterChanged]);
120120

121+
const numRepos = Object.keys(repos).length > 100 ? '100+' : Object.keys(repos).length;
122+
const numLanguages = Object.keys(languages).length > 100 ? '100+' : Object.keys(languages).length;
121123
return (
122-
<div className="p-3 flex flex-col gap-3">
123-
<h1 className="text-lg font-semibold">Filter Results</h1>
124-
124+
<div className="p-3 flex flex-col gap-3 h-full">
125125
<Filter
126-
title="By Repository"
127-
searchPlaceholder="Filter repositories"
126+
title="Filter By Repository"
127+
searchPlaceholder={`Filter ${numRepos} repositories`}
128128
entries={Object.values(repos)}
129129
onEntryClicked={(key) => onEntryClicked(key, setRepos)}
130+
className="max-h-[50%]"
130131
/>
131-
132132
<Filter
133-
title="By Language"
134-
searchPlaceholder="Filter languages"
133+
title="Filter By Language"
134+
searchPlaceholder={`Filter ${numLanguages} languages`}
135135
entries={Object.values(languages)}
136136
onEntryClicked={(key) => onEntryClicked(key, setLanguages)}
137+
className="overflow-auto"
137138
/>
138139
</div>
139140
)
@@ -167,4 +168,4 @@ const aggregateMatches = (
167168
aggregation[key].count += 1;
168169
return aggregation;
169170
}, {} as Record<string, Entry>)
170-
}
171+
}

packages/web/src/app/search/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ const PanelGroup = ({
286286
return (
287287
<ResizablePanelGroup
288288
direction="horizontal"
289+
className="h-full"
289290
>
290291
{/* ~~ Filter panel ~~ */}
291292
<ResizablePanel
@@ -354,4 +355,4 @@ const PanelGroup = ({
354355
</ResizablePanel>
355356
</ResizablePanelGroup>
356357
)
357-
}
358+
}

packages/web/src/components/ui/resizable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ const ResizableHandle = ({
2929
}) => (
3030
<ResizablePrimitive.PanelResizeHandle
3131
className={cn(
32-
"relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",
32+
"relative flex w-px items-center justify-center bg-border",
33+
"after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2",
34+
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1",
35+
"data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",
3336
className
3437
)}
3538
{...props}

0 commit comments

Comments
 (0)