Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 43f585f

Browse files
committedMar 14, 2025··
feat: do not show criticality statistics if disabled
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
1 parent 467b62f commit 43f585f

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed
 

‎src/Frontend/Components/ProjectStatisticsPopup/ProjectStatisticsPopup.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
getUnresolvedExternalAttributions,
2323
} from '../../state/selectors/resource-selectors';
2424
import { useShowClassifications } from '../../state/variables/use-show-classifications';
25+
import { useShowCriticality } from '../../state/variables/use-show-criticality';
2526
import { useUserSetting } from '../../state/variables/use-user-setting';
2627
import { AttributionCountPerSourcePerLicenseTable } from '../AttributionCountPerSourcePerLicenseTable/AttributionCountPerSourcePerLicenseTable';
2728
import { BarChart } from '../BarChart/BarChart';
@@ -94,6 +95,7 @@ export const ProjectStatisticsPopup: React.FC = () => {
9495
const [selectedTab, setSelectedTab] = useState(0);
9596

9697
const [showClassifications] = useShowClassifications();
98+
const [showCriticality] = useShowCriticality();
9799

98100
return (
99101
<NotificationPopup
@@ -137,7 +139,9 @@ export const ProjectStatisticsPopup: React.FC = () => {
137139
<PieChart segments={mostFrequentLicenseCountData} />
138140
</ChartGridItem>
139141
<ChartGridItem
140-
shouldRender={criticalSignalsCount.length > 0}
142+
shouldRender={
143+
criticalSignalsCount.length > 0 && showCriticality
144+
}
141145
testId={'criticalSignalsCountPieChart'}
142146
>
143147
<MuiTypography variant="subtitle1">

‎src/Frontend/Components/ProjectStatisticsPopup/__tests__/ProjectStatisticsPopup.test.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Attributions, Criticality } from '../../../../shared/shared-types';
99
import { text } from '../../../../shared/text';
1010
import { loadFromFile } from '../../../state/actions/resource-actions/load-actions';
1111
import { SHOW_CLASSIFICATIONS_KEY } from '../../../state/variables/use-show-classifications';
12+
import { SHOW_CRITICALITY_KEY } from '../../../state/variables/use-show-criticality';
1213
import { getParsedInputFileEnrichedWithTestData } from '../../../test-helpers/general-test-helpers';
1314
import { renderComponent } from '../../../test-helpers/render';
1415
import { setUserSetting } from '../../../test-helpers/user-settings-helpers';
@@ -319,6 +320,21 @@ describe('The ProjectStatisticsPopup', () => {
319320
).not.toBeInTheDocument();
320321
});
321322

323+
it('does not show the criticality statistics if it has been disabled', () => {
324+
renderComponent(<ProjectStatisticsPopup />, {
325+
actions: [
326+
setUserSetting(SHOW_CRITICALITY_KEY, false),
327+
loadFromFile(getParsedInputFileEnrichedWithTestData(fileSetup)),
328+
],
329+
});
330+
331+
expect(
332+
screen.queryByText(
333+
text.projectStatisticsPopup.charts.criticalSignalsCountPieChart.title,
334+
),
335+
).not.toBeInTheDocument();
336+
});
337+
322338
it('allows toggling of show-on-startup checkbox', async () => {
323339
renderComponent(<ProjectStatisticsPopup />);
324340

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-FileCopyrightText: Meta Platforms, Inc. and its affiliates
2+
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com>
3+
//
4+
// SPDX-License-Identifier: Apache-2.0
5+
import { useUserSetting } from './use-user-setting';
6+
7+
export const SHOW_CRITICALITY_KEY = 'showCriticality';
8+
9+
export function useShowCriticality() {
10+
return useUserSetting({
11+
key: SHOW_CRITICALITY_KEY,
12+
defaultValue: true,
13+
});
14+
}

0 commit comments

Comments
 (0)
Please sign in to comment.