-
Notifications
You must be signed in to change notification settings - Fork 1.9k
react_people-table-advanced #1818
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,65 @@ | ||
| import { Link, useSearchParams } from 'react-router-dom'; | ||
| import { getSearchWith } from '../utils/searchHelper'; | ||
|
|
||
| export const PeopleFilters = () => { | ||
| const [searchParams, setSearchParams] = useSearchParams(); | ||
|
|
||
| // Витягуємо поточні значення з URL для підсвічування активних кнопок/табів | ||
| const query = searchParams.get('query') || ''; | ||
| const sex = searchParams.get('sex'); | ||
| const centuries = searchParams.getAll('centuries'); | ||
|
|
||
| // Обробник для текстового поля пошуку | ||
| // Як має бути: | ||
| // Як має бути: | ||
| const handleQueryChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const value = e.target.value; | ||
|
|
||
| setSearchParams( | ||
| new URLSearchParams( | ||
| getSearchWith(searchParams, { query: value || null }), | ||
| ), | ||
| ); | ||
| }; | ||
|
|
||
| // Логіка для додавання/видалення століть | ||
| const getCenturySearch = (century: string) => { | ||
| let newCenturies = [...centuries]; | ||
|
|
||
| if (newCenturies.includes(century)) { | ||
| newCenturies = newCenturies.filter(c => c !== century); | ||
| } else { | ||
| newCenturies.push(century); | ||
|
Comment on lines
+31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| return getSearchWith(searchParams, { | ||
| centuries: newCenturies.length > 0 ? newCenturies : null, | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <nav className="panel"> | ||
| <p className="panel-heading">Filters</p> | ||
|
|
||
| <p className="panel-tabs" data-cy="SexFilter"> | ||
| <a className="is-active" href="#/people"> | ||
| <Link | ||
| to={{ search: getSearchWith(searchParams, { sex: null }) }} | ||
| className={!sex ? 'is-active' : ''} | ||
| > | ||
| All | ||
| </a> | ||
| <a className="" href="#/people?sex=m"> | ||
| </Link> | ||
| <Link | ||
| to={{ search: getSearchWith(searchParams, { sex: 'm' }) }} | ||
| className={sex === 'm' ? 'is-active' : ''} | ||
| > | ||
| Male | ||
| </a> | ||
| <a className="" href="#/people?sex=f"> | ||
| </Link> | ||
| <Link | ||
| to={{ search: getSearchWith(searchParams, { sex: 'f' }) }} | ||
| className={sex === 'f' ? 'is-active' : ''} | ||
| > | ||
| Female | ||
| </a> | ||
| </Link> | ||
| </p> | ||
|
|
||
| <div className="panel-block"> | ||
|
|
@@ -22,8 +69,9 @@ export const PeopleFilters = () => { | |
| type="search" | ||
| className="input" | ||
| placeholder="Search" | ||
| value={query} | ||
| onChange={handleQueryChange} | ||
| /> | ||
|
|
||
| <span className="icon is-left"> | ||
| <i className="fas fa-search" aria-hidden="true" /> | ||
| </span> | ||
|
|
@@ -33,63 +81,38 @@ export const PeopleFilters = () => { | |
| <div className="panel-block"> | ||
| <div className="level is-flex-grow-1 is-mobile" data-cy="CenturyFilter"> | ||
| <div className="level-left"> | ||
| <a | ||
| data-cy="century" | ||
| className="button mr-1" | ||
| href="#/people?centuries=16" | ||
| > | ||
| 16 | ||
| </a> | ||
|
|
||
| <a | ||
| data-cy="century" | ||
| className="button mr-1 is-info" | ||
| href="#/people?centuries=17" | ||
| > | ||
| 17 | ||
| </a> | ||
|
|
||
| <a | ||
| data-cy="century" | ||
| className="button mr-1 is-info" | ||
| href="#/people?centuries=18" | ||
| > | ||
| 18 | ||
| </a> | ||
|
|
||
| <a | ||
| data-cy="century" | ||
| className="button mr-1 is-info" | ||
| href="#/people?centuries=19" | ||
| > | ||
| 19 | ||
| </a> | ||
|
|
||
| <a | ||
| data-cy="century" | ||
| className="button mr-1" | ||
| href="#/people?centuries=20" | ||
| > | ||
| 20 | ||
| </a> | ||
| {['16', '17', '18', '19', '20'].map(century => ( | ||
| <Link | ||
| key={century} | ||
| data-cy="century" | ||
| className={`button mr-1 ${centuries.includes(century) ? 'is-info' : ''}`} | ||
| to={{ search: getCenturySearch(century) }} | ||
| > | ||
| {century} | ||
| </Link> | ||
| ))} | ||
| </div> | ||
|
|
||
| <div className="level-right ml-4"> | ||
| <a | ||
| <Link | ||
| data-cy="centuryALL" | ||
| className="button is-success is-outlined" | ||
| href="#/people" | ||
| className={`button ${centuries.length === 0 ? 'is-success' : ''} is-outlined`} | ||
| to={{ search: getSearchWith(searchParams, { centuries: null }) }} | ||
| > | ||
| All | ||
| </a> | ||
| </Link> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="panel-block"> | ||
| <a className="button is-link is-outlined is-fullwidth" href="#/people"> | ||
| {/* Reset All просто скидає всі параметри пошуку (порожній рядок) */} | ||
| <Link | ||
| className="button is-link is-outlined is-fullwidth" | ||
| to={{ search: '' }} | ||
| > | ||
| Reset all filters | ||
| </a> | ||
| </Link> | ||
| </div> | ||
| </nav> | ||
| ); | ||
|
|
||
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 checklist requires: (1) first click = ascending with no
orderparam, (2) second click = descending withorder=desc, and (3) third click = sorting disabled with nosortand noorder. YourhandleSortcorrectly togglessortand setsorder='desc'on the second click, and clears both on the third click, so the URL behavior from the table side matches the requirements.