Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/young-moments-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@serverlessworkflow/diagram-editor": patch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use minor
https://semver.org/#summary

Suggested change
"@serverlessworkflow/diagram-editor": patch
"@serverlessworkflow/diagram-editor": minor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be minor as well and please update the file name

---

Implementation of tooltip
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
*/

.dec-root {
--background: hsl(0 0% 100%);

--foreground: hsl(222.2 84% 4.9%);
Comment on lines +28 to +30

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use more specific names for these new variables, following the code style already here?

Suggested change
--background: hsl(0 0% 100%);
--foreground: hsl(222.2 84% 4.9%);
--tooltip-background: hsl(0 0% 100%);
--tooltip-foreground: hsl(222.2 84% 4.9%);


--sidebar: hsl(0 0% 98%);

--sidebar-foreground: hsl(240 5.3% 26.1%);
Expand All @@ -43,6 +47,10 @@
}

.dec-root.dark {
--background: hsl(222.2 84% 4.9%);

--foreground: hsl(210 40% 98%);
Comment on lines +50 to +52

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--background: hsl(222.2 84% 4.9%);
--foreground: hsl(210 40% 98%);
--tooltip-background: hsl(222.2 84% 4.9%);
--tooltip-foreground: hsl(210 40% 98%);


--sidebar: #2d3748;

--sidebar-foreground: hsl(240 4.8% 95.9%);
Expand All @@ -61,6 +69,10 @@
}

@theme inline {
--color-background: var(--background);

--color-foreground: var(--foreground);
Comment on lines +72 to +74

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-tooltip-background: var(--background);
--color-tooltip-foreground: var(--foreground);


--color-sidebar: var(--sidebar);

--color-sidebar-foreground: var(--sidebar-foreground);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,18 @@ function TooltipContent({
...props
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
return (
<TooltipPrimitive.Portal>
<TooltipPrimitive.Content
data-slot="tooltip-content"
sideOffset={sideOffset}
className={cn(
"dec:z-50 dec:w-fit dec:origin-(--radix-tooltip-content-transform-origin) dec:animate-in dec:rounded-md dec:bg-foreground dec:px-3 dec:py-1.5 dec:text-xs dec:text-balance dec:text-background dec:fade-in-0 dec:zoom-in-95 dec:data-[side=bottom]:slide-in-from-top-2 dec:data-[side=left]:slide-in-from-right-2 dec:data-[side=right]:slide-in-from-left-2 dec:data-[side=top]:slide-in-from-bottom-2 dec:data-[state=closed]:animate-out dec:data-[state=closed]:fade-out-0 dec:data-[state=closed]:zoom-out-95",
className,
)}
{...props}
>
{children}
<TooltipPrimitive.Arrow className="dec:z-50 dec:size-2.5 dec:translate-y-[calc(-50%_-_2px)] dec:rotate-45 dec:rounded-[2px] dec:bg-foreground dec:fill-foreground" />
</TooltipPrimitive.Content>
</TooltipPrimitive.Portal>
<TooltipPrimitive.Content

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw in the official implementation they use Tooltip.Portal (https://www.radix-ui.com/primitives/docs/components/tooltip#anatomy).
The docs say "When used, portals the content part into the body," and I can see this UI issue with selected edges. As you can see, the tooltip is under the edge.
Maybe the Portal can help with this, anyway I would follow the official examples.

Image

data-slot="tooltip-content"
sideOffset={sideOffset}
className={cn(
Comment thread
kumaradityaraj marked this conversation as resolved.
"dec:z-50 dec:w-fit dec:origin-(--radix-tooltip-content-transform-origin) dec:animate-in dec:rounded-sm dec:bg-foreground dec:px-1 dec:py-1 dec:text-[9px] dec:text-balance dec:text-background dec:fade-in-0 dec:zoom-in-95 dec:data-[side=bottom]:slide-in-from-top-2 dec:data-[side=left]:slide-in-from-right-2 dec:data-[side=right]:slide-in-from-left-2 dec:data-[side=top]:slide-in-from-bottom-2 dec:data-[state=closed]:animate-out dec:data-[state=closed]:fade-out-0 dec:data-[state=closed]:zoom-out-95",
className,
)}
{...props}
>
{children}
<TooltipPrimitive.Arrow className="dec:z-50 dec:size-2.5 dec:translate-y-[calc(-50%_-_2px)] dec:rotate-45 dec:rounded-[2px] dec:bg-foreground dec:fill-foreground" />
</TooltipPrimitive.Content>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useResolvedColorMode } from "../hooks/useResolvedColorMode";
import { SidebarProvider } from "@/components/ui/sidebar";
import { SidePanel } from "@/side-panel/SidePanel";
import { DiagramEditorErrorBoundary } from "./error-pages/DiagramEditorErrorBoundary";
import { TooltipProvider } from "@/components/ui/tooltip";

/**
* DiagramEditor component API
Expand Down Expand Up @@ -113,16 +114,18 @@ export const DiagramEditor = (props: DiagramEditorProps) => {
isReadOnly={props.isReadOnly}
locale={locale}
>
<SidebarProvider defaultOpen={false}>
<div className="dec-diagram-content">
<DiagramEditorContent
diagramRef={diagramRef}
diagramDivRef={diagramDivRef}
colorMode={resolvedColorMode}
/>
</div>
<SidePanel />
</SidebarProvider>
<TooltipProvider>
<SidebarProvider defaultOpen={false}>
<div className="dec-diagram-content">
<DiagramEditorContent
diagramRef={diagramRef}
diagramDivRef={diagramDivRef}
colorMode={resolvedColorMode}
/>
</div>
<SidePanel />
</SidebarProvider>
</TooltipProvider>
</DiagramEditorContextProvider>
</ReactFlowProvider>
</DiagramEditorErrorBoundary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
terminalNodeConfigMap,
} from "./taskNodeConfig";
import { getCallSubType, getListenSubType, getRunSubType } from "../../core";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { CircleAlert } from "lucide-react";

export const ReactFlowNodeTypes: RF.NodeTypes = {
Expand Down Expand Up @@ -94,19 +95,21 @@ function TaskNodeBadge({ badge, testId }: BadgeProps) {
const isUnknown = !KNOWN_BADGES.has(badge.toLowerCase());

if (isUnknown) {
/* TODO: instead of using the browser default to display tool tip like below, replace with tooltip component when we add it */
return (
<span
title={badge}
aria-label={`${t("aria.badge")} ${badge}`}
className="dec-task-node-badge-custom"
data-testid={`${testId}-custom`}
>
{badge}
</span>
<Tooltip>
<TooltipTrigger asChild>
<span
className="dec-task-node-badge-custom"
data-testid={`${testId}-custom`}
aria-label={`${t("aria.badge")} ${badge}`}
>
{badge}
</span>
</TooltipTrigger>
Comment thread
kumaradityaraj marked this conversation as resolved.
<TooltipContent>{badge}</TooltipContent>
</Tooltip>
);
}

return (
<span className="dec-task-node-badge" data-testid={testId}>
{badge}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
import { DEFAULT_NODE_SIZE } from "../../../src/react-flow/diagram/autoLayout";
import { en } from "../../../src/i18n/locales/en";
import { renderWithProviders } from "../../test-utils/render-helpers";
import { TooltipProvider } from "../../../src/components/ui/tooltip";
import userEvent from "@testing-library/user-event";

function testNode(
id: string,
Expand Down Expand Up @@ -256,19 +258,52 @@ describe("React Flow custom node types", () => {
}),
];
renderWithProviders(
<div>
<RF.ReactFlow
nodeTypes={ReactFlowNodeTypes}
nodes={nodesWithUnknownBadges}
edges={allEdges}
/>
</div>,
<TooltipProvider>
<div>
<RF.ReactFlow
nodeTypes={ReactFlowNodeTypes}
nodes={nodesWithUnknownBadges}
edges={allEdges}
/>
</div>
</TooltipProvider>,
);

const callBadge = screen.getByTestId("call-node-n1-badge-custom");
expect(callBadge).toBeInTheDocument();
expect(callBadge.textContent).toBe("customCall");
expect(callBadge).toHaveAttribute("title", "customCall");
Comment thread
kumaradityaraj marked this conversation as resolved.
});
Comment thread
kumaradityaraj marked this conversation as resolved.

it("should render the raw value as a custom badge for an unknown subtype and display it in the tooltip", async () => {
const user = userEvent.setup();

const nodesWithUnknownBadges = [
testNode("n1", GraphNodeType.Call, 100, "CallNode", {
call: "customCall",
}),
];

renderWithProviders(
<TooltipProvider>
<div>
<RF.ReactFlow
nodeTypes={ReactFlowNodeTypes}
nodes={nodesWithUnknownBadges}
edges={allEdges}
/>
</div>
</TooltipProvider>,
);

const callBadge = screen.getByTestId("call-node-n1-badge-custom");

expect(callBadge).toBeInTheDocument();
expect(callBadge).toHaveTextContent("customCall");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is already tested by the previous test

Suggested change
expect(callBadge).toHaveTextContent("customCall");


await user.hover(callBadge);

const tooltip = await screen.findByRole("tooltip");
expect(tooltip).toHaveTextContent("customCall");
});

it("should render while/compete badges on container nodes", () => {
Expand Down
Loading
Loading