Skip to content

Commit

Permalink
fix: Rearrange the mainactivity to left
Browse files Browse the repository at this point in the history
  • Loading branch information
srvEq committed Feb 11, 2025
1 parent 3527344 commit 04430a7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
53 changes: 40 additions & 13 deletions components/canvas/hooks/useNodeDrag.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { moveVertice, moveVerticeRightOfTarget } from "@/services/graphApi";
import {
moveVertice,
moveVerticeLeftOfTarget,
moveVerticeRightOfTarget,
} from "@/services/graphApi";
import { notifyOthers } from "@/services/notifyOthers";
import { NodeDataCommon } from "@/types/NodeData";
import { NodeTypes } from "@/types/NodeTypes";
Expand Down Expand Up @@ -77,11 +81,7 @@ export const useNodeDrag = () => {
moveNode.mutate({
nodeId: node.id,
targetId: target?.id ?? "",
position:
node.type === NodeTypes.mainActivity &&
target?.type === NodeTypes.mainActivity
? Position.Right
: Position.Bottom,
position: target ? getPosition(node, target) : Position.Bottom,
includeChildren: target ? includeChildren(node, target) : false,
});
setTarget(undefined);
Expand Down Expand Up @@ -111,13 +111,25 @@ export const useNodeDrag = () => {
includeChildren: boolean;
}) => {
dispatch.setSnackMessage("⏳ Moving card...");
return position === Position.Bottom
? moveVertice(
{ vertexToMoveId: nodeId, vertexDestinationParentId: targetId },
projectId,
includeChildren
)
: moveVerticeRightOfTarget({ vertexId: nodeId }, targetId, projectId);
if (position === Position.Right) {
return moveVerticeRightOfTarget(
{ vertexId: nodeId },
targetId,
projectId
);
}
if (position === Position.Left) {
return moveVerticeLeftOfTarget(
{ vertexId: nodeId },
targetId,
projectId
);
}
return moveVertice(
{ vertexToMoveId: nodeId, vertexDestinationParentId: targetId },
projectId,
includeChildren
);
},
{
onSuccess: () => {
Expand Down Expand Up @@ -145,6 +157,21 @@ export const useNodeDrag = () => {
return false;
};

const getPosition = (
source: Node<NodeDataCommon>,
target: Node<NodeDataCommon>
) => {
if (
source.type === NodeTypes.mainActivity &&
target?.type === NodeTypes.mainActivity
) {
return (source.data?.order ?? 0) > (target.data?.order ?? 0)
? Position.Left
: Position.Right;
}
return Position.Bottom;
};

return {
onNodeDragStart,
onNodeDrag,
Expand Down
10 changes: 10 additions & 0 deletions services/graphApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ export const moveVerticeRightOfTarget = (
data
).then((r) => r.data);

export const moveVerticeLeftOfTarget = (
data: { vertexId: string },
targetId: string,
projectId: string
): Promise<unknown> =>
BaseAPIServices.put(
`${baseUrl}/graph/${projectId}/vertices/${targetId}/left`,
data
).then((r) => r.data);

export const mergeVertices = (
data: { fromVertexId: string; toVertexId: string },
projectId: string
Expand Down

0 comments on commit 04430a7

Please sign in to comment.