-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98a72e5
Admin filter title venue date first draft
Shum-ster f2f8f3f
Added status filter and date range shortcuts
Shum-ster cd1b034
Merge branch 'master' into feature/admin-booking-filter
Shum-ster ed65468
Fix date shortcut filter
Shum-ster df971c6
Merge branch 'feature/admin-booking-filter' of https://github.com/CAP…
Shum-ster 1ee398b
Merge branch 'master' into feature/admin-booking-filter
Shum-ster 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
Some comments aren't visible on the classic Files Changed page.
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
| 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 { | ||
|
|
||
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
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 | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||
| import { endOfDay, isWithinInterval, parseISO, startOfDay } from "date-fns"; | ||||||||
| import throttle from "lodash/throttle"; | ||||||||
| import { Key, useMemo, useState } from "react"; | ||||||||
| import { SortOrder } from "react-base-table"; | ||||||||
|
|
@@ -14,7 +15,17 @@ export type TableStateOptions = { | |||||||
| defaultSortBy?: SortBy; | ||||||||
| }; | ||||||||
|
|
||||||||
| export default function useTableState<T>( | ||||||||
| interface FilterableItem { | ||||||||
| title?: string; | ||||||||
| venue?: { | ||||||||
| name?: string; | ||||||||
| } | null; | ||||||||
| eventDateString?: string; | ||||||||
| startDateTime?: number | string; | ||||||||
| status?: string; | ||||||||
| } | ||||||||
|
|
||||||||
| 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) => { |
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.
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.