Skip to content

Commit

Permalink
[1269] Prevent dropping elements in a read only diagram
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#1269
Signed-off-by: Nicolas Vannier <nicolas.vannier@obeo.fr>
  • Loading branch information
nvannr committed Jun 14, 2022
1 parent c5e9ca6 commit d24c074
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- https://github.com/eclipse-sirius/sirius-components/issues/1253[#1253] [studio] Fix the computation of unsynchronized semantic elements in studios (which broke the use of the Create View operation)
- https://github.com/eclipse-sirius/sirius-components/issues/1193[#1193] [layout] Fix edge layout on diagrams with node lists.
- https://github.com/eclipse-sirius/sirius-components/issues/1260[#1260] [workbench] Fix download project fails when model contains a Form Description Editor
- https://github.com/eclipse-sirius/sirius-components/issues/1269[#1269] [diagram] Prevent dropping elements in a read only diagram

=== Improvements

Expand Down
31 changes: 20 additions & 11 deletions frontend/src/diagram/DropArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const DropArea = ({
invokeHover,
convertInSprottyCoordinate,
children,
readOnly,
}: DropAreaProps) => {
const [{ value, context }, dispatch] = useMachine<DropAreaContext, DropEvent>(dropAreaMachine);
const { toast } = value as SchemaValue;
Expand Down Expand Up @@ -141,17 +142,25 @@ export const DropArea = ({

const handleDrop = (event) => {
event.preventDefault();
const dragSourcesStringified = event.dataTransfer.getData(DRAG_SOURCES_TYPE);
if (dragSourcesStringified) {
const sources = JSON.parse(dragSourcesStringified);
if (Array.isArray(sources)) {
const sourceIds = sources.filter((source) => source?.id).map((source) => source.id);
if (sourceIds.length > 0) {
const diagramElementId = searchId(event.target);
if (diagramElementId) {
dropElement(sourceIds, event.clientX, event.clientY, diagramElementId);
} else {
dropElement(sourceIds, event.clientX, event.clientY);
if (readOnly) {
const showToastEvent: ShowToastEvent = {
type: 'SHOW_TOAST',
message: 'You do not have permission to edit this representation',
};
dispatch(showToastEvent);
} else {
const dragSourcesStringified = event.dataTransfer.getData(DRAG_SOURCES_TYPE);
if (dragSourcesStringified) {
const sources = JSON.parse(dragSourcesStringified);
if (Array.isArray(sources)) {
const sourceIds = sources.filter((source) => source?.id).map((source) => source.id);
if (sourceIds.length > 0) {
const diagramElementId = searchId(event.target);
if (diagramElementId) {
dropElement(sourceIds, event.clientX, event.clientY, diagramElementId);
} else {
dropElement(sourceIds, event.clientX, event.clientY);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/diagram/DropArea.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface DropAreaProps {
invokeHover: (id: string, mouseIsHover: boolean) => void;
convertInSprottyCoordinate: (x: number, y: number) => Promise<{ x: number; y: number }>;
children: React.ReactNode;
readOnly: boolean;
}

0 comments on commit d24c074

Please sign in to comment.