Skip to content

Commit

Permalink
#1483 - checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Oct 17, 2024
1 parent c6161c2 commit 6ce4124
Show file tree
Hide file tree
Showing 42 changed files with 790 additions and 263 deletions.
6 changes: 3 additions & 3 deletions js/components/datasets/customDatasetList.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const CustomDatasetList = memo(({ dataset, hideProjects, isActive }) => {
dispatch(clearDatasetSettings(dataset.id));
}
}
return () => {
dispatch(clearDatasetSettings(dataset?.id));
};
// return () => {
// dispatch(clearDatasetSettings(dataset?.id));
// };
}, [dataset, dispatch, isActive, isLoadingMoleculeList]);

const title = dataset && `${dataset.title} v.${dataset.version}`;
Expand Down
12 changes: 6 additions & 6 deletions js/components/datasets/datasetMoleculeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
const isSelectedTypeOn = (typeList, isLHSReference) => {
if (typeList) {
if (!isLHSReference) {
return typeList.some(molId => allMolecules.some(mol => mol.id === molId));
return typeList.some(molId => allMolecules?.some(mol => mol.id === molId));
} else {
const molsWithLHSReference = allMolecules.filter(mol => mol.site_observation_code);
const molsWithLHSReference = allMolecules?.filter(mol => mol.site_observation_code);
return typeList.some(molId =>
molsWithLHSReference.some(
mol => mol.site_observation_code === allMoleculesList.find(m => m.id === molId)?.code
mol => mol.site_observation_code === allMoleculesList?.find(m => m.id === molId)?.code
)
);
}
Expand Down Expand Up @@ -561,7 +561,7 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
);
} else {
if (molecule.site_observation_code) {
const lhsMol = allMoleculesList.find(mol => mol.code === molecule.site_observation_code);
const lhsMol = allMoleculesList?.find(mol => mol.code === molecule.site_observation_code);
if (lhsMol) {
dispatch(removeLHSType[type](stage, lhsMol, colourList[molecule.id % colourList.length], skipTracking));
}
Expand Down Expand Up @@ -595,7 +595,7 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
);
} else {
if (molecule.site_observation_code) {
const lhsMol = allMoleculesList.find(mol => mol.code === molecule.site_observation_code);
const lhsMol = allMoleculesList?.find(mol => mol.code === molecule.site_observation_code);
if (lhsMol) {
if (type === 'protein') {
promises.push(
Expand Down Expand Up @@ -1477,7 +1477,7 @@ const DatasetMoleculeList = ({ title, datasetID, url }) => {
// #1249 dataset molecules currently could use side observation molecule for some renders
let idToFind = data.id;
if (data.site_observation_code) {
const molecule = allMoleculesList.find(mol => mol.code === data.site_observation_code);
const molecule = allMoleculesList?.find(mol => mol.code === data.site_observation_code);
if (molecule) {
idToFind = molecule.id;
}
Expand Down
5 changes: 3 additions & 2 deletions js/components/datasets/inspirationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const InspirationDialog = memo(
let rationale = '';
if (datasetID && inspirationLists.hasOwnProperty(datasetID) && inspirationLists[datasetID][0]) {
const moleculeID = inspirationLists[datasetID][0];
const molecule = moleculeLists[datasetID].find(molecule => molecule.id === moleculeID);
const molecule = moleculeLists[datasetID]?.find(molecule => molecule.id === moleculeID);
if (molecule !== undefined) {
rationale = molecule.text_scores.hasOwnProperty('rationale') ? molecule.text_scores.rationale : '';
}
Expand Down Expand Up @@ -194,7 +194,7 @@ export const InspirationDialog = memo(
}, [inspirationMoleculeDataList, searchString]);

const allSelectedMolecules = inspirationMoleculeDataList.filter(
molecule => moleculesToEditIds.includes(molecule.id) /* || molForTagEditId.some(mid => molecule.id === mid)*/
molecule => moleculesToEditIds.includes(molecule?.id) /* || molForTagEditId.some(mid => molecule.id === mid)*/
);

// TODO: refactor from this line (duplicity in datasetMoleculeList.js)
Expand Down Expand Up @@ -451,6 +451,7 @@ export const InspirationDialog = memo(
<div className={classes.content}>
{moleculeList.length > 0 &&
moleculeList.map((molecule, index, array) => {
if (!molecule) return <> </>;
let data = molecule;
data.isInspiration = true;
let previousData = index > 0 && Object.assign({ isInspiration: true }, array[index - 1]);
Expand Down
22 changes: 0 additions & 22 deletions js/components/datasets/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,6 @@ export const addDatasetSurface = (
datasetID: datasetID
})
);
// dispatch(appendSurfaceList(datasetID, generateMoleculeCompoundId(data)));
// return dispatch(
// loadObject({
// target: Object.assign(
// { display_div: VIEWS.MAJOR_VIEW },
// generateSurfaceObject(data, colourToggle, base_url, datasetID)
// ),
// stage,
// previousRepresentations: representations,
// orientationMatrix: null
// })
// ).finally(() => {
// const currentOrientation = stage.viewerControls.getOrientation();
// dispatch(setOrientation(VIEWS.MAJOR_VIEW, currentOrientation));
// });
};

export const removeDatasetSurface = (stage, data, colourToggle, datasetID) => dispatch => {
Expand All @@ -201,13 +186,6 @@ export const removeDatasetSurface = (stage, data, colourToggle, datasetID) => di
datasetID: datasetID
})
);
// dispatch(
// deleteObject(
// Object.assign({ display_div: VIEWS.MAJOR_VIEW }, generateSurfaceObject(data, colourToggle, base_url, datasetID)),
// stage
// )
// );
// dispatch(removeFromSurfaceList(datasetID, generateMoleculeCompoundId(data)));
};

export const addDatasetLigand = (
Expand Down
9 changes: 7 additions & 2 deletions js/components/datasets/useScrollToCompound.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const useScrollToCompound = () => {
const rhsOpen = useSelector(state => state.previewReducers.viewerControls.sidesOpen.RHS);
const isSelectedCompoundsTab = tabValue === 1;

const rhsDataIsLoaded = useSelector(state => state.apiReducers.rhsDataIsLoaded);

const dialogOpenedForInspirationWithId =
isSelectedCompoundsTab && Object.keys(inspirationLists)?.length > 0
? inspirationLists[Object.keys(inspirationLists)]?.length > 0
Expand Down Expand Up @@ -112,7 +114,9 @@ export const useScrollToCompound = () => {
}
}
console.log(`${uuid} useScrollToCompound useEffect - end - setting selected dataset scrolled`);
dispatch(setSelectedDatasetScrolled(true));
if (rhsDataIsLoaded) {
dispatch(setSelectedDatasetScrolled(true));
}
}
}
console.log(`${uuid} useScrollToCompound useEffect - end`);
Expand All @@ -132,7 +136,8 @@ export const useScrollToCompound = () => {
rhsOpen,
surfaceList,
surfaceListDataset,
uuid
uuid,
rhsDataIsLoaded
]);

useEffect(() => {
Expand Down
9 changes: 7 additions & 2 deletions js/components/datasets/useScrollToSelected.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const useScrollToSelected = (datasetID, moleculesPerPage, setCurrentPage)
const tabValue = useSelector(state => state.datasetsReducers.tabValue);
const isComputedDatasetsTab = tabValue > 1;

const rhsDataIsLoaded = useSelector(state => state.apiReducers.rhsDataIsLoaded);

// First pass, iterates over all the molecules and checks if any of them is selected. If it is,
// it saves the ID of the molecule and determines how many pages of molecules should be displayed.
// This is done only once and only if right hand side is open.
Expand Down Expand Up @@ -89,7 +91,9 @@ export const useScrollToSelected = (datasetID, moleculesPerPage, setCurrentPage)
}
}

dispatch(setDatasetScrolled(datasetID));
if (rhsDataIsLoaded) {
dispatch(setDatasetScrolled(datasetID));
}
}
}, [
compoundsToBuyList,
Expand All @@ -110,7 +114,8 @@ export const useScrollToSelected = (datasetID, moleculesPerPage, setCurrentPage)
proteinList,
complexList,
surfaceList,
isComputedDatasetsTab
isComputedDatasetsTab,
rhsDataIsLoaded
]);

// Second pass, once the list of molecules is displayed and the refs to their DOM nodes have been
Expand Down
28 changes: 18 additions & 10 deletions js/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,14 @@ export default memo(
currentProject.authorID === userId ? (
<Button
onClick={() => {
isProjectModalLoading === false
? (dispatch(setProjectModalIsLoading(true)), dispatch(setAddButton(false)))
: dispatch(setProjectModalIsLoading(false));
openSaveSnapshotModal === true ? dispatch(setOpenSnapshotSavingDialog(false)) : '';
if (!isProjectModalLoading) {
dispatch(setProjectModalIsLoading(true));
dispatch(setAddButton(false));
} else {
dispatch(setProjectModalIsLoading(false));
}

openSaveSnapshotModal ?? dispatch(setOpenSnapshotSavingDialog(false));
}}
key="newProject"
color="primary"
Expand All @@ -282,10 +286,14 @@ export default memo(
) : (
<Button
onClick={() => {
openNewProjectModal === false
? (dispatch(setProjectModalIsLoading(true)), dispatch(setAddButton(false)))
: dispatch(setProjectModalIsLoading(false));
openSaveSnapshotModal === true ? dispatch(setOpenSnapshotSavingDialog(false)) : '';
if (!openNewProjectModal) {
dispatch(setProjectModalIsLoading(true));
dispatch(setAddButton(false));
} else {
dispatch(setProjectModalIsLoading(false));
}

openSaveSnapshotModal ?? dispatch(setOpenSnapshotSavingDialog(false));
}}
key="newProject"
color="primary"
Expand All @@ -303,8 +311,8 @@ export default memo(
openSaveSnapshotModal === false
? dispatch(setOpenSnapshotSavingDialog(true))
: dispatch(setOpenSnapshotSavingDialog(false));
openSaveSnapshotModal === true ? dispatch(setOpenSnapshotSavingDialog(false)) : '';
isProjectModalLoading === true ? dispatch(setProjectModalIsLoading(false)) : '';
openSaveSnapshotModal ?? dispatch(setOpenSnapshotSavingDialog(false));
isProjectModalLoading ?? dispatch(setProjectModalIsLoading(false));

dispatch(setAddButton(false));
}}
Expand Down
22 changes: 14 additions & 8 deletions js/components/nglView/generatingObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ export const generateCompoundMolObject = (sdf_info, identifier) => ({
});

// Ligand
export const generateMoleculeObject = (data, colourToggle, datasetID) => ({
name: `${data.code || data.name}_${OBJECT_TYPE.LIGAND}${datasetID ? '_' + datasetID : ''}`,
OBJECT_TYPE: OBJECT_TYPE.LIGAND,
colour: colourToggle,
sdf_info: data.ligand_mol_file || data.sdf_info,
moleculeId: data.id,
selectionType: SELECTION_TYPE.LIGAND
});
export const generateMoleculeObject = (data, colourToggle, datasetID) => {
if (data) {
return {
name: `${data.code || data.name}_${OBJECT_TYPE.LIGAND}${datasetID ? '_' + datasetID : ''}`,
OBJECT_TYPE: OBJECT_TYPE.LIGAND,
colour: colourToggle,
sdf_info: data.ligand_mol_file || data.sdf_info,
moleculeId: data.id,
selectionType: SELECTION_TYPE.LIGAND
};
} else {
return null;
}
};

// Vector
export const generateArrowObject = (data, start, end, name, colour) => ({
Expand Down
Loading

0 comments on commit 6ce4124

Please sign in to comment.