Skip to content

Commit 23fb842

Browse files
Merge remote-tracking branch 'remotes/origin/#446' into allfunctionality
2 parents 1274ab0 + 81f3533 commit 23fb842

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

js/components/preview/molecule/moleculeList.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -442,18 +442,26 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei
442442
handleFilterChange(newFilter);*/
443443
};
444444

445-
const changeButtonClassname = (givenList = []) => {
446-
if (joinedMoleculeLists.length === givenList.length) {
445+
const joinedGivenMatch = useCallback((givenList) => {
446+
return givenList.filter(element => joinedMoleculeLists.filter(element2 => element2.id === element).length > 0).length;
447+
}, [joinedMoleculeLists]);
448+
449+
const joinedLigandMatchLength = useMemo(() => joinedGivenMatch(fragmentDisplayList), [fragmentDisplayList, joinedGivenMatch]);
450+
const joinedProteinMatchLength = useMemo(() => joinedGivenMatch(proteinList), [proteinList, joinedGivenMatch]);
451+
const joinedComplexMatchLength = useMemo(() => joinedGivenMatch(complexList), [complexList, joinedGivenMatch]);
452+
453+
const changeButtonClassname = (givenList = [], matchListLength) => {
454+
if (joinedMoleculeLists.length === matchListLength) {
447455
return true;
448-
} else if (givenList.length > 0) {
456+
} else if (givenList.length > 0 && matchListLength > 0) {
449457
return null;
450458
}
451459
return false;
452460
};
453461

454-
const isLigandOn = changeButtonClassname(fragmentDisplayList);
455-
const isProteinOn = changeButtonClassname(proteinList);
456-
const isComplexOn = changeButtonClassname(complexList);
462+
const isLigandOn = changeButtonClassname(fragmentDisplayList, joinedLigandMatchLength);
463+
const isProteinOn = changeButtonClassname(proteinList, joinedProteinMatchLength);
464+
const isComplexOn = changeButtonClassname(complexList, joinedComplexMatchLength);
457465

458466
const addType = {
459467
ligand: addLigand,

0 commit comments

Comments
 (0)