Skip to content

feat: add reset ability for selectors #93923

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 7 commits into from
Jun 25, 2025

Conversation

adrianviquez
Copy link
Contributor

This PR adds the ability to reset state for Codecov selectors based on the selector you choose. This is directly implemented in the repository selector as a POC.

Notes

  • Added the handleReset function in the codecov context. This mainly deletes query params and local storage data for an array of values to be deleted.
  • Adjusted context file to use useSearchParams and get rid of useLocation, as well as expose the handleReset fn
  • Implemented reset functionality on the repository selector
    • Took the opportunity to refactor the picker + selector components into 1

@adrianviquez adrianviquez requested a review from a team as a code owner June 19, 2025 21:01
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jun 19, 2025
};

for (const [key, value] of Object.entries(validEntries)) {
if (!value || typeof value !== 'string') {
delete validEntries[key as keyof CodecovContextData];
delete validEntries[key as keyof Omit<CodecovContextData, 'handleReset'>];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the same as CodecovContextDataParams?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, will change

}, [setLocalStorageState, location.query]);
}, [setLocalStorageState, searchParams]);

const changeContextValue = useCallback(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the chunk of the PR. Basically updates the URL + storage if there are values to reset

: 'codecovPeriod' in localStorageState
? (localStorageState.codecovPeriod as CodecovPeriodOptions)
: '24h',
...(typeof queryRepository === '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.

This is a reflection of updating the types originally. I had them like

branch: string | null

Implying the key was always present in local storage, with string or null, but that isn't true. We either have the key or not, and if we have the key, it has a string, never a null, so updated the type to have optional keys with string, such as branch?: string

Comment on lines 58 to 60
for (const key of valuesToReset) {
delete currentParams[key];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on standardizing this function with line 64-66? Seems it's doing the same thing but for different objects. I think it's fine to keep them separated out since the function of setLocalStorageState should be focused on returning the new localStorage state.

Copy link
Contributor

@calvin-codecov calvin-codecov Jun 25, 2025

Choose a reason for hiding this comment

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

We can't use the same value of currentParams instead of newState inside the function below right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nvm about the second comment above. And the first one is just a nit for making the for loops the same (both being the earlier for version or the later forEach version)

@adrianviquez adrianviquez merged commit 74a3272 into master Jun 25, 2025
45 checks passed
@adrianviquez adrianviquez deleted the adrian/add-reset-to-codecov-selectors branch June 25, 2025 19:28
adrianviquez added a commit that referenced this pull request Jun 25, 2025
This PR continues the work on
#93923 and adds the reset
capabilities to the org and branch selectors. It additionally deletes
the DatePicker and only leaves the DateSelector component.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants