Skip to content

Commit

Permalink
- #1190 - compounds for LHS
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Dec 13, 2023
1 parent 839559a commit ecc3d6c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 33 deletions.
8 changes: 7 additions & 1 deletion js/components/preview/molecule/moleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import useDisableNglControlButtons from './useDisableNglControlButtons';
import GroupNglControlButtonsContext from './groupNglControlButtonsContext';
import { extractTargetFromURLParam } from '../utils';
import { LoadingContext } from '../../loading';
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -898,7 +899,12 @@ export const MoleculeList = memo(({ hideProjects }) => {

<IconButton
color={'inherit'}
disabled={!joinedMoleculeListsCopy.length || noTagsReceived || !tags.length}
disabled={
!joinedMoleculeListsCopy.length ||
noTagsReceived ||
!tags.length ||
DJANGO_CONTEXT['username'] === 'NOT_LOGGED_IN'
}
onClick={event => {
if (isTagEditorOpen === false) {
setTagEditorAnchorEl(event.currentTarget);
Expand Down
8 changes: 8 additions & 0 deletions js/components/preview/tags/api/tagsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export const getAllDataNew = async targetId => {
});
};

export const getCompoundsLHS = async targetId => {
return api({ url: `${base_url}/api/cmpdimg/?target=${targetId}` }).then(response => {
if (response?.data) {
return response.data?.results;
}
});
};

export const getTagMolecules = targetId => {
return api({ url: `${base_url}/api/siteobservation_tag/?target=${targetId}` })
.then(response => {
Expand Down
67 changes: 38 additions & 29 deletions js/components/preview/tags/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import {
setCategoryList,
setTargetDataLoadingInProgress,
setAllDataLoaded,
setMoleculeTags
setMoleculeTags,
setLHSCompoundsLIst
} from '../../../../reducers/api/actions';
import { setSortDialogOpen } from '../../molecule/redux/actions';
import { resetCurrentCompoundsSettings } from '../../compounds/redux/actions';
import { updateExistingTag, getTags, getAllDataNew, getTagCategories } from '../api/tagsApi';
import { updateExistingTag, getTags, getAllDataNew, getTagCategories, getCompoundsLHS } from '../api/tagsApi';
import {
getMoleculeTagForTag,
createMoleculeTagObject,
Expand Down Expand Up @@ -181,34 +182,42 @@ export const loadMoleculesAndTagsNew = targetId => async (dispatch, getState) =>
dispatch(setNoTagsReceived(false));
}
const tagCategories = await getTagCategories();
return getAllDataNew(targetId).then(data => {
let allMolecules = [];
data?.results?.forEach(mol => {
let newObject = { ...mol };
const tagsForMol = getTagsForMol(mol.id, tags);
if (tagsForMol) {
newObject['tags_set'] = [...tagsForMol.map(t => t.id)];
} else {
newObject['tags_set'] = [];
}
allMolecules.push(newObject);
});

allMolecules?.sort((a, b) => {
if (a.code < b.code) {
return -1;
}
if (a.code > b.code) {
return 1;
}
return 0;
});
const data = await getAllDataNew(targetId);
let allMolecules = [];
data?.results?.forEach(mol => {
let newObject = { ...mol };
const tagsForMol = getTagsForMol(mol.id, tags);
if (tagsForMol) {
newObject['tags_set'] = [...tagsForMol.map(t => t.id)];
} else {
newObject['tags_set'] = [];
}
allMolecules.push(newObject);
});

dispatch(setAllMolLists([...allMolecules]));
//need to do this this way because only categories which have at least one tag assigned are sent from backend
tags = tags.sort(compareTagsAsc);
dispatch(setMoleculeTags(tags));
dispatch(setTagSelectorData(tagCategories, tags));
dispatch(setAllDataLoaded(true));
allMolecules?.sort((a, b) => {
if (a.code < b.code) {
return -1;
}
if (a.code > b.code) {
return 1;
}
return 0;
});

dispatch(setAllMolLists([...allMolecules]));
//need to do this this way because only categories which have at least one tag assigned are sent from backend
tags = tags.sort(compareTagsAsc);
dispatch(setMoleculeTags(tags));
dispatch(setTagSelectorData(tagCategories, tags));
dispatch(setAllDataLoaded(true));

return getCompoundsLHS(targetId).then(compounds => {
compounds?.forEach(c => {
const siteObs = allMolecules.find(m => m.cmpd === c.id);
c['smiles'] = siteObs ? siteObs.smiles : '';
});
dispatch(setLHSCompoundsLIst([...compounds]));
});
};
7 changes: 7 additions & 0 deletions js/reducers/api/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export const setAllMolLists = all_mol_lists => {
};
};

export const setLHSCompoundsLIst = lhs_compounds_list => {
return {
type: constants.SET_LHS_COMPOUNDS_LIST,
lhs_compounds_list: lhs_compounds_list
};
};

export const setMoleculeTags = moleculeTags => {
return {
type: constants.SET_MOLECULE_TAGS,
Expand Down
9 changes: 7 additions & 2 deletions js/reducers/api/apiReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export const INITIAL_STATE = {
categoryList: [],
target_data_loading_in_progress: false,
all_data_loaded: false,
isSnapshot: false
isSnapshot: false,
lhs_compounds_list: []
};

export const RESET_TARGET_STATE = {
Expand Down Expand Up @@ -91,7 +92,8 @@ export const RESET_TARGET_STATE = {
tagList: [],
target_data_loading_in_progress: false,
all_data_loaded: false,
snapshotLoadingInProgress: false
snapshotLoadingInProgress: false,
lhs_compounds_list: []
};

export default function apiReducers(state = INITIAL_STATE, action = {}) {
Expand Down Expand Up @@ -175,6 +177,9 @@ export default function apiReducers(state = INITIAL_STATE, action = {}) {
return state;
}

case constants.SET_LHS_COMPOUNDS_LIST:
return { ...state, lhs_compounds_list: action.lhs_compounds_list };

case constants.SET_PANNDA_EVENT_LIST:
return Object.assign({}, state, {
pandda_event_list: action.pandda_event_list
Expand Down
3 changes: 2 additions & 1 deletion js/reducers/api/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ export const constants = {
SET_TARGET_DATA_LOADING_IN_PROGRESS: prefix + 'SET_TARGET_DATA_LOADING_IN_PROGRESS',
SET_ALL_DATA_LOADED: prefix + 'SET_ALL_DATA_LOADED',
SET_SNAPSHOT_LOADING_IN_PROGRESS: prefix + 'SET_SNAPSHOT_LOADING_IN_PROGRESS',
SET_IS_SNAPSHOT: prefix + 'SET_IS_SNAPSHOT'
SET_IS_SNAPSHOT: prefix + 'SET_IS_SNAPSHOT',
SET_LHS_COMPOUNDS_LIST: prefix + 'SET_LHS_COMPOUNDS_LIST'
};

0 comments on commit ecc3d6c

Please sign in to comment.