Skip to content

Commit

Permalink
#267 refactor of code
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed May 11, 2020
1 parent 2b6ea93 commit 55a767b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 74 deletions.
75 changes: 3 additions & 72 deletions js/components/datasets/customDatasetList.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,32 @@
/**
* Created by abradley on 14/03/2018.
*/
import React, { useState, useEffect, memo, useRef, useContext } from 'react';
import React, { useState, useEffect, memo, useContext } from 'react';
import { Button } from '../common/Inputs/Button';
import { FilterList } from '@material-ui/icons';
import { connect, useDispatch } from 'react-redux';
import * as apiActions from '../../reducers/api/actions';
import * as listType from '../../constants/listTypes';
import { filterMolecules } from '../preview/molecule/moleculeListSortFilterDialog';
import { getJoinedMoleculeList } from '../preview/molecule/redux/selectors';
import { getUrl, loadFromServer } from '../../utils/genericList';
import { setFilterDialogOpen, setMoleculeListIsLoading } from './redux/actions';
import { VIEWS } from '../../constants/constants';
import { NglContext } from '../nglView/nglProvider';
import { initializeFilter, loadMoleculesOfDataSet } from './redux/dispatchActions';
import { loadMoleculesOfDataSet } from './redux/dispatchActions';
import { setFilter } from './redux/actions';
import { DatasetMoleculeList } from './datasetMoleculeList';
import { initializeMolecules } from '../preview/molecule/redux/dispatchActions';

const CustomDatasetList = memo(
({
dataset,
object_selection,
height,
// target_on,
mol_group_on,
// setMoleculeList,
setFilterItemsHeight,
filterItemsHeight,
filter,
sortDialogOpen,
setFilterDialogOpen,
firstLoad,
hideProjects
}) => {
const dispatch = useDispatch();

console.log('!!!!!!!!!!!!!!!!There can be loader ');

const isActiveFilter = !!(filter || {}).active;
const [sortDialogAnchorEl, setSortDialogAnchorEl] = useState(null);

const { getNglView } = useContext(NglContext);
const stage = getNglView(VIEWS.MAJOR_VIEW) && getNglView(VIEWS.MAJOR_VIEW).stage;

// TODO Reset Infinity scroll
/*useEffect(() => {
// setCurrentPage(0);
}, [object_selection]);*/

// prevent loading molecules multiple times
// const firstLoadRef = useRef(!firstLoad);
//
// useEffect(() => {
// // TODO this reloads too much..
// // loadFromServer({
// // url: getUrl({ list_type, target_on, mol_group_on }),
// // setOldUrl: url => setOldUrl(url),
// // old_url: oldUrl.current,
// // list_type,
// // setObjectList: setMoleculeList,
// // setCachedMolLists,
// // mol_group_on,
// // cached_mol_lists
// // })
// // .then(() => {
// console.log('initializing filter');
// // setPredefinedFilter(dispatch(initializeFilter()).predefined);
// dispatch(initializeFilter());
// // initialize molecules on first target load
// // if (
// // stage &&
// // cached_mol_lists &&
// // cached_mol_lists[mol_group_on] &&
// // firstLoadRef &&
// // firstLoadRef.current &&
// // hideProjects
// // ) {
// // console.log('initializing molecules');
// // firstLoadRef.current = false;
// // dispatch(initializeMolecules(stage, cached_mol_lists[mol_group_on]));
// // }
// // })
// // .catch(error => {
// // throw new Error(error);
// // });
// }, [dispatch, hideProjects, mol_group_on, stage]);

useEffect(() => {
if (dataset && dataset.id) {
dispatch(setMoleculeListIsLoading(true));
Expand All @@ -96,12 +36,6 @@ const CustomDatasetList = memo(
}
}, [dataset, dispatch]);

useEffect(() => {
if (isActiveFilter === false) {
setFilterItemsHeight(0);
}
}, [isActiveFilter, setFilterItemsHeight]);

const actions = [
<Button
onClick={event => {
Expand Down Expand Up @@ -143,13 +77,10 @@ const CustomDatasetList = memo(
function mapStateToProps(state) {
return {
group_type: state.apiReducers.group_type,
target_on: state.apiReducers.target_on,
mol_group_on: state.apiReducers.mol_group_on,
object_selection: state.selectionReducers.mol_group_selection,
object_list: state.apiReducers.molecule_list,
filter: state.datasetsReducers.filter,
sortDialogOpen: state.datasetsReducers.filterDialogOpen,
firstLoad: state.selectionReducers.firstLoad
sortDialogOpen: state.datasetsReducers.filterDialogOpen
};
}
const mapDispatchToProps = {
Expand Down
2 changes: 1 addition & 1 deletion js/components/datasets/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,5 @@ export const loadDataSets = () => dispatch =>
export const loadMoleculesOfDataSet = dataSetID => dispatch =>
api({ url: `${base_url}/api/compound-molecules/?compound_set=${dataSetID}` }).then(response => {
dispatch(addMoleculeList(dataSetID, response.data.results));
//dispatch(setDataset(response.data.results.map(ds => ({ id: ds.id, title: ds.name }))));
dispatch(initializeFilter());
});
2 changes: 1 addition & 1 deletion js/components/preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const Preview = memo(({ isStateLoaded, hideProjects }) => {
}px - ${theme.spacing(8)}px)`;

/* Custom dataset list height */
const customMoleculeListHeight = `calc(100vh - ${headerHeight}px - ${theme.spacing(2)}px - ${
const customMoleculeListHeight = `calc(100vh - ${headerHeight}px - ${theme.spacing(2)}px - ${molGroupsHeight}px - ${
filterItemsHeight > 0 ? filterItemsHeight + theme.spacing(1) / 2 : 0
}px - ${theme.spacing(8)}px - ${TABS_HEADER_HEIGHT}px)`;

Expand Down

0 comments on commit 55a767b

Please sign in to comment.