-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Conversation
}; | ||
|
||
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'>]; |
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.
Is this the same as CodecovContextDataParams?
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.
Yep, will change
}, [setLocalStorageState, location.query]); | ||
}, [setLocalStorageState, searchParams]); | ||
|
||
const changeContextValue = useCallback( |
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.
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' |
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.
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
for (const key of valuesToReset) { | ||
delete currentParams[key]; | ||
} |
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.
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.
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.
We can't use the same value of currentParams
instead of newState
inside the function below right?
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.
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)
…-codecov-selectors
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.
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
handleReset
function in the codecov context. This mainly deletes query params and local storage data for an array of values to be deleted.useSearchParams
and get rid ofuseLocation
, as well as expose thehandleReset
fn