From 148802cbb59722d48347f09ff7351dc747f272a6 Mon Sep 17 00:00:00 2001 From: Roberto Jimenez Sanchez Date: Wed, 17 Dec 2025 15:55:16 +0100 Subject: [PATCH] fix: update BootstrapStep component to remove legacy storage handling and adjust resource counting logic - Removed legacy storage flag from useResourceStats hook in BootstrapStep. - Updated BootstrapStepResourceCounting to simplify rendering logic and removed target prop. - Adjusted tests to reflect changes in resource counting and rendering behavior. --- .../Wizard/BootstrapStep.test.tsx | 55 ++----------------- .../provisioning/Wizard/BootstrapStep.tsx | 3 +- .../Wizard/BootstrapStepResourceCounting.tsx | 35 +++--------- 3 files changed, 15 insertions(+), 78 deletions(-) diff --git a/public/app/features/provisioning/Wizard/BootstrapStep.test.tsx b/public/app/features/provisioning/Wizard/BootstrapStep.test.tsx index ef16124895c..f9c6c4cb009 100644 --- a/public/app/features/provisioning/Wizard/BootstrapStep.test.tsx +++ b/public/app/features/provisioning/Wizard/BootstrapStep.test.tsx @@ -143,7 +143,7 @@ describe('BootstrapStep', () => { it('should render correct info for GitHub repository type', async () => { setup(); expect(screen.getAllByText('External storage')).toHaveLength(2); - expect(screen.getAllByText('Empty')).toHaveLength(3); // Three elements should have the role "Empty" (2 external + 1 unmanaged) + expect(screen.getAllByText('Empty')).toHaveLength(4); // Four elements should have the role "Empty" (2 external + 2 unmanaged - one for each sync option card) }); it('should render correct info for local file repository type', async () => { @@ -198,7 +198,9 @@ describe('BootstrapStep', () => { setup(); - expect(await screen.findByText('7 resources')).toBeInTheDocument(); + // The resource count string appears twice because BootstrapStepResourceCounting is rendered + // for each enabled sync option (instance and folder), and both show the resource count + expect(await screen.findAllByText('7 resources')).toHaveLength(2); }); }); @@ -207,21 +209,7 @@ describe('BootstrapStep', () => { setup(); const mockUseResourceStats = require('./hooks/useResourceStats').useResourceStats; - expect(mockUseResourceStats).toHaveBeenCalledWith('test-repo', undefined); - }); - - it('should use useResourceStats hook with legacy storage flag', async () => { - setup({ - settingsData: { - legacyStorage: true, - allowImageRendering: true, - items: [], - availableRepositoryTypes: [], - }, - }); - - const mockUseResourceStats = require('./hooks/useResourceStats').useResourceStats; - expect(mockUseResourceStats).toHaveBeenCalledWith('test-repo', true); + expect(mockUseResourceStats).toHaveBeenCalledWith('test-repo'); }); }); @@ -233,39 +221,6 @@ describe('BootstrapStep', () => { expect(await screen.findByText('Sync external storage to a new Grafana folder')).toBeInTheDocument(); }); - it('should only display instance option when legacy storage exists', async () => { - (useModeOptions as jest.Mock).mockReturnValue({ - enabledOptions: [ - { - target: 'instance', - label: 'Sync all resources with external storage', - description: 'Resources will be synced with external storage', - subtitle: 'Use this option if you want to sync your entire instance', - }, - ], - disabledOptions: [ - { - target: 'folder', - label: 'Sync external storage to a new Grafana folder', - description: 'A new Grafana folder will be created', - subtitle: 'Use this option to sync into a new folder', - }, - ], - }); - - setup({ - settingsData: { - legacyStorage: true, - allowImageRendering: true, - items: [], - availableRepositoryTypes: [], - }, - }); - - expect(await screen.findByText('Sync all resources with external storage')).toBeInTheDocument(); - expect(await screen.findByText('Sync external storage to a new Grafana folder')).not.toBeChecked(); - }); - it('should allow selecting different sync targets', async () => { const { user } = setup(); diff --git a/public/app/features/provisioning/Wizard/BootstrapStep.tsx b/public/app/features/provisioning/Wizard/BootstrapStep.tsx index 1dafe14c709..939568c39a2 100644 --- a/public/app/features/provisioning/Wizard/BootstrapStep.tsx +++ b/public/app/features/provisioning/Wizard/BootstrapStep.tsx @@ -37,7 +37,7 @@ export const BootstrapStep = memo(function BootstrapStep({ settingsData, repoNam const repositoryType = watch('repository.type'); const { enabledOptions, disabledOptions } = useModeOptions(repoName, settingsData); const { target } = enabledOptions?.[0]; - const { resourceCountString, fileCountString, isLoading } = useResourceStats(repoName, settingsData?.legacyStorage); + const { resourceCountString, fileCountString, isLoading } = useResourceStats(repoName); const styles = useStyles2(getStyles); useEffect(() => { @@ -103,7 +103,6 @@ export const BootstrapStep = memo(function BootstrapStep({ settingsData, repoNam
diff --git a/public/app/features/provisioning/Wizard/BootstrapStepResourceCounting.tsx b/public/app/features/provisioning/Wizard/BootstrapStepResourceCounting.tsx index 1c5f0f16d4f..ade52354935 100644 --- a/public/app/features/provisioning/Wizard/BootstrapStepResourceCounting.tsx +++ b/public/app/features/provisioning/Wizard/BootstrapStepResourceCounting.tsx @@ -1,40 +1,23 @@ import { Trans } from '@grafana/i18n'; import { Stack, Text } from '@grafana/ui'; -import { Target } from './types'; - export function BootstrapStepResourceCounting({ - target, fileCountString, resourceCountString, }: { - target: Target; fileCountString: string; resourceCountString: string; }) { - if (target === 'instance') { - return ( - - - External storage - {fileCountString} - - - Unmanaged resources{' '} - {resourceCountString} - - - ); - } - - if (target === 'folder') { - return ( + return ( + - External storage{' '} + External storage {fileCountString} - ); - } - - return null; + + Unmanaged resources{' '} + {resourceCountString} + + + ); }