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

[cleanup] Improve typing of frontend Palette #1612

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import {
import { SelectionDialog } from '@eclipse-sirius/sirius-components-selection';
import IconButton from '@material-ui/core/IconButton';
import Snackbar from '@material-ui/core/Snackbar';
import makeStyles from '@material-ui/core/styles/makeStyles';
import Typography from '@material-ui/core/Typography';
import makeStyles from '@material-ui/core/styles/makeStyles';
import CloseIcon from '@material-ui/icons/Close';
import { useMachine } from '@xstate/react';
import { useCallback, useContext, useEffect, useRef } from 'react';
import { HoverFeedbackAction, SEdge, SModelElement, SNode, SPort } from 'sprotty';
import { HoverFeedbackAction, SEdge, SModelElement, SNode, SPort, isDeletable, isWithEditableLabel } from 'sprotty';
import { FitToScreenAction, Point } from 'sprotty-protocol';
import { DropArea } from '../droparea/DropArea';
import { ContextualMenu } from '../palette/ContextualMenu';
Expand Down Expand Up @@ -97,17 +97,16 @@ import {
DiagramRefreshedEvent,
DiagramRepresentationContext,
DiagramRepresentationEvent,
diagramRepresentationMachine,
HandleDiagramDescriptionResultEvent,
HandleSelectedObjectInSelectionDialogEvent,
HideToastEvent,
InitializeRepresentationEvent,
ResetSelectedObjectInSelectionDialogEvent,
ResetToolsEvent,
SchemaValue,
SelectZoomLevelEvent,
SelectedElementEvent,
SelectionEvent,
SelectZoomLevelEvent,
SetActiveConnectorToolsEvent,
SetActiveToolEvent,
SetContextualMenuEvent,
Expand All @@ -117,6 +116,7 @@ import {
ShowToastEvent,
SubscribersUpdatedEvent,
SwitchRepresentationEvent,
diagramRepresentationMachine,
} from './DiagramRepresentationMachine';
import { getDiagramDescriptionQuery } from './GetDiagramDescriptionQuery';
import { GQLGetDiagramDescriptionData, GQLGetDiagramDescriptionVariables } from './GetDiagramDescriptionQuery.types';
Expand Down Expand Up @@ -810,7 +810,7 @@ export const DiagramRepresentation = ({
]);

useEffect(() => {
if (selectedObjectId && activeTool && contextualPalette) {
if (selectedObjectId && activeTool && contextualPalette && contextualPalette.element) {
invokeTool(activeTool, contextualPalette.element.id, contextualPalette.palettePosition);
const sourceElementAction: SourceElementAction = { kind: SOURCE_ELEMENT_ACTION, sourceElement: null };
diagramServer.actionDispatcher.dispatch(sourceElementAction);
Expand Down Expand Up @@ -1044,15 +1044,14 @@ export const DiagramRepresentation = ({
*/
let contextualPaletteContent;
if (!readOnly && contextualPalette) {
const { element, palettePosition, canvasBounds, edgeStartPosition, renameable, deletable } = contextualPalette;
const { element, palettePosition, canvasBounds, edgeStartPosition } = contextualPalette;
const { x, y } = edgeStartPosition;
const style = {
left: canvasBounds.x + 'px',
top: canvasBounds.y + 'px',
};

let invokeDeleteFromContextualPalette;
if (deletable) {
if (isDeletable(element)) {
invokeDeleteFromContextualPalette = (deletionPolicy: GQLDeletionPolicy) =>
deleteElements([element], deletionPolicy);
}
Expand Down Expand Up @@ -1121,7 +1120,7 @@ export const DiagramRepresentation = ({
representationId={representationId}
diagramElement={element}
diagramServer={diagramServer}
renameable={renameable}
renameable={isWithEditableLabel(element)}
invokeTool={invokeToolFromContextualPalette}
invokeConnectorTool={invokeConnectorToolFromContextualPalette}
invokeDelete={invokeDeleteFromContextualPalette}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { Node } from '../sprotty/Diagram.types';
import { BorderNode, Diagram, Edge, Node } from '../sprotty/Diagram.types';

export type CursorValue = 'pointer' | 'copy' | 'not-allowed';

Expand Down Expand Up @@ -62,9 +62,7 @@ export interface Palette {
palettePosition: Position;
canvasBounds: Bounds;
edgeStartPosition: Position;
element: any;
renameable: boolean;
deletable: boolean;
element: Diagram | Node | BorderNode | Edge;
}

export interface Menu {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
ReconnectAction,
SEdge,
SelectionResult,
SGraph,
SModelElement,
SNode,
SPort,
Expand Down Expand Up @@ -474,10 +473,7 @@ export class DiagramServer extends ModelSource {

handleShowContextualToolbarAction(action: ShowContextualToolbarAction) {
const { element, position: palettePosition } = action;
if (
!!element &&
((element as any).kind === 'siriusComponents://representation?type=Diagram' || (element as any).parent)
) {
if (element) {
this.actionDispatcher.request<ViewportResult>(GetViewportAction.create()).then((viewportResult) => {
const { viewport, canvasBounds } = viewportResult;
const { scroll, zoom } = viewport;
Expand All @@ -501,8 +497,6 @@ export class DiagramServer extends ModelSource {
canvasBounds: bounds,
edgeStartPosition,
element,
renameable: !(element instanceof SGraph),
deletable: !(element instanceof SGraph),
};
this.setContextualPalette(contextualPalette);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
SingleClickOnTwoDiagramElementsTool,
Tool,
} from '../representation/DiagramRepresentation.types';
import { BorderNode, Diagram, Edge, Node } from './Diagram.types';

export interface SiriusUpdateModelAction extends Action {
kind: 'siriusUpdateModel';
Expand All @@ -40,7 +41,7 @@ export interface SiriusSelectAction extends Action {

export interface SprottySelectAction extends Action {
kind: 'sprottySelectElement';
element: SModelElement;
element: Diagram | Node | BorderNode | Edge | null;
}

export interface ZoomToAction extends Action {
Expand Down Expand Up @@ -73,6 +74,6 @@ export interface ShowContextualMenuAction extends Action {

export interface ShowContextualToolbarAction extends Action {
kind: 'showContextualToolbar';
element: SModelElement;
element: Diagram | Node | BorderNode | Edge | null;
position: Point;
}