Skip to content

Commit

Permalink
feat: Add editable flag to ContentTagsDrawer
Browse files Browse the repository at this point in the history
Currently set to always be editable. Need to implement proper permission
checks to determine whether user has access to readonly/editable drawer.
  • Loading branch information
yusuf-musleh committed Nov 26, 2023
1 parent ae34667 commit 9592d11
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
23 changes: 14 additions & 9 deletions src/content-tags-drawer/ContentTagsCollapsible.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ const removeTags = (tree, tagsToRemove) => {
* @param {Object[]} taxonomyAndTagsData.contentTags - Array of taxonomy tags that are applied to the content
* @param {string} taxonomyAndTagsData.contentTags.value - Value of applied Tag
* @param {string} taxonomyAndTagsData.contentTags.lineage - Array of Tag's ancestors sorted (ancestor -> tag)
* @param {boolean} editable - Whether the tags can be edited
*/
const ContentTagsCollapsible = ({ contentId, taxonomyAndTagsData }) => {
const ContentTagsCollapsible = ({ contentId, taxonomyAndTagsData, editable }) => {
const intl = useIntl();
const {
id, name, contentTags,
Expand Down Expand Up @@ -296,17 +297,20 @@ const ContentTagsCollapsible = ({ contentId, taxonomyAndTagsData }) => {
<div className="d-flex">
<Collapsible title={name} styling="card-lg" className="taxonomy-tags-collapsible">
<div key={id}>
<ContentTagsTree tagsTree={tagsTree} removeTagHandler={tagChangeHandler} />
<ContentTagsTree tagsTree={tagsTree} removeTagHandler={tagChangeHandler} editable={editable} />
</div>

<div className="d-flex taxonomy-tags-selector-menu">
<Button
ref={setTarget}
variant="outline-primary"
onClick={open}
>
<FormattedMessage {...messages.addTagsButtonText} />
</Button>

{editable && (
<Button
ref={setTarget}
variant="outline-primary"
onClick={open}
>
<FormattedMessage {...messages.addTagsButtonText} />
</Button>
)}
</div>
<ModalPopup
placement="bottom"
Expand Down Expand Up @@ -362,6 +366,7 @@ ContentTagsCollapsible.propTypes = {
lineage: PropTypes.arrayOf(PropTypes.string),
})),
}).isRequired,
editable: PropTypes.bool.isRequired,
};

export default ContentTagsCollapsible;
3 changes: 2 additions & 1 deletion src/content-tags-drawer/ContentTagsDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ const ContentTagsDrawer = () => {
{ isTaxonomyListLoaded && isContentTaxonomyTagsLoaded
? taxonomies.map((data) => (
<div key={`taxonomy-tags-collapsible-${data.id}`}>
<ContentTagsCollapsible contentId={contentId} taxonomyAndTagsData={data} />
{/* TODO: Properly set whether tags should be editable or not based on permissions */}
<ContentTagsCollapsible contentId={contentId} taxonomyAndTagsData={data} editable />
<hr />
</div>
))
Expand Down
6 changes: 5 additions & 1 deletion src/content-tags-drawer/ContentTagsTree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ import TagBubble from './TagBubble';
* };
*
* @param {Object} tagsTree - Array of taxonomy tags that are applied to the content
* @param {Func} removeTagHandler - Function that is called when removing tags from tree
* @param {boolean} editable - Whether the tags appear with an 'x' allowing the user to remove them
*/
const ContentTagsTree = ({ tagsTree, removeTagHandler }) => {
const ContentTagsTree = ({ tagsTree, removeTagHandler, editable }) => {
const renderTagsTree = (tag, level, lineage) => Object.keys(tag).map((key) => {
const updatedLineage = [...lineage, encodeURIComponent(key)];
if (tag[key] !== undefined) {
Expand All @@ -49,6 +51,7 @@ const ContentTagsTree = ({ tagsTree, removeTagHandler }) => {
level={level}
lineage={updatedLineage}
removeTagHandler={removeTagHandler}
editable={editable}
/>
{ renderTagsTree(tag[key].children, level + 1, updatedLineage) }
</div>
Expand All @@ -68,6 +71,7 @@ ContentTagsTree.propTypes = {
}).isRequired,
).isRequired,
removeTagHandler: PropTypes.func.isRequired,
editable: PropTypes.bool.isRequired,
};

export default ContentTagsTree;
7 changes: 4 additions & 3 deletions src/content-tags-drawer/TagBubble.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import PropTypes from 'prop-types';
import TagOutlineIcon from './TagOutlineIcon';

const TagBubble = ({
value, implicit, level, lineage, removeTagHandler,
value, implicit, level, lineage, removeTagHandler, editable,
}) => {
const className = `tag-bubble mb-2 ${implicit ? 'implicit' : ''}`;

const handleClick = React.useCallback(() => {
if (!implicit) {
if (!implicit && editable) {
removeTagHandler(lineage.join(','), false);
}
}, [implicit, lineage]);
Expand All @@ -24,7 +24,7 @@ const TagBubble = ({
className={className}
variant="light"
iconBefore={!implicit ? Tag : TagOutlineIcon}
iconAfter={!implicit ? Close : null}
iconAfter={!implicit && editable ? Close : null}
onIconAfterClick={handleClick}
>
{value}
Expand All @@ -44,6 +44,7 @@ TagBubble.propTypes = {
level: PropTypes.number,
lineage: PropTypes.arrayOf(PropTypes.string).isRequired,
removeTagHandler: PropTypes.func.isRequired,
editable: PropTypes.bool.isRequired,
};

export default TagBubble;

0 comments on commit 9592d11

Please sign in to comment.