Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1519 and #1520 #453

Merged
merged 16 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions js/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { AddProjectDetail } from '../projects/addProjectDetail';
import { ServicesStatusWrapper } from '../services';
import { COMPANIES, get_logo } from '../funders/constants';
import { setEditTargetDialogOpen } from '../target/redux/actions';
import { Upload } from '@mui/icons-material';

const useStyles = makeStyles(theme => ({
padding: {
Expand Down Expand Up @@ -272,8 +273,8 @@ export default memo(
targetName !== undefined ? (
<>
{currentProject.authorID === null ||
currentProject.projectID === null ||
currentProject.authorID === userId ? (
currentProject.projectID === null ||
currentProject.authorID === userId ? (
<Button
onClick={() => {
isProjectModalLoading === false
Expand Down Expand Up @@ -574,6 +575,29 @@ export default memo(
</ListItemIcon>
<ListItemText primary="Contributors" />
</ListItem>
{DJANGO_CONTEXT.pk &&
<>
<Divider />
<ListItem button onClick={() => openLink(URLS.lhsUpload)}>
<ListItemIcon>
<Upload />
</ListItemIcon>
<ListItemText primary="LHS upload" />
</ListItem>
<ListItem button onClick={() => openLink(URLS.rhsUpload)}>
<ListItemIcon>
<Upload />
</ListItemIcon>
<ListItemText primary="RHS upload" />
</ListItem>
<ListItem button onClick={() => openLink(URLS.metadataUpload)}>
<ListItemIcon>
<Upload />
</ListItemIcon>
<ListItemText primary="Metadata upload" />
</ListItem>
</>
}
<Divider />
{authListItem}
</Grid>
Expand Down
10 changes: 4 additions & 6 deletions js/components/preview/molecule/moleculeView/moleculeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ export const img_data_init = `<svg xmlns="http://www.w3.org/2000/svg" version="1
<animateTransform attributeName="transform" type="rotate" repeatCount="indefinite" dur="0.689655172413793s" values="0 50 50;360 50 50" keyTimes="0;1"></animateTransform>
</circle> '</svg>`;

export const XCA_TAGS_CATEGORIES = ['CanonSites', 'ConformerSites', 'Quatassemblies', 'Crystalforms', 'CrystalformSites'];

const MoleculeView = memo(
({
imageHeight,
Expand Down Expand Up @@ -476,9 +478,6 @@ const MoleculeView = memo(
setTagEditModalOpenNew(tagEditorOpenObs);
}, [tagEditorOpenObs]);

const XCA_TAGS_CATEGORIES = ['CanonSites', 'ConformerSites', 'Quatassemblies', 'Crystalforms', 'CrystalformSites'];
const XCA_TAGS_CATEGORIES_EXPANDED = ['Quatassemblies', 'ConformerSites', 'Crystalforms', 'CrystalformSites', 'CanonSites'];

useEffect(() => {
api({
url: `${base_url}/api/canon_site_confs/`,
Expand Down Expand Up @@ -523,7 +522,7 @@ const MoleculeView = memo(
setHeaderWidthsHandler(getTagLabel(tagCategory), tagCategory);
})
}
}, [showExpandedView, getTagType, getTagLabel, centroidRes, data.longcode, setHeaderWidthsHandler, XCA_TAGS_CATEGORIES]);
}, [showExpandedView, getTagType, getTagLabel, centroidRes, data.longcode, setHeaderWidthsHandler]);

const handlePopoverOpen = event => {
setTagPopoverOpen(event.currentTarget);
Expand Down Expand Up @@ -1428,7 +1427,6 @@ const MoleculeView = memo(
xs={5}
container
direction="row"
justifyContent="center"
alignItems="center"
// wrap="nowrap"
style={{ height: "100%" }}
Expand Down Expand Up @@ -1488,7 +1486,7 @@ const MoleculeView = memo(
</div>}
</Grid>
{showExpandedView && <Grid item container alignItems='center' wrap="nowrap">
{XCA_TAGS_CATEGORIES_EXPANDED.map((tagCategory, index) => {
{XCA_TAGS_CATEGORIES.map((tagCategory, index) => {
return <Tooltip title={`${PLURAL_TO_SINGULAR[tagCategory]} - ${getTagTooltip(tagCategory)}`} key={index}>
<Grid item align="center" className={classes.categoryCell} style={{ minWidth: headerWidths[tagCategory] }}>
{getTagLabel(tagCategory)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ const ObservationCmpView = memo(
{/* CanonSites */}
<Grid item xs container direction="column" justifyContent="center" alignItems="stretch" wrap="nowrap">
<Tooltip
title={<div style={{ whiteSpace: 'pre-line' }}>CanonSite - {getCanonSitesTag().upload_name}</div>}
title={<div style={{ whiteSpace: 'pre-line' }}>CanonSite - {getCanonSitesTag().tag}</div>}
>
<Grid
item
Expand All @@ -1631,7 +1631,7 @@ const ObservationCmpView = memo(
{getConformerSites().map((conformerSite, i, sites) => (
<Tooltip
key={conformerSite.id + i}
title={<div style={{ whiteSpace: 'pre-line' }}>ConformerSite - {conformerSite.upload_name}</div>}
title={<div style={{ whiteSpace: 'pre-line' }}>ConformerSite - {conformerSite.tag}</div>}
>
<Grid
item
Expand Down
14 changes: 7 additions & 7 deletions js/components/preview/molecule/observationsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { updateLHSCompound, updateMoleculeInMolLists, updateMoleculeTag, updateT
import { createPoseErrorMessage } from './api/poseApi';
import { augumentTagObjectWithId, createMoleculeTagObject, DEFAULT_TAG_COLOR, getMoleculeTagForTag } from '../tags/utils/tagUtils';
import { updateExistingTag } from '../tags/api/tagsApi';
import { XCA_TAGS_CATEGORIES } from './moleculeView/moleculeView';

const MIN_PANEL_HEIGHT = 250;

Expand Down Expand Up @@ -277,11 +278,11 @@ export const ObservationsDialog = memo(
const [tagEditorAnchorEl, setTagEditorAnchorEl] = useState(null);
const [expandView, setExpandView] = useState(null);
const [headerWidths, setHeaderWidths] = useState({
Quatassemblies: getCalculatedTagColumnWidth('Quatassemblies'),
CanonSites: getCalculatedTagColumnWidth('CanonSites'),
ConformerSites: getCalculatedTagColumnWidth('ConformerSites'),
Quatassemblies: getCalculatedTagColumnWidth('Quatassemblies'),
Crystalforms: getCalculatedTagColumnWidth('Crystalforms'),
CrystalformSites: getCalculatedTagColumnWidth('CrystalformSites'),
CanonSites: getCalculatedTagColumnWidth('CanonSites'),
CentroidRes: getCalculatedTagColumnWidth('CentroidRes'),
LongCode: getCalculatedTagColumnWidth('LongCode'),
});
Expand All @@ -292,7 +293,7 @@ export const ObservationsDialog = memo(
* @param {*} tagCategory
*/
const setHeaderWidthsHandler = (tagText, tagCategory) => {
const calculatedWidth = getCalculatedTagColumnWidth(tagText, '12px bold');
const calculatedWidth = getCalculatedTagColumnWidth(tagText, 'bold 12px');
if (headerWidths[tagCategory] < calculatedWidth) {
setHeaderWidths(old => {
const newWidths = { ...old };
Expand Down Expand Up @@ -984,11 +985,10 @@ export const ObservationsDialog = memo(
item
xs
container
justifyContent="space-around"
// adjust maxWidth if headers are a bit misplaced
style={{ maxWidth: '74%', marginLeft: 95 }}
alignItems="center"
style={{ marginLeft: 95 }}
>
{['Quatassemblies', 'ConformerSites', 'Crystalforms', 'CrystalformSites', 'CanonSites'].map(
{XCA_TAGS_CATEGORIES.map(
(tagCategory, index) => (
<Grid item align="center" key={index} className={classes.headerCell} style={{ minWidth: headerWidths[tagCategory] }}>
{PLURAL_TO_SINGULAR[tagCategory]}
Expand Down
14 changes: 7 additions & 7 deletions js/components/preview/tags/api/tagsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { getDefaultTagDiscoursePostText } from '../utils/tagUtils';
// });
// };

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

export const getTagCategories = () => {
export const getTagCategories = async () => {
return api({ url: `${base_url}/api/tag_category/` }).then(response => {
if (response?.data) {
return response.data?.results;
Expand Down Expand Up @@ -67,7 +67,7 @@ export const getTagMolecules = targetId => {
.catch(err => console.log(err));
};

export const createNewTag = (tag, targetName) => {
export const createNewTag = async (tag, targetName) => {
let url = `${base_url}/api/siteobservation_tag/`;
if (isDiscourseAvailable()) {
return createTagPost(tag, targetName, getDefaultTagDiscoursePostText(tag))
Expand Down Expand Up @@ -101,7 +101,7 @@ export const createNewTag = (tag, targetName) => {
}
};

export const createNewDownloadTag = tag => {
export const createNewDownloadTag = async tag => {
let url = `${base_url}/api/siteobservation_tag/`;
const jsonString = JSON.stringify(tag);
return api({
Expand All @@ -115,7 +115,7 @@ export const createNewDownloadTag = tag => {
.catch(err => console.log(err));
};

export const updateExistingTag = (tag, tagId) => {
export const updateExistingTag = async (tag, tagId) => {
const jsonString = JSON.stringify(tag);
let url = `${base_url}/api/siteobservation_tag/${tagId}/`;
return api({
Expand All @@ -129,7 +129,7 @@ export const updateExistingTag = (tag, tagId) => {
.catch(err => console.log(err));
};

export const getTagByName = tagName => {
export const getTagByName = async tagName => {
let url = `${base_url}/api/siteobservation_tag/?tag=${tagName}`;
return api({ url: url }).then(response => {
if (response?.data?.results?.length > 0) {
Expand All @@ -138,7 +138,7 @@ export const getTagByName = tagName => {
});
};

export const deleteExistingTag = (tag, tagId) => {
export const deleteExistingTag = async (tag, tagId) => {
const jsonString = JSON.stringify(tag);
let url = `${base_url}/api/siteobservation_tag/${tagId}/`;
return api({
Expand Down
21 changes: 12 additions & 9 deletions js/components/preview/tags/modal/editTagsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { removeSelectedTag, updateTagProp } from "../redux/dispatchActions";
import { getCategoryById } from "../../molecule/redux/dispatchActions";
import { ToastContext } from "../../../toast";
import { TAG_DETAILS_REMOVED_CATEGORIES } from "../../../../constants/constants";
import { setTagToEdit } from "../../../../reducers/selection/actions";

const useStyles = makeStyles(theme => ({
leftSide: {
Expand Down Expand Up @@ -44,9 +45,9 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => {
const allMolList = useSelector(state => state.apiReducers.all_mol_lists);
const moleculesToEditIds = useSelector(state => state.selectionReducers.moleculesToEdit);
const selectedTagList = useSelector(state => state.selectionReducers.selectedTagList);
const tag = useSelector(state => state.selectionReducers.tagToEdit);

const id = open ? 'simple-popover-tags-editor' : undefined;
const [tag, setTag] = useState(null);
const [tags, setTags] = useState([NEW_TAG]);
const [newTagColor, setNewTagColor] = useState(DEFAULT_TAG_COLOR);
const [newTagName, setNewTagName] = useState('');
Expand Down Expand Up @@ -90,7 +91,7 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => {
});
setTags([NEW_TAG, ...newTagList.sort(compareTagsByCategoryAndNameAsc)]);
return () => {
setTag(null);
// dispatch(setTagToEdit(null)); // uncomment this to reset tag after update - clean up moved to resetTagToEditState
setTags([NEW_TAG]);
};
}, [preTagList, tagCategories]);
Expand All @@ -105,7 +106,7 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => {
setNewTagLink(tag.discourse_url);
setNewHidden(tag.hidden || false);
}
}, [dispatch, getColourForTag, tag]);
}, [getColourForTag, tag]);

const comboCategories = useMemo(() => {
return getEditNewTagCategories(tagCategories);
Expand Down Expand Up @@ -139,6 +140,7 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => {
setNewTagName('');
setNewTagLink('');
setNewHidden(false);
dispatch(setTagToEdit(null));
};

const onCategoryForNewTagChange = event => {
Expand Down Expand Up @@ -211,15 +213,15 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => {
}
};

const updateTag = () => {
const updateTag = async () => {
if (validateTag() && tag && newTagCategory && newTagName) {
if (!tag.hidden && newHidden && selectedTagList.some(selectedTag => selectedTag.id === tag.id)) {
dispatch(removeSelectedTag(tag));
toastWarning('Tag was automatically deselected because of becoming hidden', { autoHideDuration: 5000 });
}
// update all props at once
if (newTagCategory) {
dispatch(
const updatedTag = await dispatch(
updateTagProp(
Object.assign({}, tag, {
category: newTagCategory,
Expand All @@ -232,8 +234,9 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => {
'tag'
)
);
dispatch(setTagToEdit(updatedTag));
} else {
dispatch(
const updatedTag = await dispatch(
updateTagProp(
Object.assign({}, tag, {
colour: newTagColor,
Expand All @@ -245,10 +248,9 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => {
'tag'
)
);
dispatch(setTagToEdit(updatedTag));
}
toastInfo('Tag was updated', { autoHideDuration: 5000 });
// reset tag/fields after updating selected one
resetTagToEditState();
}
};

Expand Down Expand Up @@ -278,6 +280,7 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => {
const handleCloseModal = () => {
if (open) {
setOpenDialog(false);
resetTagToEditState();
}
};

Expand Down Expand Up @@ -326,7 +329,7 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => {
{rightSide(
<Select
value={tag?.id || 0}
onChange={(event) => setTag(tags.find(tag => tag.id === event.target.value))}
onChange={(event) => dispatch(setTagToEdit(tags.find(tag => tag.id === event.target.value)))}
fullWidth
>
{tags?.map(tag => (
Expand Down
9 changes: 8 additions & 1 deletion js/components/preview/tags/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,16 @@ export const storeData = data => (dispatch, getState) => {
dispatch(setTagSelectorData(categories, tags));

let allMolecules = [];
data.molecules.forEach(mol => {});
data.molecules.forEach(mol => { });
};

/**
*
* @param {Object} tag tag object
* @param {*} value new value
* @param {*} prop name of the prop to be updated
* @returns {Promise<Object>}
*/
export const updateTagProp = (tag, value, prop) => (dispatch, getState) => {
const state = getState();
const molTags = state.apiReducers.moleculeTags;
Expand Down
4 changes: 4 additions & 0 deletions js/components/routes/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const URLS = {
funders: '/viewer/react/funders/',
target: '/viewer/react/preview/target/',

lhsUpload: '/api/upload_target_experiments/',
rhsUpload: '/viewer/upload_cset/',
metadataUpload: '/api/metadata_upload/',

// Projects feature
projects: '/viewer/react/projects/',
// Direct feature
Expand Down