Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/allfunctionality' into #441
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Feb 11, 2021
2 parents c5af2dc + a2bbaa2 commit 452b8ce
Show file tree
Hide file tree
Showing 21 changed files with 740 additions and 345 deletions.
17 changes: 13 additions & 4 deletions js/components/datasets/datasetFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
setFilterDialogOpen,
setFilterProperties,
setFilterSettings,
setDatasetFilter,
setFilterWithInspirations
} from './redux/actions';
import {
Expand Down Expand Up @@ -96,20 +97,25 @@ export const DatasetFilter = memo(
return scoreDatasetList[Object.keys(scoreDatasetList).find(attrName => attrName === attr)];
};

const handleFilterChange = (newFilterProperties, newFilterSettings) => {
const handleFilterChange = (newFilterProperties, newFilterSettings, key, prio, oldPrio) => {
Object.keys(scoreDatasetList).forEach(attrKey => {
if (newFilterProperties[attrKey].priority === undefined || newFilterProperties[attrKey].priority === '') {
newFilterProperties[attrKey].priority = 0;
}
if (attrKey === key && prio !== undefined && prio !== null) {
newFilterProperties[attrKey].newPrio = prio;
newFilterProperties[attrKey].oldPrio = oldPrio;
}
});
dispatch(setDatasetFilter(datasetID, newFilterProperties, newFilterSettings, key));
dispatch(setFilterProperties(datasetID, newFilterProperties));
dispatch(setFilterSettings(datasetID, newFilterSettings));
};

const handleItemChange = key => setting => {
const newFilterSettings = createFilterSettingsObject({ active: true, predefined, priorityOrder });
const newFilterProperties = { ...filterProperties, [key]: setting };
handleFilterChange(newFilterProperties, newFilterSettings);
handleFilterChange(newFilterProperties, newFilterSettings, key);
};

const handlePrioChange = key => inc => () => {
Expand All @@ -124,13 +130,16 @@ export const DatasetFilter = memo(
newFilterSettings.priorityOrder = localPriorityOrder;
newFilterSettings.active = true;

handleFilterChange(filterProperties, newFilterSettings);
let oldPrio = index;
let newPrio = index + inc;
let newFilterProperties = { ...filterProperties };
handleFilterChange(newFilterProperties, newFilterSettings, key, newPrio, oldPrio);
}
};

const handleClear = () => {
setPredefinedFilter('none');
handleFilterChange(defaultFilterProperties, defaultFilterSettings);
handleFilterChange(defaultFilterProperties, defaultFilterSettings, 'clear');
};

// Check for multiple attributes with same sorting priority
Expand Down
72 changes: 37 additions & 35 deletions js/components/datasets/datasetMoleculeListSortFilterItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useState } from 'react';
import React, { memo, useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import Button from '@material-ui/core/Button';
import Slider from '@material-ui/core/Slider';
Expand Down Expand Up @@ -120,6 +120,10 @@ export const DatasetMoleculeListSortFilter = memo(
isString
};

useEffect(() => {
setSliderValue([normMinValue, normMaxValue]);
}, [normMinValue, normMaxValue]);

const handleCheckboxChange = e => {
const isChecked = e.target.checked;

Expand All @@ -142,7 +146,7 @@ export const DatasetMoleculeListSortFilter = memo(
};

const handleCommitChangeSlider = (event, newValue) => {
setting.minValue = isBoolean ? 1 : (isFloat ? newValue[0] / MULT : newValue[0]);
setting.minValue = isFloat ? newValue[0] / MULT : newValue[0];
setting.maxValue = isFloat ? newValue[1] / MULT : newValue[1];
if (newValue === 1) {
setting.isChecked = false;
Expand Down Expand Up @@ -259,7 +263,7 @@ export const DatasetMoleculeListSortFilter = memo(
{isBoolean && (
<>
<Grid item className={classNames(classes.min, classes.centered)} style={{ width: widthMin }}>
{"False"}
{'False'}
</Grid>
<Grid item className={classNames(classes.centered, classes.slider)} style={{ width: widthSlider }}>
<Slider
Expand All @@ -268,44 +272,42 @@ export const DatasetMoleculeListSortFilter = memo(
onChangeCommitted={handleCommitChangeSlider}
valueLabelDisplay="auto"
step={null}
marks={[{ value: 1, label: "", }, { value: 50, label: "Ignore", }, { value: 100, label: "", },]}
getAriaValueText={
value => {
if (value === 0) {
return "";
} else if (value === 100) {
return "";
} else {
return "Ignore";
}
marks={[
{ value: 1, label: '' },
{ value: 50, label: 'Ignore' },
{ value: 100, label: '' }
]}
getAriaValueText={value => {
if (value === 0) {
return '';
} else if (value === 100) {
return '';
} else {
return 'Ignore';
}
}
getAriaLabel={
index => {
if (index === 0) {
return "False";
} else if (index === 1) {
return "Ignore";
} else {
return "True";
}
}}
getAriaLabel={index => {
if (index === 0) {
return 'False';
} else if (index === 1) {
return 'Ignore';
} else {
return 'True';
}
}
valueLabelFormat={
value => {
if (value === 1) {
return "False";
} else if (value === 50) {
return "Ignore";
} else {
return "True";
}
}}
valueLabelFormat={value => {
if (value === 1) {
return 'False';
} else if (value === 50) {
return 'Ignore';
} else {
return 'True';
}
}
}}
/>
</Grid>
<Grid item className={classNames(classes.min, classes.centered)} style={{ width: widthMin }}>
{"True"}
{'True'}
</Grid>
</>
)}
Expand Down
14 changes: 0 additions & 14 deletions js/components/datasets/datasetMoleculeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,20 +485,6 @@ export const DatasetMoleculeView = memo(
});
};

const getInspirationsForMol = (datasetId, molId) => {
let inspirations = [];

if (
allInspirations &&
allInspirations.hasOwnProperty(datasetId) &&
allInspirations[datasetId].hasOwnProperty(molId)
) {
inspirations = allInspirations[datasetId][molId];
}

return inspirations;
};

const handleClickOnDownArrow = () => {
const refNext = ref.current.nextSibling;
scrollToElement(refNext);
Expand Down
6 changes: 5 additions & 1 deletion js/components/datasets/datasetSelectorMenuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Popper from '@material-ui/core/Popper';
import MenuItem from '@material-ui/core/MenuItem';
import MenuList from '@material-ui/core/MenuList';
import { makeStyles } from '@material-ui/core';
import { useDispatch } from 'react-redux';

const useStyles = makeStyles(theme => ({
dropDown: {
Expand All @@ -21,9 +22,12 @@ export const DatasetSelectorMenuButton = ({
setSelectedDatasetIndex
}) => {
const classes = useStyles();
const dispatch = useDispatch();

const handleMenuItemClick = (event, index) => {
setSelectedDatasetIndex(index);
let oldDataset = customDatasets[selectedDatasetIndex]?.title;
let newDataset = customDatasets[index]?.title;
dispatch(setSelectedDatasetIndex(selectedDatasetIndex, index, newDataset, oldDataset));
setOpen(false);
event.stopPropagation();
};
Expand Down
21 changes: 21 additions & 0 deletions js/components/datasets/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ export const setMoleculeListIsLoading = isLoading => ({
payload: isLoading
});

export const setSelectedDatasetIndex = (oldValue, tabValue, tabName, oldName, skipTracking = false) => ({
type: constants.SET_SELECTED_DATASET_INDEX,
payload: { oldValue: oldValue, value: tabValue, name: tabName, oldName: oldName },
skipTracking: skipTracking
});

export const setTabValue = (oldValue, tabValue, tabName, oldName) => ({
type: constants.SET_TAB_VALUE,
payload: { oldValue: oldValue, value: tabValue, name: tabName, oldName: oldName }
});

export const replaceAllMoleculeLists = allMoleculeLists => ({
type: constants.REPLACE_ALL_MOLECULELISTS,
payload: allMoleculeLists
Expand All @@ -41,6 +52,11 @@ export const setFilterProperties = (datasetID, properties) => ({
payload: { datasetID, properties }
});

export const setDatasetFilter = (datasetID, properties, settings, key) => ({
type: constants.SET_DATASET_FILTER,
payload: { datasetID, properties, settings, key }
});

export const setFilterDialogOpen = filterDialogOpen => ({
type: constants.SET_FILTER_DIALOG_OPEN,
payload: filterDialogOpen
Expand Down Expand Up @@ -234,6 +250,11 @@ export const updateFilterShowedScoreProperties = ({ datasetID, scoreList = [] })
payload: { datasetID, scoreList }
});

export const setFilterShowedScoreProperties = ({ datasetID, scoreList = [], oldScoreList, isChecked, scoreName }) => ({
type: constants.SET_FILTER_SHOWED_SCORE_PROPERTIES,
payload: { datasetID, scoreList, isChecked, scoreName, oldScoreList }
});

export const removeFromFilterShowedScoreProperties = datasetID => ({
type: constants.REMOVE_FROM_FILTER_SHOWED_SCORE_PROPERTIES,
payload: datasetID
Expand Down
4 changes: 4 additions & 0 deletions js/components/datasets/redux/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ export const constants = {
ADD_MOLECULELIST: prefix + 'ADD_MOLECULELIST',
REMOVE_MOLECULELIST: prefix + 'REMOVE_MOLECULELIST',
SET_IS_LOADING_MOLECULE_LIST: prefix + 'SET_IS_LOADING_MOLECULE_LIST',
SET_SELECTED_DATASET_INDEX: prefix + 'SET_SELECTED_DATASET_INDEX',
SET_TAB_VALUE: prefix + 'SET_TAB_VALUE',

SET_FILTER_SETTINGS: prefix + 'SET_FILTER_SETTINGS',
SET_FILTER_PROPERTIES: prefix + 'SET_FILTER_PROPERTIES',
SET_FILTER_DIALOG_OPEN: prefix + 'SET_FILTER_DIALOG_OPEN',
SET_FILTER_WITH_INSPIRATIONS: prefix + 'SET_FILTER_WITH_INSPIRATIONS',
SET_DATASET_FILTER: prefix + 'SET_DATASET_FILTER',

SET_LIGAND_LIST: prefix + 'SET_LIGAND_LIST',
APPEND_LIGAND_LIST: prefix + 'APPEND_LIGAND_LIST',
Expand Down Expand Up @@ -39,6 +42,7 @@ export const constants = {
APPEND_TO_SCORE_COMPOUND_MAP_BY_SCORE_CATEGORY: prefix + 'APPEND_TO_SCORE_COMPOUND_MAP_BY_SCORE_CATEGORY',
CLEAR_SCORE_COMPOUND_MAP: prefix + 'CLEAR_SCORE_COMPOUND_MAP',

SET_FILTER_SHOWED_SCORE_PROPERTIES: prefix + 'SET_FILTER_SHOWED_SCORE_PROPERTIES',
UPDATE_FILTER_SHOWED_SCORE_PROPERTIES: prefix + 'UPDATE_FILTER_SHOWED_SCORE_PROPERTIES',
REMOVE_FROM_FILTER_SHOWED_SCORE_PROPERTIES: prefix + 'REMOVE_FROM_FILTER_SHOWED_SCORE_PROPERTIES',

Expand Down
7 changes: 7 additions & 0 deletions js/components/datasets/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
appendToScoreDatasetMap,
appendToScoreCompoundMapByScoreCategory,
updateFilterShowedScoreProperties,
setFilterShowedScoreProperties,
setFilterProperties,
setIsLoadingInspirationListOfMolecules,
appendToInspirationMoleculeDataList,
Expand Down Expand Up @@ -339,6 +340,8 @@ export const selectScoreProperty = ({ isChecked, datasetID, scoreName }) => (dis
const state = getState();
const filteredScorePropertiesOfDataset = state.datasetsReducers.filteredScoreProperties[datasetID];
const scoreDatasetMap = state.datasetsReducers.scoreDatasetMap[datasetID];
let scoreList = [];
let oldScoreList = [...filteredScorePropertiesOfDataset];

if (isChecked === true) {
if (filteredScorePropertiesOfDataset.length === COUNT_OF_VISIBLE_SCORES) {
Expand All @@ -348,20 +351,24 @@ export const selectScoreProperty = ({ isChecked, datasetID, scoreName }) => (dis
// 2. select new property
const selectedProperty = scoreDatasetMap[scoreName];
filteredScorePropertiesOfDataset.push(selectedProperty);
scoreList = filteredScorePropertiesOfDataset;
dispatch(
updateFilterShowedScoreProperties({
datasetID,
scoreList: filteredScorePropertiesOfDataset
})
);
} else {
scoreList = filteredScorePropertiesOfDataset.filter(item => item.name !== scoreName);
dispatch(
updateFilterShowedScoreProperties({
datasetID,
scoreList: filteredScorePropertiesOfDataset.filter(item => item.name !== scoreName)
})
);
}

dispatch(setFilterShowedScoreProperties({ datasetID, scoreList, oldScoreList, isChecked, scoreName }));
};

export const loadInspirationMoleculesDataList = (inspirationList = []) => (dispatch, getState) => {
Expand Down
13 changes: 11 additions & 2 deletions js/components/datasets/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const INITIAL_STATE = {
scoreDatasetMap: {}, // map of $datasetID and its $scoreList
scoreCompoundMap: {}, // map of $compoundID and its $scoreList

selectedDatasetIndex: 0,
tabValue: 0,

// filter
filterDatasetMap: {}, // map of $datasetID and its $filterSettings
filterPropertiesDatasetMap: {}, // map of $datasetID and its $filterProperties
Expand Down Expand Up @@ -138,7 +141,7 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
return Object.assign({}, state, { datasets: action.payload });

case constants.REPLACE_ALL_MOLECULELISTS:
return {...state, moleculeLists: action.payload};
return { ...state, moleculeLists: action.payload };

case constants.ADD_MOLECULELIST:
// initialize also control containers
Expand All @@ -161,6 +164,12 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
case constants.SET_IS_LOADING_MOLECULE_LIST:
return Object.assign({}, state, { isLoadingMoleculeList: action.payload });

case constants.SET_SELECTED_DATASET_INDEX:
return Object.assign({}, state, { selectedDatasetIndex: action.payload.value });

case constants.SET_TAB_VALUE:
return Object.assign({}, state, { tabValue: action.payload.value });

case constants.SET_FILTER_SETTINGS:
const { datasetID, filter } = action.payload;
return { ...state, filterDatasetMap: { ...state.filterDatasetMap, [datasetID]: filter } };
Expand Down Expand Up @@ -347,7 +356,7 @@ export const datasetsReducers = (state = INITIAL_STATE, action = {}) => {
return Object.assign({}, state, { inspirationFragmentList: [...diminishedInspirationFragmentList] });

case constants.SET_ALL_INSPIRATIONS:
return {...state, allInspirations: action.payload};
return { ...state, allInspirations: action.payload };

case constants.APPEND_MOLECULE_TO_COMPOUNDS_TO_BUY_OF_DATASET:
const setOfMolecules = new Set(state.compoundsToBuyDatasetMap[action.payload.datasetID]);
Expand Down
4 changes: 1 addition & 3 deletions js/components/nglView/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export const toggleMoleculeGroup = (molGroupId, summaryViewStage) => (dispatch,
).catch(error => {
throw new Error(error);
});
dispatch(
clearAfterDeselectingMoleculeGroup()
);
dispatch(clearAfterDeselectingMoleculeGroup({ molGroupId }));
}
};

Expand Down
Loading

0 comments on commit 452b8ce

Please sign in to comment.