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

feat: Create modal for controlling bundle cache settings #3652

Conversation

nicholas-codecov
Copy link
Contributor

@nicholas-codecov nicholas-codecov commented Jan 13, 2025

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

  • Add in new modal that users can control which bundles are being cached
  • Slight tweaks to the mutation mutation
  • Add/Update tests

Screenshots

Light mode:

Screenshot 2025-01-13 at 09 33 11

Dark mode:

Screenshot 2025-01-13 at 09 33 54

@codecov-staging
Copy link

codecov-staging bot commented Jan 13, 2025

Bundle Report

Bundle size has no change ✅

Copy link

codecov bot commented Jan 13, 2025

Bundle Report

Changes will increase total bundle size by 22 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
gazebo-production-system 6.04MB 15 bytes (0.0%) ⬆️
gazebo-production-esm 6.09MB 7 bytes (0.0%) ⬆️

@codecov-notifications
Copy link

codecov-notifications bot commented Jan 13, 2025

Codecov Report

All 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              
Files with missing lines Coverage Δ
...reCachedBundleModal/ConfigureCachedBundleModal.tsx 100.00% <100.00%> (ø)
...c/services/bundleAnalysis/useUpdateBundleCache.tsx 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.71% <ø> (ø)
Pages 98.65% <100.00%> (+<0.01%) ⬆️
Services 99.34% <100.00%> (+<0.01%) ⬆️
Shared 99.37% <ø> (+0.06%) ⬆️
UI 99.14% <ø> (ø)

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 6807f02...703aee1. Read the comment docs.

Copy link

codecov-public-qa bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.94%. Comparing base (6807f02) to head (703aee1).
Report is 3 commits behind head on main.

✅ 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              
Files with missing lines Coverage Δ
...reCachedBundleModal/ConfigureCachedBundleModal.tsx 100.00% <100.00%> (ø)
...c/services/bundleAnalysis/useUpdateBundleCache.tsx 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.71% <ø> (ø)
Pages 98.65% <100.00%> (+<0.01%) ⬆️
Services 99.34% <100.00%> (+<0.01%) ⬆️
Shared 99.37% <ø> (+0.06%) ⬆️
UI 99.14% <ø> (ø)

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 6807f02...703aee1. Read the comment docs.

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.94%. Comparing base (6807f02) to head (703aee1).
Report is 3 commits behind head on main.

✅ 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              
Files with missing lines Coverage Δ
...reCachedBundleModal/ConfigureCachedBundleModal.tsx 100.00% <100.00%> (ø)
...c/services/bundleAnalysis/useUpdateBundleCache.tsx 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.71% <ø> (ø)
Pages 98.65% <100.00%> (+<0.01%) ⬆️
Services 99.34% <100.00%> (+<0.01%) ⬆️
Shared 99.37% <ø> (+0.06%) ⬆️
UI 99.14% <ø> (ø)

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 6807f02...703aee1. Read the comment docs.

@codecov-qa
Copy link

codecov-qa bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.94%. Comparing base (6807f02) to head (703aee1).
Report is 3 commits behind head on main.

✅ 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              
Files with missing lines Coverage Δ
...reCachedBundleModal/ConfigureCachedBundleModal.tsx 100.00% <100.00%> (ø)
...c/services/bundleAnalysis/useUpdateBundleCache.tsx 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (ø)
Layouts 99.71% <ø> (ø)
Pages 98.65% <100.00%> (+<0.01%) ⬆️
Services 99.34% <100.00%> (+<0.01%) ⬆️
Shared 99.37% <ø> (+0.06%) ⬆️
UI 99.14% <ø> (ø)

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 6807f02...703aee1. Read the comment docs.

@codecov-releaser
Copy link
Contributor

codecov-releaser commented Jan 13, 2025

✅ Deploy preview for gazebo ready!

Previews expire after 1 month automatically.

Storybook

Commit Created Cloud Enterprise
3bb16b4 Mon, 13 Jan 2025 13:37:23 GMT Expired Expired
4d238f4 Mon, 13 Jan 2025 14:19:49 GMT Expired Expired
b1ce75a Mon, 13 Jan 2025 14:49:49 GMT Expired Expired
7f26c1c Mon, 13 Jan 2025 17:48:34 GMT Expired Expired
703aee1 Tue, 14 Jan 2025 19:26:17 GMT Cloud Enterprise

Comment on lines 300 to 308
queryClientV5.setQueryData(
CachedBundlesQueryOpts({
provider,
owner,
repo,
branch: defaultBranch,
}).queryKey,
{ bundles }
)
Copy link
Contributor Author

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
Copy link
Contributor Author

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([])
Copy link
Contributor Author

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.

Comment on lines 204 to 211
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,
})),
Copy link
Contributor Author

@nicholas-codecov nicholas-codecov Jan 13, 2025

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({
Copy link
Contributor Author

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.

Copy link
Contributor

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

Comment on lines 205 to 214
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,
})
Copy link
Contributor Author

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! 🥳

Comment on lines 278 to 286
queryClientV5.setQueryData(
CachedBundlesQueryOpts({
provider,
owner,
repo,
branch: defaultBranch,
}).queryKey,
{ bundles }
)
Copy link
Contributor Author

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.

@nicholas-codecov nicholas-codecov marked this pull request as ready for review January 13, 2025 14:49
Copy link
Contributor

@ajay-sentry ajay-sentry left a 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

})
const defaultBranch = repoOverview?.defaultBranch ?? ''

const { data: bundleData, isPending: isBundlesPending } = useQueryV5({
Copy link
Contributor

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

Copy link
Contributor

@ajay-sentry ajay-sentry left a comment

Choose a reason for hiding this comment

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

lgtm!

@nicholas-codecov nicholas-codecov added this pull request to the merge queue Jan 14, 2025
Merged via the queue into main with commit 333b4e9 Jan 14, 2025
62 checks passed
@nicholas-codecov nicholas-codecov deleted the gh-eng-3156-create-modal-for-controlling-bundle-cache-settings branch January 14, 2025 19:28
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.

[UI] Create Modal for Controlling Bundle Cache Settings
4 participants