-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat: Create modal for controlling bundle cache settings #3652
feat: Create modal for controlling bundle cache settings #3652
Conversation
…ion input being toggleCaching not isCached
Bundle ReportBundle size has no change ✅ |
Bundle ReportChanges will increase total bundle size by 22 bytes (0.0%) ⬆️. This is within the configured threshold ✅ Detailed changes
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. @@ Coverage Diff @@
## main #3652 +/- ##
==========================================
+ Coverage 98.93% 98.94% +0.01%
==========================================
Files 814 815 +1
Lines 14612 14676 +64
Branches 4151 4156 +5
==========================================
+ Hits 14456 14521 +65
+ Misses 149 148 -1
Partials 7 7
... and 1 file with indirect coverage changes
Continue to review full report in Codecov by Sentry.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. @@ Coverage Diff @@
## main #3652 +/- ##
==========================================
+ Coverage 98.93% 98.94% +0.01%
==========================================
Files 814 815 +1
Lines 14612 14676 +64
Branches 4151 4156 +5
==========================================
+ Hits 14456 14521 +65
+ Misses 149 148 -1
Partials 7 7
... and 1 file with indirect coverage changes
Continue to review full report in Codecov by Sentry.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #3652 +/- ##
==========================================
+ Coverage 98.93% 98.94% +0.01%
==========================================
Files 814 815 +1
Lines 14612 14676 +64
Branches 4144 4156 +12
==========================================
+ Hits 14456 14521 +65
+ Misses 149 148 -1
Partials 7 7
... and 1 file with indirect coverage changes
Continue to review full report in Codecov by Sentry.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. @@ Coverage Diff @@
## main #3652 +/- ##
==========================================
+ Coverage 98.93% 98.94% +0.01%
==========================================
Files 814 815 +1
Lines 14612 14676 +64
Branches 4144 4156 +12
==========================================
+ Hits 14456 14521 +65
+ Misses 149 148 -1
Partials 7 7
... and 1 file with indirect coverage changes
Continue to review full report in Codecov by Sentry.
|
✅ Deploy preview for gazebo ready!Previews expire after 1 month automatically.
|
queryClientV5.setQueryData( | ||
CachedBundlesQueryOpts({ | ||
provider, | ||
owner, | ||
repo, | ||
branch: defaultBranch, | ||
}).queryKey, | ||
{ bundles } | ||
) |
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.
Instead of invalidating the query, this mutation returns the updated state so we can just update the query state removing an extra network request (a "single flight mutation")! However, just incase when the modal is re-opened the data will be refetched if the data is stale.
If you wanna learn more about "single flight mutations", you can watch this short video.
} | ||
|
||
return ( | ||
<Modal |
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.
I originally wanted to use a <form>
with react-hook-form
however because of the way our modal component is built at this point in time, i wasn't able to do this.
As our modal component isn't composable, and it uses portals, you can't wrap the Modal
component in a <form>
so that you can utilize react-hook-form
to control the inputs as it renders the content of the modal elsewhere in the DOM tree.
My work around to this, is to use simple plain old React state that is set with data returned from the API, and is updated when the user interacts with the form, and then the state is used when submitting the mutation.
|
||
const closeModal = () => { | ||
// this resets the state when the modal is closed | ||
setBundleState([]) |
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.
Just reseting the state if the user has been poking around with the toggles, but didn't save anything.
const { data: bundleData, isLoading: isBundlesLoading } = useQueryV5({ | ||
...CachedBundlesQueryOpts({ provider, owner, repo, branch: defaultBranch }), | ||
// we can use the select hook to transform the data to the format we want | ||
select: (data) => | ||
data.bundles.map((bundle) => ({ | ||
bundleName: bundle.bundleName, | ||
toggleCaching: bundle.isCached, | ||
})), |
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.
Thanks to the queryOptions
API setup, we can utilize select
like this and have all the correct types can be generated through inference 🥳
Unlike before, where we'd lose all type inference and would have to type things out manually and could end up being incorrect!
}) | ||
const defaultBranch = repoOverview?.defaultBranch ?? '' | ||
|
||
const { data: bundleData, isPending: isBundlesPending } = useQueryV5({ |
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're using isPending
here because of a change in TS Query V5, you can read about it here.
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.
TLDR: isLoading renamed to isPending
const { data: bundleData, isPending: isBundlesPending } = useQueryV5({ | ||
...CachedBundlesQueryOpts({ provider, owner, repo, branch: defaultBranch }), | ||
// we can use the select hook to transform the data to the format we want | ||
select: (data) => | ||
data.bundles.map((bundle) => ({ | ||
bundleName: bundle.bundleName, | ||
toggleCaching: bundle.isCached, | ||
})), | ||
enabled: isOpen && !!defaultBranch, | ||
}) |
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.
Thanks to the queryOptions
API, we're able to spread the details from it, and utilize the select
option so that we can pre-format the data from this hook AND still have all the types be generated through inference and be correct! 🥳
queryClientV5.setQueryData( | ||
CachedBundlesQueryOpts({ | ||
provider, | ||
owner, | ||
repo, | ||
branch: defaultBranch, | ||
}).queryKey, | ||
{ bundles } | ||
) |
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.
Instead of invalidating a query here, the GQL mutation we're using actually returns the updated state so we're able to leverage it and update the cache directly without an extra network request!
There is a relatively new term coined for this call "Single-Flight Mutations`, and if you want to learn a little bit more about them, here's a 30s YT short talking about them.
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.
couple comments to look at
src/pages/RepoPage/shared/ConfigureCachedBundleModal/ConfigureCachedBundleModal.tsx
Outdated
Show resolved
Hide resolved
}) | ||
const defaultBranch = repoOverview?.defaultBranch ?? '' | ||
|
||
const { data: bundleData, isPending: isBundlesPending } = useQueryV5({ |
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.
TLDR: isLoading renamed to isPending
src/pages/RepoPage/shared/ConfigureCachedBundleModal/ConfigureCachedBundleModal.tsx
Outdated
Show resolved
Hide resolved
src/pages/RepoPage/shared/ConfigureCachedBundleModal/ConfigureCachedBundleModal.tsx
Outdated
Show resolved
Hide resolved
src/pages/RepoPage/shared/ConfigureCachedBundleModal/ConfigureCachedBundleModal.tsx
Outdated
Show resolved
Hide resolved
src/pages/RepoPage/shared/ConfigureCachedBundleModal/ConfigureCachedBundleModal.tsx
Outdated
Show resolved
Hide resolved
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.
lgtm!
Description
This PR adds in a new modal, that will be used in codecov/engineering-team#3157 on the bundles and repo configuration pages so that users can control which bundles are being cached.
Closes codecov/engineering-team#3156
Note
This modal isn't currently being used in the UI, and will be added in future PRs.
Notable Changes
Screenshots
Light mode:
Dark mode: