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.
This commit is contained in:
Roberto Jimenez Sanchez
2025-12-17 15:55:16 +01:00
parent 9f139da063
commit 148802cbb5
3 changed files with 15 additions and 78 deletions
@@ -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();
@@ -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
<div className={styles.divider} />
<BootstrapStepResourceCounting
target={action.target}
fileCountString={fileCountString}
resourceCountString={resourceCountString}
/>
@@ -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 (
<Stack direction="row" gap={3}>
<Stack gap={1}>
<Trans i18nKey="provisioning.bootstrap-step.external-storage-label">External storage</Trans>
<Text color="primary">{fileCountString}</Text>
</Stack>
<Stack gap={1}>
<Trans i18nKey="provisioning.bootstrap-step.unmanaged-resources-label">Unmanaged resources</Trans>{' '}
<Text color="primary">{resourceCountString}</Text>
</Stack>
</Stack>
);
}
if (target === 'folder') {
return (
return (
<Stack direction="row" gap={3}>
<Stack gap={1}>
<Trans i18nKey="provisioning.bootstrap-step.external-storage-label">External storage</Trans>{' '}
<Trans i18nKey="provisioning.bootstrap-step.external-storage-label">External storage</Trans>
<Text color="primary">{fileCountString}</Text>
</Stack>
);
}
return null;
<Stack gap={1}>
<Trans i18nKey="provisioning.bootstrap-step.unmanaged-resources-label">Unmanaged resources</Trans>{' '}
<Text color="primary">{resourceCountString}</Text>
</Stack>
</Stack>
);
}