Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1269] Prevent dropping elements in a read only diagram #1270

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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