Skip to content

Commit d10542e

Browse files
committed
feat: respect settings for showing also in overview table
Signed-off-by: Dominikus Hellgartner <dominikus.hellgartner@tngtech.com>
1 parent 25861ef commit d10542e

File tree

4 files changed

+154
-18
lines changed

4 files changed

+154
-18
lines changed

src/Frontend/Components/AttributionCountPerSourcePerLicenseTable/AttributionCountPerSourcePerLicenseTable.tsx

+49-17
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ import MuiTable from '@mui/material/Table';
77
import MuiTableBody from '@mui/material/TableBody';
88
import MuiTableContainer from '@mui/material/TableContainer';
99
import { orderBy, upperFirst } from 'lodash';
10-
import { useMemo, useState } from 'react';
10+
import { useCallback, useMemo, useState } from 'react';
1111

1212
import { text } from '../../../shared/text';
13+
import { useShowClassifications } from '../../state/variables/use-show-classifications';
14+
import { useShowCriticality } from '../../state/variables/use-show-criticality';
1315
import {
1416
LicenseCounts,
1517
LicenseNamesWithClassification,
1618
LicenseNamesWithCriticality,
1719
} from '../../types/types';
1820
import { Order } from '../TableCellWithSorting/TableCellWithSorting';
1921
import {
22+
Column,
2023
ColumnConfig,
2124
orderLicenseNames,
2225
SingleColumn,
@@ -32,7 +35,7 @@ const classes = {
3235
},
3336
};
3437

35-
interface AttributionCountPerSourcePerLicenseTableProps {
38+
export interface AttributionCountPerSourcePerLicenseTableProps {
3639
licenseCounts: LicenseCounts;
3740
licenseNamesWithCriticality: LicenseNamesWithCriticality;
3841
licenseNamesWithClassification: LicenseNamesWithClassification;
@@ -47,6 +50,39 @@ export const AttributionCountPerSourcePerLicenseTable: React.FC<
4750
props.licenseCounts.totalAttributionsPerSource,
4851
);
4952

53+
const showCriticality = useShowCriticality();
54+
const showClassifications = useShowClassifications();
55+
56+
const getCriticalityColumn = useCallback((): Array<Column> => {
57+
if (showCriticality) {
58+
return [
59+
{
60+
columnName: componentText.columns.criticality.title,
61+
columnType: SingleColumn.CRITICALITY,
62+
columnId: SingleColumn.CRITICALITY,
63+
align: 'center',
64+
defaultOrder: 'desc',
65+
},
66+
];
67+
}
68+
return [];
69+
}, [componentText.columns.criticality.title, showCriticality]);
70+
71+
const getClassificationColumn = useCallback((): Array<Column> => {
72+
if (showClassifications) {
73+
return [
74+
{
75+
columnName: componentText.columns.classification,
76+
columnType: SingleColumn.CLASSIFICATION,
77+
columnId: SingleColumn.CLASSIFICATION,
78+
align: 'center',
79+
defaultOrder: 'desc',
80+
},
81+
];
82+
}
83+
return [];
84+
}, [componentText.columns.classification, showClassifications]);
85+
5086
const columnConfig: ColumnConfig = useMemo(
5187
() =>
5288
new ColumnConfig([
@@ -60,20 +96,8 @@ export const AttributionCountPerSourcePerLicenseTable: React.FC<
6096
align: 'left',
6197
defaultOrder: 'asc',
6298
},
63-
{
64-
columnName: componentText.columns.criticality.title,
65-
columnType: SingleColumn.CRITICALITY,
66-
columnId: SingleColumn.CRITICALITY,
67-
align: 'center',
68-
defaultOrder: 'desc',
69-
},
70-
{
71-
columnName: componentText.columns.classification,
72-
columnType: SingleColumn.CLASSIFICATION,
73-
columnId: SingleColumn.CLASSIFICATION,
74-
align: 'center',
75-
defaultOrder: 'desc',
76-
},
99+
...getCriticalityColumn(),
100+
...getClassificationColumn(),
77101
],
78102
},
79103
{
@@ -96,7 +120,15 @@ export const AttributionCountPerSourcePerLicenseTable: React.FC<
96120
],
97121
},
98122
]),
99-
[sourceNames, componentText],
123+
[
124+
componentText.columns.licenseInfo,
125+
componentText.columns.licenseName,
126+
componentText.columns.classification,
127+
componentText.columns.signalCountPerSource,
128+
componentText.columns.totalSources,
129+
getCriticalityColumn,
130+
sourceNames,
131+
],
100132
);
101133

102134
const [ordering, setOrdering] = useState<TableOrdering>({

src/Frontend/Components/AttributionCountPerSourcePerLicenseTable/AttributionCountPerSourcePerLicenseTableHead/AttributionCountPerSourcePerLicenseTableHead.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export const AttributionCountPerSourcePerLicenseTableHead: React.FC<
3636
AttributionCountPerSourcePerLicenseTableHeadProps
3737
> = (props) => {
3838
return (
39-
<MuiTableHead sx={{ position: 'sticky', top: 0 }}>
39+
<MuiTableHead
40+
sx={{ position: 'sticky', top: 0 }}
41+
data-testid={'license-table-header'}
42+
>
4043
<MuiTableRow>
4144
{props.columnConfig.groups.map((columnGroup, idx) => {
4245
return (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 { screen } from '@testing-library/react';
6+
7+
import { Criticality } from '../../../../shared/shared-types';
8+
import { setUserSetting } from '../../../state/actions/user-settings-actions/user-settings-actions';
9+
import { renderComponent } from '../../../test-helpers/render';
10+
import { LicenseCounts } from '../../../types/types';
11+
import {
12+
AttributionCountPerSourcePerLicenseTable,
13+
AttributionCountPerSourcePerLicenseTableProps,
14+
} from '../AttributionCountPerSourcePerLicenseTable';
15+
16+
const licenseCounts: LicenseCounts = {
17+
attributionCountPerSourcePerLicense: {
18+
licenseA: {
19+
sourceA: 1,
20+
sourceB: 3,
21+
},
22+
licenseB: {
23+
sourceB: 2,
24+
},
25+
},
26+
totalAttributionsPerLicense: {
27+
licenseA: 4,
28+
licenseB: 2,
29+
},
30+
totalAttributionsPerSource: {
31+
sourceA: 1,
32+
sourceB: 5,
33+
},
34+
};
35+
const props: AttributionCountPerSourcePerLicenseTableProps = {
36+
licenseCounts,
37+
licenseNamesWithCriticality: {
38+
licenseA: Criticality.High,
39+
licenseB: Criticality.Medium,
40+
},
41+
licenseNamesWithClassification: {
42+
licenseA: 2,
43+
licenseB: 3,
44+
},
45+
};
46+
47+
describe('Attribution count per source per license table', () => {
48+
it('shows by default criticality and classification columns', () => {
49+
renderComponent(<AttributionCountPerSourcePerLicenseTable {...props} />);
50+
51+
const headerTexts = screen
52+
.getAllByTestId('classification-table-row-header')
53+
.map((node) => node.textContent);
54+
55+
expect(headerTexts).toEqual([
56+
'Namesorted ascending', //correct, the sorted, ascending is for a11y
57+
'Criticality',
58+
'Classification',
59+
'SourceA',
60+
'SourceB',
61+
'Total',
62+
]);
63+
});
64+
65+
it('does not show criticality if disabled', () => {
66+
renderComponent(<AttributionCountPerSourcePerLicenseTable {...props} />, {
67+
actions: [setUserSetting({ showCriticality: false })],
68+
});
69+
70+
const headerTexts = screen
71+
.getAllByTestId('classification-table-row-header')
72+
.map((node) => node.textContent);
73+
74+
expect(headerTexts).toEqual([
75+
'Namesorted ascending', //correct, the sorted, ascending is for a11y
76+
'Classification',
77+
'SourceA',
78+
'SourceB',
79+
'Total',
80+
]);
81+
});
82+
83+
it('does not show classification if disabled', () => {
84+
renderComponent(<AttributionCountPerSourcePerLicenseTable {...props} />, {
85+
actions: [setUserSetting({ showClassifications: false })],
86+
});
87+
88+
const headerTexts = screen
89+
.getAllByTestId('classification-table-row-header')
90+
.map((node) => node.textContent);
91+
92+
expect(headerTexts).toEqual([
93+
'Namesorted ascending', //correct, the sorted, ascending is for a11y
94+
'Criticality',
95+
'SourceA',
96+
'SourceB',
97+
'Total',
98+
]);
99+
});
100+
});

src/Frontend/Components/TableCellWithSorting/TableCellWithSorting.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const TableCellWithSorting: React.FC<TableCellWithSortingProps> = (
3232
...props.sx,
3333
}}
3434
sortDirection={props.isSortedColumn ? props.order : false}
35+
data-testid="classification-table-row-header"
3536
>
3637
<TableSortLabel
3738
sx={{

0 commit comments

Comments
 (0)