Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ivy-lli committed Jan 7, 2025
1 parent 9eba286 commit 1c8b97e
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 53 deletions.
23 changes: 10 additions & 13 deletions packages/editor/src/diagram/gateways/gateway-views.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ describe('GatewayNodeView', () => {
});

test('render full gateway graph', () => {
const graphVNode = context.renderElement(graph);
expect(toHTML(graphVNode)).to.not.include('sprotty_unknown').and.not.include('sprotty-missing');
let view = context.renderElement(graph);
expect(toHTML(view)).to.not.include('sprotty_unknown').and.not.include('sprotty-missing');
const unknown = graphFactory.createRoot({ type: 'unknown', id: 'unknown', children: [] });
const unknownVNode = context.renderElement(unknown);
expect(toHTML(unknownVNode)).to.be.equal(
view = context.renderElement(unknown);
expect(toHTML(view)).to.be.equal(
'<text id="sprotty_unknown" class="sprotty-missing" x="0" y="0" data-svg-metadata-api="true" data-svg-metadata-type="unknown">missing &quot;unknown&quot; view</text>'
);
});
Expand All @@ -53,28 +53,25 @@ describe('GatewayNodeView', () => {
});

test('render with execution badge', () => {
const view = viewRegistry.get(GatewayTypes.TASK);
const task = graph.index.getById('gatewayTask') as GatewayNode;
task.executionCount = 3;
const vnode = view.render(task, context);
const view = viewRegistry.get(GatewayTypes.TASK).render(task, context);
const executionBadge =
'<g><rect class="execution-badge" rx="7" ry="7" x="21" y="-7" width="22" height="14" /><text class="execution-text" x="32" dy=".4em">3</text></g>';
expect(toHTML(vnode)).to.contains(executionBadge);
expect(toHTML(view)).to.contains(executionBadge);
});

test('render with color', () => {
const view = viewRegistry.get(GatewayTypes.TASK);
const task = graph.index.getById('gatewayTask') as GatewayNode;
task.args = { color: 'red' };
const vnode = view.render(task, context);
const view = viewRegistry.get(GatewayTypes.TASK).render(task, context);
const colorPolygon = /<polygon.*style="stroke: red".*\/>/;
expect(toHTML(vnode)).to.matches(colorPolygon);
expect(toHTML(view)).to.matches(colorPolygon);
});

function assertGateway(type: string, nodeId: string): void {
const view = viewRegistry.get(type);
const vnode = view.render(graph.index.getById(nodeId) as GNode, context);
const node = toHTML(vnode);
const view = viewRegistry.get(type).render(graph.index.getById(nodeId) as GNode, context);
const node = toHTML(view);
expect(node).to.contains('<polygon class="sprotty-node" points="16,0 32,16 16,32 0,16" style="stroke: " />');
expect(node).to.contains('<svg class="sprotty-icon-svg" viewBox="0 0 20 20" height="14" width="18" x="7" y="9">');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/diagram/grid/ivy-graph-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class IvyGraphView extends GLSPProjectionView {

protected renderNegativeArea(model: Readonly<GViewportRootElement>): VNode {
if (isViewport(model.root)) {
const modelBounds = getModelBounds(model.root)!;
const modelBounds = getModelBounds(model.root) ?? Bounds.EMPTY;
return h('g', { class: { 'negative-area-group': true } }, [
h('rect', {
attrs: {
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/diagram/icon/views.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { describe, test, expect } from 'vitest';
import type { VNode, VNodeData } from 'snabbdom';
import type { Bounds } from '@eclipse-glsp/client';
Expand Down
28 changes: 12 additions & 16 deletions packages/editor/src/diagram/lanes/lane-views.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,52 +46,48 @@ describe('LaneNodeView', () => {
});

test('render full lane graph', () => {
const graphVNode = context.renderElement(graph);
expect(toHTML(graphVNode)).to.not.include('sprotty_unknown').and.not.include('sprotty-missing');
let view = context.renderElement(graph);
expect(toHTML(view)).to.not.include('sprotty_unknown').and.not.include('sprotty-missing');
const unknown = graphFactory.createRoot({ type: 'unknown', id: 'unknown', children: [] });
const unknownVNode = context.renderElement(unknown);
expect(toHTML(unknownVNode)).to.be.equal(
view = context.renderElement(unknown);
expect(toHTML(view)).to.be.equal(
'<text id="sprotty_unknown" class="sprotty-missing" x="0" y="0" data-svg-metadata-api="true" data-svg-metadata-type="unknown">missing &quot;unknown&quot; view</text>'
);
});

test('render pool node', () => {
const view = viewRegistry.get(LaneTypes.POOL);
const vnode = view.render(graph.index.getById('pool') as GNode, context);
const view = viewRegistry.get(LaneTypes.POOL).render(graph.index.getById('pool') as GNode, context);
const expectation =
'<g><rect class="sprotty-node" x="0" y="0" rx="4px" ry="4px" width="800" height="500" />' +
'<path class="sprotty-node pool-label-rect" d="M23,0 v500 h-19 q-4,0 -4,-4 v-492 q0,-4 4,-4 z" />' +
'<text id="sprotty_poolLabel" class="sprotty-label label" transform="rotate(270) translate(-250 15)" data-svg-metadata-type="lanes:label" data-svg-metadata-parent-id="sprotty_pool">' +
'<tspan dy="0" x="0" /></text></g>';
expect(toHTML(vnode)).to.be.equal(expectation);
expect(toHTML(view)).to.be.equal(expectation);
});

test('render pool node with multiline label', () => {
const view = viewRegistry.get(LaneTypes.POOL);
const vnode = view.render(graph.index.getById('pool2') as GNode, context);
const view = viewRegistry.get(LaneTypes.POOL).render(graph.index.getById('pool2') as GNode, context);
const expectation =
'<g><rect class="sprotty-node" x="0" y="0" rx="4px" ry="4px" width="800" height="500" />' +
'<path class="sprotty-node pool-label-rect" d="M37,0 v500 h-33 q-4,0 -4,-4 v-492 q0,-4 4,-4 z" />' +
'<text id="sprotty_poolLabel2" class="sprotty-label label" transform="rotate(270) translate(-250 15)" data-svg-metadata-type="lanes:label" data-svg-metadata-parent-id="sprotty_pool2">' +
'<tspan dy="0" x="0" /><tspan dy="1.2em" x="0" /></text></g>';
expect(toHTML(vnode)).to.be.equal(expectation);
expect(toHTML(view)).to.be.equal(expectation);
});

test('render lane node', () => {
const view = viewRegistry.get(LaneTypes.LANE);
const vnode = view.render(graph.index.getById('lane') as GNode, context);
const view = viewRegistry.get(LaneTypes.LANE).render(graph.index.getById('lane') as GNode, context);
const expectation =
'<g><rect class="sprotty-node" x="0" y="0" rx="4px" ry="4px" width="770" height="500" />' +
'<text id="sprotty_laneLabel" class="sprotty-label label" transform="rotate(270) translate(-250 15)" data-svg-metadata-type="lanes:label" data-svg-metadata-parent-id="sprotty_lane">' +
'<tspan dy="0" x="0" /></text></g>';
expect(toHTML(vnode)).to.be.equal(expectation);
expect(toHTML(view)).to.be.equal(expectation);
});

test('render lane with color dot', () => {
const view = viewRegistry.get(LaneTypes.LANE);
const lane = graph.index.getById('lane') as LaneNode;
lane.args = { color: 'red' };
const vnode = view.render(lane, context);
expect(toHTML(vnode)).to.contain('style="--lane-color: red"');
const view = viewRegistry.get(LaneTypes.LANE).render(lane, context);
expect(toHTML(view)).to.contain('style="--lane-color: red"');
});
});
33 changes: 14 additions & 19 deletions packages/editor/src/diagram/views.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,55 +31,50 @@ describe('EdgeView', () => {
});

test('render full edge graph', () => {
const graphVNode = context.renderElement(graph);
expect(toHTML(graphVNode)).to.not.include('sprotty_unknown').and.not.include('sprotty-missing');
let view = context.renderElement(graph);
expect(toHTML(view)).to.not.include('sprotty_unknown').and.not.include('sprotty-missing');
const unknown = graphFactory.createRoot({ type: 'unknown', id: 'unknown', children: [] });
const unknownVNode = context.renderElement(unknown);
expect(toHTML(unknownVNode)).to.be.equal(
view = context.renderElement(unknown);
expect(toHTML(view)).to.be.equal(
'<text id="sprotty_unknown" class="sprotty-missing" x="0" y="0" data-svg-metadata-api="true" data-svg-metadata-type="unknown">missing &quot;unknown&quot; view</text>'
);
});

test('render edge', () => {
const view = viewRegistry.get(EdgeTypes.DEFAULT);
const vnode = view.render(graph.index.getById('edge') as GEdge, context);
const view = viewRegistry.get(EdgeTypes.DEFAULT).render(graph.index.getById('edge') as GEdge, context);
const expectation =
'<g class="sprotty-edge"><path d="M 130,115 L 200,115" />' +
'<path class="sprotty-edge arrow" d="M 0,0.3 L 6,-3.5 M 0,-0.3 L 6,3.5" transform="rotate(180 200 115) translate(200 115)" /></g>';
expect(toHTML(vnode)).to.be.equal(expectation);
expect(toHTML(view)).to.be.equal(expectation);
});

test('render edge with routing points', () => {
const view = viewRegistry.get(EdgeTypes.DEFAULT);
const vnode = view.render(graph.index.getById('edgeWithRoutes') as GEdge, context);
const view = viewRegistry.get(EdgeTypes.DEFAULT).render(graph.index.getById('edgeWithRoutes') as GEdge, context);
const expectation =
'<g class="sprotty-edge"><path d="M 116.35803619063778,129.93839809701555 L 150,500 L 212.5028714424112,129.79068453341068" />' +
'<path class="sprotty-edge arrow" d="M 0,0.3 L 6,-3.5 M 0,-0.3 L 6,3.5" transform="rotate(99.58294472353258 212.5028714424112 129.79068453341068) ' +
'translate(212.5028714424112 129.79068453341068)" /></g>';
expect(toHTML(vnode)).to.be.equal(expectation);
expect(toHTML(view)).to.be.equal(expectation);
});

test('render edge with padding', () => {
const view = viewRegistry.get(EdgeTypes.DEFAULT);
const vnode = view.render(graph.index.getById('edgeWithPadding') as GEdge, context);
const view = viewRegistry.get(EdgeTypes.DEFAULT).render(graph.index.getById('edgeWithPadding') as GEdge, context);
const mouseHandle =
'<path class="mouse-handle" d="M 130,115 L 200,115" style="stroke-width: 10px; stroke: transparent; stroke-dasharray: none; stroke-dashoffset: 0" />';
expect(toHTML(vnode)).to.contains(mouseHandle);
expect(toHTML(view)).to.contains(mouseHandle);
});

test('render edge assoziation', () => {
const view = viewRegistry.get(EdgeTypes.ASSOCIATION);
const vnode = view.render(graph.index.getById('assoziation') as GEdge, context);
const view = viewRegistry.get(EdgeTypes.ASSOCIATION).render(graph.index.getById('assoziation') as GEdge, context);
const expectation = '<g class="sprotty-edge"><path d="M 675,150 L 675,150" /></g>';
expect(toHTML(vnode)).to.be.equal(expectation);
expect(toHTML(view)).to.be.equal(expectation);
});

test('render edge with color', () => {
const view = viewRegistry.get(EdgeTypes.DEFAULT);
const edge = graph.index.getById('edge') as Edge;
edge.args = { color: 'red' };
const vnode = view.render(edge, context);
const view = viewRegistry.get(EdgeTypes.DEFAULT).render(edge, context);
const color = 'style="stroke: red"';
expect(toHTML(vnode)).to.contain(color);
expect(toHTML(view)).to.contain(color);
});
});
5 changes: 3 additions & 2 deletions packages/editor/src/edit-label/edit-label-ui.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Action, EditLabelUI, IActionHandler, ICommand, isEditLabelAction, SetUIExtensionVisibilityAction } from '@eclipse-glsp/client';
import { Action, EditLabelUI, IActionHandler, isEditLabelAction, SetUIExtensionVisibilityAction } from '@eclipse-glsp/client';
import { injectable } from 'inversify';

@injectable()
export class IvyEditLabelActionHandler implements IActionHandler {
handle(action: Action): void | Action | ICommand {
handle(action: Action) {
if (isEditLabelAction(action)) {
return SetUIExtensionVisibilityAction.create({
extensionId: IvyEditLabelUI.IVY_ID,
visible: true,
contextElementsId: [action.labelId]
});
}
return;
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/execution/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class SetExecutedElementsActionHandler implements IActionHandler {

protected oldExecutions: ElementExecution[];

handle(action: Action): Action | void {
handle(action: Action) {
if (SetExecutedElementsAction.is(action)) {
const feedbackAction = ExecutedFeedbackAction.create({
oldElementExecutions: this.oldExecutions,
Expand Down Expand Up @@ -47,7 +47,7 @@ export class StoppedActionHandler implements IActionHandler {

protected oldStoppedElement: string;

handle(action: Action): Action | void {
handle(action: Action) {
if (StoppedAction.is(action)) {
const feedbackAction = StoppedFeedbackAction.create({ oldStoppedElement: this.oldStoppedElement, stoppedElement: action.elementId });
if (action.elementId && action.elementId.length > 0) {
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/ui-tools/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export abstract class ItemMenu implements Menu {
const matchingChildren = itemGroup.children.filter(child => child.label.toLowerCase().includes(filter.toLowerCase()));
if (matchingChildren.length > 0) {
itemGroup.children.splice(0, itemGroup.children.length);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
matchingChildren.forEach(child => itemGroup.children!.push(child));
filteredPaletteItems.push(itemGroup);
}
Expand Down

0 comments on commit 1c8b97e

Please sign in to comment.