Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add classification column to "Signals per Sources" table in project statistics popup #2819

Open
wants to merge 1 commit into
base: feat/move-criticality-display
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading