sshiv012 commented on code in PR #9278:
URL: https://github.com/apache/texera/pull/9278#discussion_r4624699679
##########
frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.ts:
##########
@@ -1263,6 +1265,94 @@ export class WorkflowEditorComponent implements OnInit,
AfterViewInit, OnDestroy
});
}
+ /**
+ * Anchors comment boxes by dragging them: while comment boxes are dragged
without any operator, the
+ * operators they would anchor to are outlined, and on drop each dragged box
settles its own anchor
+ * by where it landed (see anchorCommentBoxOnDrop, which also detaches a box
dropped far from its
+ * operator). Dragging them along with operators changes nothing.
+ */
+ private handleCommentBoxDragToAnchor(): void {
+ const TARGET_HIGHLIGHT_ID = "commentBoxAnchorTarget";
+ const texeraGraph = this.workflowActionService.getTexeraGraph();
+ // The comment box under the pointer, and every comment box the drag moves
(the whole selection).
+ let drag: { pressedID: string; start: Point; commentBoxIDs: string[] } |
undefined;
+ let targetOperatorIDs: string[] = [];
+ const setTargets = (operatorIDs: string[]) => {
+ targetOperatorIDs
+ .filter(operatorID => !operatorIDs.includes(operatorID))
+ .map(operatorID => this.paper.findViewByModel(operatorID))
+ .forEach(view => view && joint.highlighters.mask.remove(view,
TARGET_HIGHLIGHT_ID));
+ operatorIDs
+ .filter(operatorID => !targetOperatorIDs.includes(operatorID))
+ .map(operatorID => this.paper.findViewByModel(operatorID))
+ .forEach(
+ view =>
+ view &&
+ joint.highlighters.mask.add(view, "rect.body",
TARGET_HIGHLIGHT_ID, {
+ padding: 6,
+ rx: 5,
+ ry: 5,
+ attrs: { "stroke-width": 2, stroke: "#1890FF",
"stroke-dasharray": "4 2" },
+ })
+ );
+ targetOperatorIDs = operatorIDs;
+ };
+ const draggedCommentBoxIDs = () =>
+ drag!.commentBoxIDs.filter(commentBoxID =>
texeraGraph.hasCommentBox(commentBoxID));
+
+ fromJointPaperEvent(this.paper, "element:pointerdown")
+ .pipe(untilDestroyed(this))
+ .subscribe(event => {
+ const pressedID = event[0].model.id.toString();
+ drag =
+ this.interactive &&
+ texeraGraph.hasCommentBox(pressedID) &&
+ this.wrapper.getCurrentHighlightedOperatorIDs().length === 0
+ ? {
+ pressedID,
+ start: this.wrapper.getElementPosition(pressedID),
+ commentBoxIDs: _.union([pressedID],
this.wrapper.getCurrentHighlightedCommentBoxIDs()),
Review Comment:
Confirmed. Fixed in 5b2454019: pointerdown records each candidate box's
start position, and the drop settles only boxes that actually moved (the target
outline uses the same set). Added an editor spec: shift-press one of two
selected comments and drag it away; the other, 10px from an operator, stays put
and stays floating.
##########
frontend/src/app/workspace/service/workflow-graph/model/shared-model-change-handler.ts:
##########
@@ -463,18 +466,59 @@ export class SharedModelChangeHandler {
this.texeraGraph.portAddedOrDeletedSubject.next({ newOperator: operator });
}
+ /**
+ * Keeps each anchored comment box's outline and connector line on its
operator: redrawn whenever the
+ * comment box or the operator is added to the joint graph, moves, or the
operator is removed.
+ * An anchor to an operator that is not on the canvas (e.g. deleted by an
editor that predates anchoring)
+ * is drawn as floating.
+ * Listens on the joint graph itself, which outlives every shared model, so
it is registered once.
+ * @private
+ */
+ private handleCommentBoxConnectors(): void {
+ this.jointGraph.on("add remove change:position", (cell: joint.dia.Cell) =>
{
+ const elementID = cell.id.toString();
+ if (this.texeraGraph.hasCommentBox(elementID)) {
+ this.refreshCommentBoxConnector(elementID);
+ } else {
+ // A removed operator is already gone from the texera graph, so look
up its comment boxes by ID alone.
+ this.texeraGraph
+ .getCommentBoxesAnchoredTo(elementID)
+ .forEach(commentBoxID =>
this.refreshCommentBoxConnector(commentBoxID));
+ }
+ });
+ }
+
+ private refreshCommentBoxConnector(commentBoxID: string): void {
+ const commentElement = this.jointGraph.getCell(commentBoxID) as
joint.dia.Element | undefined;
+ if (commentElement === undefined) {
+ return;
+ }
+ const operatorID =
this.texeraGraph.getCommentBox(commentBoxID).anchoredOperatorID;
+ const operatorElement =
+ operatorID === undefined ? undefined :
(this.jointGraph.getCell(operatorID) as joint.dia.Element | undefined);
+ commentElement.attr("rect",
JointUIService.getCommentBoxAnchorAttrs(operatorElement !== undefined));
+ commentElement.attr(
+ ".anchor-connector",
+ JointUIService.getCommentBoxConnectorAttrs(commentElement.getBBox(),
operatorElement?.getBBox())
+ );
+ }
+
/**
* Syncs changes that are on nested-structures of comment boxes, including
changes of:
* - adding comments
* - deleting comments
* - editing comments (processed as deleting and then adding in-place)
+ * - anchoring the box to an operator, or detaching it
* @private
*/
private handleCommentBoxDeep(): void {
this.texeraGraph.sharedModel.commentBoxMap.observeDeep((events:
Y.YEvent<any>[]) => {
events.forEach(event => {
if (event.target !== this.texeraGraph.sharedModel.commentBoxMap) {
const commentBox: CommentBox =
this.texeraGraph.getCommentBox(event.path[0] as string);
+ if (event.path.length === 1 &&
event.changes.keys.has("anchoredOperatorID")) {
Review Comment:
Confirmed (0 events for anchor, detach and undo). Fixed in 5b2454019: the
anchor observer now emits on a new `commentBoxAnchorChangedSubject`, for local
changes, co-editors, undo and redo alike, and `workflowChanged()` merges its
stream. A spec counts one change each for anchor, detach and the undo.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]