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: #1269
Signed-off-by: Nicolas Vannier <nicolas.vannier@obeo.fr>
  • Loading branch information
nvannr authored and sbegaudeau committed Sep 1, 2022
1 parent 006df30 commit 06f53b1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ This allows representation precondition expressions to be more precise as they k
- https://github.com/eclipse-sirius/sirius-components/issues/1231[#1231] [releng] Fix every unit tests provided in the various frontend packages
- https://github.com/eclipse-sirius/sirius-components/issues/1318[#1318] [studio] Java service classes used by studios (via `IJavaServiceProvider`) can now ask to be injected with any Spring bean available in the application context (for example `IObjectService` or other Sirius Components services they need for their implementation).
- https://github.com/eclipse-sirius/sirius-components/issues/1288[#1288] [core] Improve support for precondition expression from representation description
- https://github.com/eclipse-sirius/sirius-components/issues/1269[#1269] [diagram] Prevent dropping elements in a read only diagram

=== New features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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 @@ -150,17 +151,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: 'This representation is currently read-only',
};
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
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,8 @@ export const DiagramRepresentation = ({
editingContextId={editingContextId}
representationId={representationId}
invokeHover={invokeHover}
convertInSprottyCoordinate={convertInSprottyCoordinate}>
convertInSprottyCoordinate={convertInSprottyCoordinate}
readOnly={readOnly}>
<div id="diagram-wrapper" className={classes.diagramWrapper}>
<div ref={diagramDomElement} id="diagram" className={classes.diagram} />
{contextualPaletteContent}
Expand Down

0 comments on commit 06f53b1

Please sign in to comment.