-
Notifications
You must be signed in to change notification settings - Fork 0
feat: redesign guest list table and extract filter popover #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6a4e07b
feat: redesign guest list table and extract filter popover
zaydaanjahangir 3006f71
feat: Fix linting and drop tests
zaydaanjahangir 3a0b22d
feat: Add multi-filter filtering
zaydaanjahangir 37d8df9
Merge branch 'main' into feat/guests-list-refresh
zaydaanjahangir 6c2bd73
feat: link new guests backend
zaydaanjahangir a812ae5
fix: Update type errors
zaydaanjahangir 067043b
feat: remove ancient listeners
zaydaanjahangir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
clients/web/src/components/guests/GuestFilterPopover.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| import { Filter } from "lucide-react"; | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { Button } from "@/components/ui/Button"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| type GuestFilterPopoverProps = { | ||
| availableFloors: Array<number>; | ||
| availableGroupSizes: Array<number>; | ||
| selectedFloors: Array<number>; | ||
| selectedGroupSizes: Array<number>; | ||
| onApply: (floors: Array<number>, groupSizes: Array<number>) => void; | ||
| }; | ||
|
|
||
| function FilterChip({ | ||
| label, | ||
| selected, | ||
| onClick, | ||
| }: { | ||
| label: string; | ||
| selected: boolean; | ||
| onClick: () => void; | ||
| }) { | ||
| return ( | ||
| <button | ||
| type="button" | ||
| onClick={onClick} | ||
| className={cn( | ||
| "rounded-lg border px-4 py-1.5 text-sm transition-colors", | ||
| selected | ||
| ? "border-primary bg-primary/10 text-primary" | ||
| : "border-stroke-subtle bg-white text-text-default hover:border-primary", | ||
| )} | ||
| > | ||
| {label} | ||
| </button> | ||
| ); | ||
| } | ||
|
|
||
| function toggleItem(arr: Array<number>, item: number): Array<number> { | ||
| return arr.includes(item) ? arr.filter((v) => v !== item) : [...arr, item]; | ||
| } | ||
|
|
||
| export function GuestFilterPopover({ | ||
| availableFloors, | ||
| availableGroupSizes, | ||
| selectedFloors, | ||
| selectedGroupSizes, | ||
| onApply, | ||
| }: GuestFilterPopoverProps) { | ||
| const [open, setOpen] = useState(false); | ||
| const [pendingFloors, setPendingFloors] = | ||
| useState<Array<number>>(selectedFloors); | ||
| const [pendingGroupSizes, setPendingGroupSizes] = | ||
| useState<Array<number>>(selectedGroupSizes); | ||
| const containerRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| const handleOpen = () => { | ||
| setPendingFloors(selectedFloors); | ||
| setPendingGroupSizes(selectedGroupSizes); | ||
| setOpen(true); | ||
| }; | ||
|
|
||
| const handleClose = () => { | ||
| setOpen(false); | ||
| }; | ||
|
|
||
| const handleApply = () => { | ||
| onApply(pendingFloors, pendingGroupSizes); | ||
| setOpen(false); | ||
| }; | ||
|
|
||
| const handleReset = () => { | ||
| onApply([], []); | ||
| setOpen(false); | ||
| }; | ||
|
|
||
| // Close on click-outside or Escape | ||
| useEffect(() => { | ||
| if (!open) return; | ||
|
|
||
| const handleMouseDown = (e: MouseEvent) => { | ||
| if ( | ||
| containerRef.current && | ||
| !containerRef.current.contains(e.target as Node) | ||
| ) { | ||
| handleClose(); | ||
| } | ||
| }; | ||
|
|
||
| const handleKeyDown = (e: KeyboardEvent) => { | ||
| if (e.key === "Escape") { | ||
| handleClose(); | ||
| } | ||
| }; | ||
|
|
||
| document.addEventListener("mousedown", handleMouseDown); | ||
| document.addEventListener("keydown", handleKeyDown); | ||
| return () => { | ||
| document.removeEventListener("mousedown", handleMouseDown); | ||
| document.removeEventListener("keydown", handleKeyDown); | ||
| }; | ||
| }, [open]); | ||
|
|
||
| const activeFilterCount = selectedFloors.length + selectedGroupSizes.length; | ||
|
|
||
| return ( | ||
| <div className="relative shrink-0" ref={containerRef}> | ||
| <button | ||
| type="button" | ||
| onClick={open ? handleClose : handleOpen} | ||
| aria-expanded={open} | ||
| className={cn( | ||
| "flex h-11 items-center gap-2 rounded-lg border px-4 text-sm font-medium transition-colors", | ||
| activeFilterCount > 0 | ||
| ? "border-primary bg-primary/5 text-primary" | ||
| : "border-stroke-subtle text-text-default hover:bg-primary/5", | ||
| )} | ||
| > | ||
| <Filter className="h-4 w-4" /> | ||
| Filter | ||
| {activeFilterCount > 0 && ( | ||
| <span className="flex h-5 w-5 items-center justify-center rounded-full bg-primary text-xs text-white"> | ||
| {activeFilterCount} | ||
| </span> | ||
| )} | ||
| </button> | ||
|
|
||
| {open && ( | ||
| <div className="absolute right-0 top-[calc(100%+0.5rem)] z-50 flex w-80 flex-col overflow-hidden rounded-2xl bg-white px-6 shadow-xl"> | ||
| <div className="flex items-center justify-between pt-5"> | ||
| <span className="text-base font-medium text-text-default"> | ||
| Filters | ||
| </span> | ||
| <button | ||
| type="button" | ||
| onClick={handleReset} | ||
| className="text-sm text-text-subtle transition-colors hover:text-text-default" | ||
| > | ||
| Reset | ||
| </button> | ||
| </div> | ||
|
|
||
| <div className="flex flex-col gap-5 py-5"> | ||
| {availableFloors.length > 0 && ( | ||
| <section className="flex flex-col gap-3"> | ||
| <h3 className="text-sm font-medium text-text-default">Floor</h3> | ||
| <div className="flex flex-wrap gap-2"> | ||
| {availableFloors.map((floor) => ( | ||
| <FilterChip | ||
| key={floor} | ||
| label={`Floor ${floor}`} | ||
| selected={pendingFloors.includes(floor)} | ||
| onClick={() => | ||
| setPendingFloors(toggleItem(pendingFloors, floor)) | ||
| } | ||
| /> | ||
| ))} | ||
| </div> | ||
| </section> | ||
| )} | ||
|
|
||
| {availableGroupSizes.length > 0 && ( | ||
| <section className="flex flex-col gap-3"> | ||
| <h3 className="text-sm font-medium text-text-default"> | ||
| Group Size | ||
| </h3> | ||
| <div className="flex flex-wrap gap-2"> | ||
| {availableGroupSizes.map((size) => ( | ||
| <FilterChip | ||
| key={size} | ||
| label={String(size)} | ||
| selected={pendingGroupSizes.includes(size)} | ||
| onClick={() => | ||
| setPendingGroupSizes( | ||
| toggleItem(pendingGroupSizes, size), | ||
| ) | ||
| } | ||
| /> | ||
| ))} | ||
| </div> | ||
| </section> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="border-t border-stroke-subtle" /> | ||
| <div className="flex justify-end gap-3 py-4"> | ||
| <Button variant="secondary" onClick={handleClose}> | ||
| Cancel | ||
| </Button> | ||
| <Button variant="primary" onClick={handleApply}> | ||
| Apply | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { GuestFilterPopover } from "./GuestFilterPopover"; | ||
| import { GuestSearchBar } from "./GuestSearchBar"; | ||
|
|
||
| type GuestListHeaderProps = { | ||
| searchTerm: string; | ||
| onSearchChange: (value: string) => void; | ||
| availableFloors: Array<number>; | ||
| availableGroupSizes: Array<number>; | ||
| selectedFloors: Array<number>; | ||
| selectedGroupSizes: Array<number>; | ||
| onApplyFilters: (floors: Array<number>, groupSizes: Array<number>) => void; | ||
| }; | ||
|
|
||
| export function GuestListHeader({ | ||
| searchTerm, | ||
| onSearchChange, | ||
| availableFloors, | ||
| availableGroupSizes, | ||
| selectedFloors, | ||
| selectedGroupSizes, | ||
| onApplyFilters, | ||
| }: GuestListHeaderProps) { | ||
| return ( | ||
| <div className="flex items-center gap-3"> | ||
| <div className="min-w-0 flex-1"> | ||
| <GuestSearchBar value={searchTerm} onChange={onSearchChange} /> | ||
| </div> | ||
| <GuestFilterPopover | ||
| availableFloors={availableFloors} | ||
| availableGroupSizes={availableGroupSizes} | ||
| selectedFloors={selectedFloors} | ||
| selectedGroupSizes={selectedGroupSizes} | ||
| onApply={onApplyFilters} | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like there's a most modern approach to doing key listens aside from a document get. If not, this is good