-
Notifications
You must be signed in to change notification settings - Fork 2
Admin booking filter 2 #151
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
Changes from 3 commits
98a72e5
f2f8f3f
cd1b034
ed65468
df971c6
1ee398b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| } | ||
|
|
||
| .small { | ||
| flex: 1 1 0; | ||
| flex: 0.5 1 0; | ||
| } | ||
|
|
||
| .fluid { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,9 @@ | ||||||||||||||||||||||||||||||||
| import { parseISO, parse, isWithinInterval, startOfDay, endOfDay } from "date-fns"; | ||||||||||||||||||||||||||||||||
| import throttle from "lodash/throttle"; | ||||||||||||||||||||||||||||||||
| import { Key, useMemo, useState } from "react"; | ||||||||||||||||||||||||||||||||
| import { SortOrder } from "react-base-table"; | ||||||||||||||||||||||||||||||||
| import { Filters } from "../components/admin-search-bar/admin-search-bar"; | ||||||||||||||||||||||||||||||||
| import { DATE_FORMAT } from "../constants"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import { sort } from "../utils/transform-utils"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -14,7 +16,16 @@ export type TableStateOptions = { | |||||||||||||||||||||||||||||||
| defaultSortBy?: SortBy; | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| export default function useTableState<T>( | ||||||||||||||||||||||||||||||||
| interface FilterableItem { | ||||||||||||||||||||||||||||||||
| title?: string; | ||||||||||||||||||||||||||||||||
| venue?: { | ||||||||||||||||||||||||||||||||
| name?: string; | ||||||||||||||||||||||||||||||||
| } | null; | ||||||||||||||||||||||||||||||||
| date?: string; | ||||||||||||||||||||||||||||||||
| status?: string; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+26
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| export default function useTableState<T extends FilterableItem>( | ||||||||||||||||||||||||||||||||
| data: T[], | ||||||||||||||||||||||||||||||||
| { defaultSortBy }: TableStateOptions = {}, | ||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||
|
|
@@ -23,6 +34,7 @@ export default function useTableState<T>( | |||||||||||||||||||||||||||||||
| title: "", | ||||||||||||||||||||||||||||||||
| venue: "", | ||||||||||||||||||||||||||||||||
| date: "", | ||||||||||||||||||||||||||||||||
| status: "" | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const onFilterChange = useMemo( | ||||||||||||||||||||||||||||||||
|
|
@@ -31,24 +43,17 @@ export default function useTableState<T>( | |||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const filteredData = useMemo(() => { | ||||||||||||||||||||||||||||||||
| const { title, venue, date } = activeFilters; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const { title, venue, date, status } = activeFilters; | ||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||
| data.length === 0 || | ||||||||||||||||||||||||||||||||
| (!title && !venue && !date) | ||||||||||||||||||||||||||||||||
| (!title && !venue && !date && !status) | ||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||
| return data; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const formattedDate = date | ||||||||||||||||||||||||||||||||
| ? new Date(date).toLocaleDateString("en-GB", { | ||||||||||||||||||||||||||||||||
| day: "2-digit", | ||||||||||||||||||||||||||||||||
| month: "2-digit", | ||||||||||||||||||||||||||||||||
| year: "numeric", | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| : ""; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return data.filter((item: any) => { | ||||||||||||||||||||||||||||||||
| return data.filter((datum) => { | ||||||||||||||||||||||||||||||||
| const item = datum; | ||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+55
|
||||||||||||||||||||||||||||||||
| return data.filter((datum) => { | |
| const item = datum; | |
| return data.filter((item) => { |
Copilot
AI
Jan 3, 2026
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.
The date range logic creates an interval from the earlier of filterDate or today to the later of the two. This means selecting "Tomorrow" filters bookings between today and tomorrow, while "Yesterday" filters bookings between yesterday and today. This range-based filtering behavior is not intuitive given the shortcut names like "Tomorrow" or "Yesterday" which suggest single-day filtering. Consider clarifying the intended behavior: if these shortcuts should filter for a specific day, use a single-day range instead; if they should filter for ranges, consider renaming the shortcuts to be more explicit (e.g., "Through Tomorrow", "Since Yesterday").
| const today = new Date(); | |
| if (!item.date) return false; | |
| const itemDate = parse(item.date, DATE_FORMAT, new Date()); | |
| const start = startOfDay(filterDate < today ? filterDate : today); | |
| const end = endOfDay(filterDate > today ? filterDate : today); | |
| if (!item.date) return false; | |
| const itemDate = parse(item.date, DATE_FORMAT, new Date()); | |
| const start = startOfDay(filterDate); | |
| const end = endOfDay(filterDate); |
Copilot
AI
Jan 3, 2026
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.
The date filtering logic checks item.date, but the actual property name in the booking data is eventDateString (as defined in constants and used in the booking table). This will cause the filter to always return false for items, making the date filter non-functional. The code should check item.eventDateString instead.
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.
The
currentShortcutValuecomputation performs multiple date calculations and format operations on every render. While it's memoized withuseMemo, the calculation itself is still expensive with 14 conditional branches. Consider extracting this logic into a helper function or simplifying by storing the shortcut value directly in state when a shortcut is selected, rather than reverse-engineering it from the date string.