Skip to content

Commit 44b1bd8

Browse files
Meret BehrensFlorianSchepers
authored andcommitted
Fix marking of located signals
#2183 introduced the marking of signals with an icon if they match the filters from the LocatorPopup. If we have `frequentLicenses` in the file and search for a short name of a `frequentLicense` we also want to locate and mark the signals that have the corresponding full name as license name or the other way around. We marked the resources correctly for these cases but didn't mark the corresponding signal, this is fixed with this commit. Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
1 parent 6c4b55f commit 44b1bd8

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

src/Frontend/Components/PackageCard/PackageCard.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ButtonText, PopupType, View } from '../../enums/enums';
1515
import { useSelector } from 'react-redux';
1616
import {
1717
getAttributionIdMarkedForReplacement,
18+
getFrequentLicensesNameOrder,
1819
getManualAttributions,
1920
getManualAttributionsToResources,
2021
wereTemporaryDisplayPackageInfoModified,
@@ -136,6 +137,7 @@ export function PackageCard(props: PackageCardProps): ReactElement | null {
136137
? selectedAttributionIdAttributionView
137138
: selectedAttributionIdAuditView;
138139

140+
const frequentLicenseNames = useAppSelector(getFrequentLicensesNameOrder);
139141
function getListCardConfig(): ListCardConfig {
140142
let listCardConfig: ListCardConfig = {
141143
...props.cardConfig,
@@ -169,6 +171,7 @@ export function PackageCard(props: PackageCardProps): ReactElement | null {
169171
? attributionMatchesLocateFilter(
170172
props.displayPackageInfo,
171173
locatePopupFilter,
174+
frequentLicenseNames,
172175
)
173176
: false,
174177
};

src/Frontend/state/helpers/__tests__/action-and-reducer-helpers.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ describe('attributionMatchesLocatedFilters', () => {
616616
searchOnlyLicenseName: false,
617617
};
618618
expect(
619-
attributionMatchesLocateFilter(testPackageInfo, locatePopupFilter),
619+
attributionMatchesLocateFilter(testPackageInfo, locatePopupFilter, []),
620620
).toBeTruthy();
621621
});
622622

@@ -632,7 +632,7 @@ describe('attributionMatchesLocatedFilters', () => {
632632
searchOnlyLicenseName: false,
633633
};
634634
expect(
635-
attributionMatchesLocateFilter(testPackageInfo, locatePopupFilter),
635+
attributionMatchesLocateFilter(testPackageInfo, locatePopupFilter, []),
636636
).toBeFalsy();
637637
});
638638
it('is true if no filter selected', () => {
@@ -647,7 +647,25 @@ describe('attributionMatchesLocatedFilters', () => {
647647
searchOnlyLicenseName: false,
648648
};
649649
expect(
650-
attributionMatchesLocateFilter(testPackageInfo, locatePopupFilter),
650+
attributionMatchesLocateFilter(testPackageInfo, locatePopupFilter, []),
651+
).toBeTruthy();
652+
});
653+
654+
it('is true if the license matches a frequent license', () => {
655+
const testPackageInfo: PackageInfo = {
656+
criticality: Criticality.High,
657+
licenseName: 'MIT License',
658+
};
659+
const locatePopupFilter: LocatePopupFilters = {
660+
selectedCriticality: SelectedCriticality.Any,
661+
selectedLicenses: new Set(['MIT']),
662+
searchTerm: '',
663+
searchOnlyLicenseName: false,
664+
};
665+
expect(
666+
attributionMatchesLocateFilter(testPackageInfo, locatePopupFilter, [
667+
{ shortName: 'MIT', fullName: 'MIT License' },
668+
]),
651669
).toBeTruthy();
652670
});
653671
});

src/Frontend/state/helpers/action-and-reducer-helpers.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -291,26 +291,18 @@ export function calculateResourcesWithLocatedAttributions(
291291
externalAttributionsToResources: AttributionsToResources,
292292
frequentLicenseNames: Array<FrequentLicenseName>,
293293
): Set<string> {
294-
const augmentedLicenseNames = augmentFrequentLicenseNamesIfPresent(
295-
locatePopupFilters.selectedLicenses,
296-
frequentLicenseNames,
297-
);
298294
const locatedResources = new Set<string>();
299-
if (
300-
!anyLocateFilterIsSet({
301-
...locatePopupFilters,
302-
selectedLicenses: augmentedLicenseNames,
303-
})
304-
) {
295+
if (!anyLocateFilterIsSet(locatePopupFilters)) {
305296
return locatedResources;
306297
}
307298
for (const attributionId in externalAttributions) {
308299
const attribution = externalAttributions[attributionId];
309300
if (
310-
attributionMatchesLocateFilter(attribution, {
311-
...locatePopupFilters,
312-
selectedLicenses: augmentedLicenseNames,
313-
})
301+
attributionMatchesLocateFilter(
302+
attribution,
303+
locatePopupFilters,
304+
frequentLicenseNames,
305+
)
314306
) {
315307
externalAttributionsToResources[attributionId].forEach((resource) => {
316308
locatedResources.add(resource);
@@ -333,13 +325,18 @@ export function anyLocateFilterIsSet(
333325
export function attributionMatchesLocateFilter(
334326
attribution: PackageInfo,
335327
locatePopupFilter: LocatePopupFilters,
328+
frequentLicenseNames: Array<FrequentLicenseName>,
336329
): boolean {
337330
const licenseIsSet = locatePopupFilter.selectedLicenses.size > 0;
338331
const criticalityIsSet =
339332
locatePopupFilter.selectedCriticality != SelectedCriticality.Any;
333+
const augmentedLicenseNames = augmentFrequentLicenseNamesIfPresent(
334+
locatePopupFilter.selectedLicenses,
335+
frequentLicenseNames,
336+
);
340337
const licenseMatches =
341338
attribution.licenseName !== undefined &&
342-
locatePopupFilter.selectedLicenses.has(attribution.licenseName);
339+
augmentedLicenseNames.has(attribution.licenseName);
343340
const criticalityMatches =
344341
attribution.criticality == locatePopupFilter.selectedCriticality;
345342
const searchTermMatches =

0 commit comments

Comments
 (0)