diff --git a/js/components/header/index.js b/js/components/header/index.js index 484316a02..11ba81ab1 100644 --- a/js/components/header/index.js +++ b/js/components/header/index.js @@ -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: { @@ -272,8 +273,8 @@ export default memo( targetName !== undefined ? ( <> {currentProject.authorID === null || - currentProject.projectID === null || - currentProject.authorID === userId ? ( + currentProject.projectID === null || + currentProject.authorID === userId ? ( {XCA_TAG_CATEGORIES.map(category => - + Change {PLURAL_TO_SINGULAR[category]} - - {getTagsForCategory(category)?.map(tag => ( - handleXCAtagChange(tag)}> - {tag.upload_name} - - ))} - + {!disableXCATagChange(category) && + + {getTagsForCategory(category)?.map(tag => ( + handleXCAtagChange(tag)}> + {tag.upload_name} + + ))} + } )} diff --git a/js/components/preview/tags/api/tagsApi.js b/js/components/preview/tags/api/tagsApi.js index 3e9f52d3b..17f5ad061 100644 --- a/js/components/preview/tags/api/tagsApi.js +++ b/js/components/preview/tags/api/tagsApi.js @@ -11,7 +11,7 @@ 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; @@ -19,7 +19,7 @@ export const getTags = targetId => { }); }; -export const getTagCategories = () => { +export const getTagCategories = async () => { return api({ url: `${base_url}/api/tag_category/` }).then(response => { if (response?.data) { return response.data?.results; @@ -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)) @@ -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({ @@ -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({ @@ -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) { @@ -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({ diff --git a/js/components/preview/tags/modal/editTagsModal.js b/js/components/preview/tags/modal/editTagsModal.js index 77a5d2b36..dc6578102 100644 --- a/js/components/preview/tags/modal/editTagsModal.js +++ b/js/components/preview/tags/modal/editTagsModal.js @@ -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: { @@ -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(''); @@ -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]); @@ -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); @@ -139,6 +140,7 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => { setNewTagName(''); setNewTagLink(''); setNewHidden(false); + dispatch(setTagToEdit(null)); }; const onCategoryForNewTagChange = event => { @@ -211,7 +213,7 @@ 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)); @@ -219,7 +221,7 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => { } // update all props at once if (newTagCategory) { - dispatch( + const updatedTag = await dispatch( updateTagProp( Object.assign({}, tag, { category: newTagCategory, @@ -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, @@ -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(); } }; @@ -278,6 +280,7 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => { const handleCloseModal = () => { if (open) { setOpenDialog(false); + resetTagToEditState(); } }; @@ -326,7 +329,7 @@ export const EditTagsModal = memo(({ open, anchorEl, setOpenDialog }) => { {rightSide(