Skip to content

Persist UI state in the url - #336

Open
paigewilliams wants to merge 2 commits into
paige-react-fe-testingfrom
persist-state-url
Open

paigewilliams wants to merge 2 commits into
paige-react-fe-testingfrom
persist-state-url

Conversation

@paigewilliams

Copy link
Copy Markdown
Collaborator

asana task

Tracks the searched query and the checked filters. In the previous implementation we were tracking things like the items_per_page, which I don't think we need to have in the url search params. items_per_page is not something user configured, so I decided there was no need to keep that functionality in the react migration.

I also started adding client testing infrastructure using Vitest.

@paigewilliams
paigewilliams requested review from pollardld and rhodges and a balanced review from Copilot November 30, 2026 23:05
@paigewilliams paigewilliams self-assigned this Nov 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Search requests can overwrite newer category selections, Explore submissions duplicate requests and history entries, and Back navigation leaves the input and results out of sync with the URL.

3 open issues
1 file not reviewed
  • client/package-lock.json: Generated file
What changed in this PR

This PR adds URL-backed search state to the React client, allowing links to preserve submitted queries and selected category filters as part of the React migration.

Changes:

  • Reads and writes query and category state through URL parameters.
  • Runs searches when the results route mounts and returns no results for an empty category selection.
  • Introduces Vitest, Testing Library, and search-context tests.
File Description
client/​vitest.config.ts Configures jsdom tests separately from the React Router build setup.
client/​tests/​searchContext.test.tsx Tests URL state, category selection, search submission, and failures.
client/​package.json Adds test scripts and testing dependencies.
client/​package-lock.json Locks the new testing dependencies and related updates.
client/​app/​routes/​search.tsx Executes a search when the results route mounts.
client/​app/​context/​searchContext.tsx Adds URL-backed filters, query persistence, and empty-selection handling.

Review effort: Balanced

Comment on lines +88 to +92
const handleSearch = useCallback(
async (categoriesToSearch: FilterCategories[] = categories) => {
try {
const results = await fetchResults(categoriesToSearch, query);
setResults(results);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really think this is necessary. I don't think that we are going to have too many requests while others are pending. I'm hoping the API is fast enough to prevent this.

Comment on lines +165 to +168
useEffect(() => {
// execute search on initial load
handleSearch();
}, []);
Comment on lines +66 to +69
const [query, setQuery] = useState<string>(
() => searchParams.get(FILTER_PARAM) ?? "",
);
const searchedQuery = searchParams.get(FILTER_PARAM) ?? ""; // the executed searched query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants