Skip to content
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

fix(KFLUXUI-312): add useSearchParamBatch hook for batch params operations #107

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

marcin-michal
Copy link
Contributor

Fixes

KFLUXUI-312

Description

Hook for batch search params operation, fixes the issue where if multiple params were set separately only one of the operation had effect. Will be used in components in this PR

Type of change

  • Bugfix

Screen shots / Gifs for design review

How to test or reproduce?

Browser conformance:

  • Chrome
  • Firefox
  • Safari
  • Edge

Copy link

codecov bot commented Feb 7, 2025

Codecov Report

Attention: Patch coverage is 95.23810% with 2 lines in your changes missing coverage. Please review.

Project coverage is 80.08%. Comparing base (93f0fc3) to head (6330e7d).

Files with missing lines Patch % Lines
src/hooks/useSearchParam.ts 95.23% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #107      +/-   ##
==========================================
+ Coverage   80.06%   80.08%   +0.02%     
==========================================
  Files         544      544              
  Lines       21155    21195      +40     
  Branches     5326     5335       +9     
==========================================
+ Hits        16937    16975      +38     
- Misses       4194     4195       +1     
- Partials       24       25       +1     
Flag Coverage Δ
unittests 80.08% <95.23%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/hooks/useSearchParam.ts 97.05% <95.23%> (-2.95%) ⬇️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93f0fc3...6330e7d. Read the comment docs.

Comment on lines 57 to 59
(names?: string[]) => {
const result: Record<string, string> = {};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
(names?: string[]) => {
const result: Record<string, string> = {};
(names?: string[]) => {
If (name === undefined) return Object.fromEntries(searchParams);
if (typeof name === 'string') return searchParams.get(name);
const result: Record<string, string> = {};

src/hooks/useSearchParam.ts Outdated Show resolved Hide resolved
);

const batchUnset = React.useCallback(
(names?: string[]) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
(names?: string[]) => {
(names: string[]) => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since adding a set of managed params, I think it makes sense to keep the option to unset all the params without specifying them. Only the managed ones will be deleted

src/hooks/useSearchParam.ts Outdated Show resolved Hide resolved
@@ -45,3 +45,54 @@ export const useSearchParam = (

return [value, set, unset];
};

export const useSearchParamBatch = (): [
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we allow passing a set of keys that the hook should manage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that makes sense. I added it in the latest commit

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