Skip to content

Commit

Permalink
feat: add classification column to signals per sources table in proje…
Browse files Browse the repository at this point in the history
…ct statistics popup
  • Loading branch information
PhilippMa committed Feb 26, 2025
1 parent 2c65cf4 commit 06674aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import MuiTypography from '@mui/material/Typography';
import { Criticality } from '../../../shared/shared-types';
import { text } from '../../../shared/text';
import { OpossumColors, tableClasses } from '../../shared-styles';
import { LicenseCounts, LicenseNamesWithCriticality } from '../../types/types';
import { useAppSelector } from '../../state/hooks';
import { getClassifications } from '../../state/selectors/resource-selectors';
import {
LicenseCounts,
LicenseNamesWithClassification,
LicenseNamesWithCriticality,
} from '../../types/types';

const classes = {
container: {
Expand All @@ -29,12 +35,15 @@ const TOTAL_SOURCE_NAME = 'Total';
interface AttributionCountPerSourcePerLicenseTableProps {
licenseCounts: LicenseCounts;
licenseNamesWithCriticality: LicenseNamesWithCriticality;
licenseNamesWithClassification: LicenseNamesWithClassification;
title: string;
}

export const AttributionCountPerSourcePerLicenseTable: React.FC<
AttributionCountPerSourcePerLicenseTableProps
> = (props) => {
const classifications = useAppSelector(getClassifications);

const sourceNames = Object.keys(
props.licenseCounts.totalAttributionsPerSource,
);
Expand All @@ -51,13 +60,15 @@ export const AttributionCountPerSourcePerLicenseTable: React.FC<
const footerRow = [
text.attributionCountPerSourcePerLicenseTable.footerTitle,
'',
'',
...totalNumberOfAttributionsPerSource,
totalNumberOfAttributions,
];

const headerRow = [
text.attributionCountPerSourcePerLicenseTable.columnNames.licenseName,
text.attributionCountPerSourcePerLicenseTable.columnNames.criticality,
text.attributionCountPerSourcePerLicenseTable.columnNames.classification,
...sourceNames,
text.attributionCountPerSourcePerLicenseTable.columnNames.totalSources,
].map(
Expand Down Expand Up @@ -122,6 +133,25 @@ export const AttributionCountPerSourcePerLicenseTable: React.FC<
</MuiTableCell>
);

const licenseClassification =
props.licenseNamesWithClassification[licenseName];

const classificationCell = (
<MuiTableCell
sx={{
...tableClasses.body,
}}
key={1}
align={'center'}
>
<span>
{licenseClassification
? (classifications[licenseClassification] ?? '-')
: '-'}
</span>
</MuiTableCell>
);

const buildCountBySourceCell =
(columnOffset: number) => (sourceName: string, sourceIdx: number) => {
const columnIndex = columnOffset + sourceIdx;
Expand All @@ -141,7 +171,7 @@ export const AttributionCountPerSourcePerLicenseTable: React.FC<
);
};

const singleCells = [licenseNameCell, criticalityCell];
const singleCells = [licenseNameCell, criticalityCell, classificationCell];

return (
<MuiTableRow key={rowIndex}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const ProjectStatisticsPopup: React.FC = () => {
<AttributionCountPerSourcePerLicenseTable
licenseCounts={licenseCounts}
licenseNamesWithCriticality={licenseNamesWithCriticality}
licenseNamesWithClassification={licenseNamesWithClassification}
title={text.projectStatisticsPopup.charts.licenseCountsTable}
/>
</>
Expand Down
1 change: 1 addition & 0 deletions src/shared/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export const text = {
columnNames: {
licenseName: 'License Name',
criticality: 'Criticality',
classification: 'Classification',
totalSources: 'Total',
},
},
Expand Down

0 comments on commit 06674aa

Please sign in to comment.