Skip to content

Commit

Permalink
disable add, remove, re-order option buttons in node dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Sep 26, 2023
1 parent 7efab60 commit 5312561
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions editor.planx.uk/src/ui/ListManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from "react-beautiful-dnd";

import { removeAt, setAt } from "../utils";
import { useStore } from "pages/FlowEditor/lib/store";

export interface EditorProps<T> {
index?: number;
Expand Down Expand Up @@ -45,6 +46,10 @@ export default function ListManager<T, EditorExtraProps>(
// Initialize a random ID when the component mounts
const randomId = useRef(String(Math.random()));

// useStore.getState().getTeam().slug undefined here, use window instead
const teamSlug = window.location.pathname.split("/")[1];
const isViewOnly = !useStore.getState().canUserEditTeam(teamSlug);

return props.disableDragAndDrop ? (
<>
<Box>
Expand All @@ -54,7 +59,7 @@ export default function ListManager<T, EditorExtraProps>(
<Box>
<IconButton
disableRipple
disabled={true}
disabled={true || isViewOnly}
aria-label="Drag"
size="large"
>
Expand All @@ -76,6 +81,7 @@ export default function ListManager<T, EditorExtraProps>(
}}
aria-label="Delete"
size="large"
disabled={isViewOnly}
>
<Delete />
</IconButton>
Expand All @@ -89,6 +95,7 @@ export default function ListManager<T, EditorExtraProps>(
onClick={() => {
props.onChange([...props.values, props.newValue()]);
}}
disabled={isViewOnly}
>
{props.newValueLabel || "add new"}
</Button>
Expand Down Expand Up @@ -125,9 +132,10 @@ export default function ListManager<T, EditorExtraProps>(
disableRipple
{...(!props.disableDragAndDrop
? provided.dragHandleProps
: { disabled: true })}
: { disabled: true || isViewOnly })}
aria-label="Drag"
size="large"
disabled={isViewOnly}
>
<DragHandle />
</IconButton>
Expand All @@ -147,6 +155,7 @@ export default function ListManager<T, EditorExtraProps>(
}}
aria-label="Delete"
size="large"
disabled={isViewOnly}
>
<Delete />
</IconButton>
Expand All @@ -165,6 +174,7 @@ export default function ListManager<T, EditorExtraProps>(
onClick={() => {
props.onChange([...props.values, props.newValue()]);
}}
disabled={isViewOnly}
>
{props.newValueLabel || "add new"}
</Button>
Expand Down

0 comments on commit 5312561

Please sign in to comment.