Skip to content

Commit

Permalink
add changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Nov 19, 2024
1 parent 51ac118 commit bb671d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { FONT_WEIGHT_SEMI_BOLD } from "theme";

export const TAG_DISPLAY_VALUES: Record<
NodeTag,
{ color: keyof Palette["nodeTag"]; displayName: string; isEditable?: Role }
{ color: keyof Palette["nodeTag"]; displayName: string; isEditable?: Role[] }
> = {
placeholder: {
color: "blocking",
displayName: "Placeholder",
isEditable: "platformAdmin", // if new roles are added, we should update the canEdit() in ComponentTagSelect.tsx
isEditable: ["platformAdmin"], // if new roles are added, we should update the canEdit() in ComponentTagSelect.tsx
},
toReview: {
color: "nonBlocking",
Expand Down
13 changes: 6 additions & 7 deletions editor.planx.uk/src/ui/editor/ComponentTagSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ interface Props {
}

const canEdit = (role?: Role) => {
// depending on the role, a different form of validation will happen
switch (role) {
case "platformAdmin":
return useStore.getState().user?.isPlatformAdmin;
case undefined:
return true;
return !useStore.getState().user?.isPlatformAdmin;
default:
return true;
}
Expand All @@ -35,7 +34,7 @@ const renderOption: AutocompleteProps<
false,
"div"
>["renderOption"] = (props, tag, { selected }) => {
if (!canEdit(TAG_DISPLAY_VALUES[tag].isEditable)) return null;
if (TAG_DISPLAY_VALUES[tag].isEditable?.some(canEdit)) return null;
return (
<ListItem {...props}>
<CustomCheckbox
Expand Down Expand Up @@ -71,9 +70,9 @@ const renderTags: AutocompleteProps<
),
})}
onDelete={
canEdit(TAG_DISPLAY_VALUES[tag].isEditable)
? getTagProps({ index }).onDelete
: undefined
TAG_DISPLAY_VALUES[tag].isEditable?.some(canEdit)
? undefined
: getTagProps({ index }).onDelete
}
/>
);
Expand Down

0 comments on commit bb671d4

Please sign in to comment.