Skip to content

Commit

Permalink
Search all molecules
Browse files Browse the repository at this point in the history
  • Loading branch information
ag-m2ms committed Oct 30, 2020
1 parent e1a3e86 commit 4c93ed5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions js/components/preview/molecule/moleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
IconButton,
ButtonGroup
} from '@material-ui/core';
import React, { useState, useEffect, useCallback, memo, useRef, useContext } from 'react';
import React, { useState, useEffect, useCallback, memo, useRef, useContext, useMemo } from 'react';
import { useDispatch, useSelector, useStore } from 'react-redux';
import MoleculeView, { colourList } from './moleculeView';
import { MoleculeListSortFilterDialog, filterMolecules, getAttrDefinition } from './moleculeListSortFilterDialog';
Expand Down Expand Up @@ -49,7 +49,7 @@ import {
} from './redux/dispatchActions';
import { DEFAULT_FILTER, PREDEFINED_FILTERS } from '../../../reducers/selection/constants';
import { DeleteSweep, FilterList, Search } from '@material-ui/icons';
import { selectJoinedMoleculeList } from './redux/selectors';
import { selectAllMoleculeList, selectJoinedMoleculeList } from './redux/selectors';
import { debounce } from 'lodash';
import { MOL_ATTRIBUTES } from './redux/constants';
import { setFilter } from '../../../reducers/selection/actions';
Expand Down Expand Up @@ -235,6 +235,7 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei
const sortDialogOpen = useSelector(state => state.previewReducers.molecule.sortDialogOpen);
const filter = useSelector(state => state.selectionReducers.filter);
const getJoinedMoleculeList = useSelector(state => selectJoinedMoleculeList(state));
const getAllMoleculeList = useSelector(state => selectAllMoleculeList(state));
const selectedAll = useRef(false);

const proteinList = useSelector(state => state.selectionReducers.proteinList);
Expand Down Expand Up @@ -278,7 +279,7 @@ export const MoleculeList = memo(({ height, setFilterItemsHeight, filterItemsHei

let joinedMoleculeLists = [];
if (searchString !== null) {
joinedMoleculeLists = getJoinedMoleculeList.filter(molecule =>
joinedMoleculeLists = getAllMoleculeList.filter(molecule =>
molecule.protein_code.toLowerCase().includes(searchString.toLowerCase())
);
} else {
Expand Down
21 changes: 21 additions & 0 deletions js/components/preview/molecule/redux/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,24 @@ export const selectJoinedMoleculeList = createSelector(
return joinedMoleculeLists;
}
);

export const selectAllMoleculeList = createSelector(
getAllMolecules,
getMoleculeGroupLists,
(all_mol_lists, mol_group_list) => {
const groupList = mol_group_list || [];
const allMoleculesList = [];
groupList.forEach(site => {
const siteId = site.id;
const siteMolecules = (all_mol_lists || {})[siteId];

if (siteMolecules) {
siteMolecules.forEach(r => {
allMoleculesList.push({ site: siteId, ...r })
});
}
});

return allMoleculesList;
}
)

0 comments on commit 4c93ed5

Please sign in to comment.