Skip to content

Commit a916ed4

Browse files
authored
feat: Add bundle cache modal to bundles tab (#3653)
1 parent 12d8acb commit a916ed4

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

src/pages/RepoPage/BundlesTab/BundleContent/BundleSelection/BundleSelection.test.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ import { userEvent } from '@testing-library/user-event'
88
import { graphql, HttpResponse } from 'msw'
99
import { setupServer } from 'msw/node'
1010
import { Suspense } from 'react'
11+
import { Toaster } from 'react-hot-toast'
1112
import { MemoryRouter, Route } from 'react-router-dom'
1213

1314
import BundleSelection from './BundleSelection'
1415

16+
const mocks = vi.hoisted(() => ({
17+
useFlags: vi.fn().mockReturnValue({ displayBundleCachingModal: true }),
18+
}))
19+
20+
vi.mock('shared/featureFlags', () => ({
21+
useFlags: mocks.useFlags,
22+
}))
23+
1524
const mockRepoOverview = {
1625
__typename: 'Repository',
1726
private: false,
@@ -61,6 +70,27 @@ const mockBranchBundles = {
6170
},
6271
}
6372

73+
const mockCachedBundles = {
74+
owner: {
75+
repository: {
76+
__typename: 'Repository',
77+
branch: {
78+
head: {
79+
bundleAnalysis: {
80+
bundleAnalysisReport: {
81+
__typename: 'BundleAnalysisReport',
82+
bundles: [
83+
{ name: 'bundle1', isCached: true },
84+
{ name: 'bundle2', isCached: false },
85+
],
86+
},
87+
},
88+
},
89+
},
90+
},
91+
},
92+
}
93+
6494
const server = setupServer()
6595
const queryClient = new QueryClient({
6696
defaultOptions: { queries: { retry: false, suspense: true } },
@@ -85,6 +115,7 @@ const wrapper =
85115
]}
86116
>
87117
<Suspense fallback={<p>Loading</p>}>{children}</Suspense>
118+
<Toaster />
88119
</Route>
89120
</MemoryRouter>
90121
</QueryClientProvider>
@@ -136,6 +167,9 @@ describe('BundleSelection', () => {
136167
}),
137168
graphql.query('BranchBundlesNames', () => {
138169
return HttpResponse.json({ data: mockBranchBundles })
170+
}),
171+
graphql.query('CachedBundleList', () => {
172+
return HttpResponse.json({ data: mockCachedBundles })
139173
})
140174
)
141175

@@ -182,6 +216,16 @@ describe('BundleSelection', () => {
182216
expect(loadSelector).toBeInTheDocument()
183217
})
184218

219+
it('renders bundle caching button', async () => {
220+
setup()
221+
render(<BundleSelection />, { wrapper: wrapper() })
222+
223+
const bundleCachingButton = await screen.findByRole('button', {
224+
name: 'Configure data caching',
225+
})
226+
expect(bundleCachingButton).toBeInTheDocument()
227+
})
228+
185229
describe('user interacts with branch and bundle selectors', () => {
186230
describe('user selects a branch', () => {
187231
it('resets the bundle selector to the first available bundle', async () => {
@@ -277,4 +321,21 @@ describe('BundleSelection', () => {
277321
})
278322
})
279323
})
324+
325+
describe('user clicks bundle caching button', () => {
326+
it('renders bundle caching modal', async () => {
327+
const { user } = setup()
328+
render(<BundleSelection />, { wrapper: wrapper() })
329+
330+
const bundleCachingButton = await screen.findByRole('button', {
331+
name: 'Configure data caching',
332+
})
333+
await user.click(bundleCachingButton)
334+
335+
const modalHeader = await screen.findByText(
336+
'Configure bundle caching data'
337+
)
338+
expect(modalHeader).toBeInTheDocument()
339+
})
340+
})
280341
})

src/pages/RepoPage/BundlesTab/BundleContent/BundleSelection/BundleSelection.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { lazy, useCallback, useRef } from 'react'
1+
import { lazy, useCallback, useRef, useState } from 'react'
2+
3+
import { ConfigureCachedBundleModal } from 'pages/RepoPage/shared/ConfigureCachedBundleModal/ConfigureCachedBundleModal'
4+
import { useFlags } from 'shared/featureFlags'
5+
import Icon from 'ui/Icon'
26

37
import BranchSelector from './BranchSelector'
48
import { LoadSelector } from './LoadSelector'
@@ -10,6 +14,12 @@ const BundleSelection: React.FC = () => {
1014
const typesSelectRef = useRef<{ resetSelected: () => void }>(null)
1115
const loadingSelectRef = useRef<{ resetSelected: () => void }>(null)
1216

17+
const [showBundleCachingModal, setShowBundleCachingModal] = useState(false)
18+
19+
const { displayBundleCachingModal } = useFlags({
20+
displayBundleCachingModal: false,
21+
})
22+
1323
const resetFilterSelects = useCallback(() => {
1424
typesSelectRef.current?.resetSelected()
1525
loadingSelectRef?.current?.resetSelected()
@@ -30,6 +40,21 @@ const BundleSelection: React.FC = () => {
3040
/>
3141
<TypeSelector ref={typesSelectRef} />
3242
<LoadSelector ref={loadingSelectRef} />
43+
{displayBundleCachingModal ? (
44+
<div className="flex w-full justify-end self-start md:w-auto">
45+
<button
46+
onClick={() => setShowBundleCachingModal(true)}
47+
className="flex items-center gap-0.5 text-xs font-semibold text-ds-blue-darker hover:cursor-pointer hover:underline"
48+
>
49+
<Icon name="cog" size="sm" variant="outline" />
50+
Configure data caching
51+
</button>
52+
<ConfigureCachedBundleModal
53+
isOpen={showBundleCachingModal}
54+
setIsOpen={setShowBundleCachingModal}
55+
/>
56+
</div>
57+
) : null}
3358
</div>
3459
</div>
3560
)

src/pages/RepoPage/shared/ConfigureCachedBundleModal/ConfigureCachedBundleModal.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('ConfigureCachedBundleModal', () => {
177177
expect(alertDescription).toBeInTheDocument()
178178

179179
const alertDescription2 = await screen.findByText(
180-
'Note, if caching is removed trend data will not be available.'
180+
'Note, if caching is removed, trend data will not be available.'
181181
)
182182
expect(alertDescription2).toBeInTheDocument()
183183

src/pages/RepoPage/shared/ConfigureCachedBundleModal/ConfigureCachedBundleModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const BundleCachingModalBody: React.FC<BundleCachingModalBodyProps> = ({
153153
</Alert.Description>
154154
<br />
155155
<Alert.Description>
156-
Note, if caching is removed trend data will not be available.
156+
Note, if caching is removed, trend data will not be available.
157157
</Alert.Description>
158158
</Alert>
159159
{isBundlesPending ? (

0 commit comments

Comments
 (0)