Skip to content

Commit

Permalink
disable graph commands when in readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelpiano committed Dec 11, 2024
1 parent f320e25 commit b3e8a36
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface GraphDiagramProps {
serializedGraph?: any | undefined;
statement: ConnectivityStatement;
setStatement: (statement: any) => void;
isDisabled?: boolean;
}

const GraphDiagram: React.FC<GraphDiagramProps> = ({
Expand All @@ -60,6 +61,7 @@ const GraphDiagram: React.FC<GraphDiagramProps> = ({
serializedGraph,
statement,
setStatement,
isDisabled = false,
}) => {
const theme = useTheme();
const { statementId } = useParams();
Expand Down Expand Up @@ -285,6 +287,7 @@ const GraphDiagram: React.FC<GraphDiagramProps> = ({
switchLockedGraph={switchLockedGraph}
statement={statement}
setStatement={setStatement}
isDisabled={isDisabled}
/>
<Box
display="flex"
Expand Down
91 changes: 55 additions & 36 deletions frontend/src/components/ProofingTab/GraphDiagram/NavigationMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,21 @@ interface NavigationMenuProps {
switchLockedGraph: (locked: boolean) => void;
statement: ConnectivityStatement;
setStatement: (statement: any) => void;
isDisabled?: boolean;
}

const NavigationMenu = (props: NavigationMenuProps) => {
const {engine, statementId, toggleRankdir, resetGraph, isGraphLocked, switchLockedGraph, statement, setStatement} = props
const {
engine,
statementId,
toggleRankdir,
resetGraph,
isGraphLocked,
switchLockedGraph,
statement,
setStatement,
isDisabled
} = props
const [isSaving, setIsSaving] = useState<boolean>(false)
const [isConfirmationDialogOpen, setIsConfirmationDialogOpen] = useState(false);
const [dialogConfig, setDialogConfig] = useState({
Expand Down Expand Up @@ -239,43 +250,51 @@ const NavigationMenu = (props: NavigationMenuProps) => {
<FitScreenOutlinedIcon/>
</IconButton>
</Tooltip>
<Tooltip arrow title='Switch orientation'>
<IconButton onClick={switchOrientation} disabled={isGraphLocked}>
<CameraswitchOutlinedIcon />
</IconButton>
</Tooltip>
<Divider />
<Tooltip arrow title='Reset to default visualisation'>
<IconButton onClick={redrawGraph} disabled={isGraphLocked}>
<RestartAltOutlinedIcon />
</IconButton>
</Tooltip>
</Stack>
<Stack direction="row" spacing="1rem" alignItems='center'>
{
wasChangeDetected || positionChangeOnly ? (
<Tooltip arrow title='This diagram does not match the Path Builder. It will be updated with default routing if you leave this page.'>
<Alert severity="warning">The diagram is outdated, please use the reset button on the left to update the diagram</Alert>
{!isDisabled && (
<>
<Tooltip arrow title='Switch orientation'>
<IconButton onClick={switchOrientation} disabled={isGraphLocked}>
<CameraswitchOutlinedIcon />
</IconButton>
</Tooltip>
) : (
!isResetInvoked && (
<Tooltip arrow title='The diagram is saved for all users'>
<CheckCircleOutlineRoundedIcon
sx={{
color: "#039855 !important",
}}
/>
</Tooltip>
)
)
}
<Divider />
<CustomSwitch
disabled={(wasChangeDetected && !positionChangeOnly) || (wasChangeDetected && positionChangeOnly)}
locked={isGraphLocked && !isResetInvoked}
setLocked={(lock: boolean) => toggleGraphLock(lock)}
/>
<Divider />
<Tooltip arrow title='Reset to default visualisation'>
<IconButton onClick={redrawGraph} disabled={isGraphLocked}>
<RestartAltOutlinedIcon />
</IconButton>
</Tooltip>
</>
)}
</Stack>
{!isDisabled && (
<>
<Stack direction="row" spacing="1rem" alignItems='center'>
{
wasChangeDetected || positionChangeOnly ? (
<Tooltip arrow title='This diagram does not match the Path Builder. It will be updated with default routing if you leave this page.'>
<Alert severity="warning">The diagram is outdated, please use the reset button on the left to update the diagram</Alert>
</Tooltip>
) : (
!isResetInvoked && (
<Tooltip arrow title='The diagram is saved for all users'>
<CheckCircleOutlineRoundedIcon
sx={{
color: "#039855 !important",
}}
/>
</Tooltip>
)
)
}
<Divider />
<CustomSwitch
disabled={(wasChangeDetected && !positionChangeOnly) || (wasChangeDetected && positionChangeOnly)}
locked={isGraphLocked && !isResetInvoked}
setLocked={(lock: boolean) => toggleGraphLock(lock)}
/>
</Stack>
</>
)}
</Stack>
)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ProofingTab/ProofingTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const ProofingTab = (props: any) => {
p: 0
}}>Download graph</Button>
</Box>
<StatementChart statement={statement} setStatement={setStatement} />
<StatementChart statement={statement} setStatement={setStatement} isDisabled={isDisabled} />
</Stack>
{hasJourney && (
<>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/ProofingTab/StatementChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {ConnectivityStatement} from "../../apiclient/backend";
import {useTheme} from "@mui/system";
import GraphDiagram from "./GraphDiagram/GraphDiagram";

const StatementChart = (props: { statement: ConnectivityStatement, setStatement: () => void }) => {
const {statement, setStatement} = props;
const StatementChart = (props: { statement: ConnectivityStatement, setStatement: () => void, isDisabled: boolean }) => {
const {statement, setStatement, isDisabled} = props;
const theme = useTheme();

const displayChart = statement.origins && statement.origins.length > 0
Expand All @@ -21,6 +21,7 @@ const StatementChart = (props: { statement: ConnectivityStatement, setStatement:
serializedGraph={statement.graph_rendering_state?.serialized_graph}
statement={statement}
setStatement={setStatement}
isDisabled={isDisabled}
/>
) : (
<Box
Expand Down

0 comments on commit b3e8a36

Please sign in to comment.