Skip to content
Draft
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
@@ -1,21 +1,20 @@
import type { ComponentProps, DragEvent } from "react";
import { useCallback, useMemo, useRef } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";

import { ComponentDetailsDialog } from "@/components/shared/Dialogs";
import { ComponentFavoriteToggle } from "@/components/shared/FavoriteComponentToggle";
import { useOutdatedComponents } from "@/components/shared/ManageComponent/hooks/useOutdatedComponents";
import { useFlagValue } from "@/components/shared/Settings/useFlags";
import { withSuspenseWrapper } from "@/components/shared/SuspenseWrapper";
import { Icon } from "@/components/ui/icon";
import { BlockStack, InlineStack } from "@/components/ui/layout";
import { InlineStack } from "@/components/ui/layout";
import { Skeleton } from "@/components/ui/skeleton";
import { Spinner } from "@/components/ui/spinner";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { Text } from "@/components/ui/typography";
import { useHydrateComponentReference } from "@/hooks/useHydrateComponentReference";
import { cn } from "@/lib/utils";
import { type ComponentReference, type TaskSpec } from "@/utils/componentSpec";
Expand Down Expand Up @@ -87,6 +86,8 @@ const ComponentMarkup = ({

// TODO: respect selected node as a starting point
const carousel = useRef(0);
const titleRef = useRef<HTMLSpanElement>(null);
const [isTruncated, setIsTruncated] = useState(false);
const { notifyNode, getNodeIdsByDigest, fitNodeIntoView } = useNodesOverlay();

const { spec, digest, url, name, published_by: author, owned } = component;
Expand All @@ -96,6 +97,25 @@ const ComponentMarkup = ({
[spec, url, name],
);

useEffect(() => {
const checkTruncation = () => {
if (titleRef.current) {
setIsTruncated(
titleRef.current.scrollWidth > titleRef.current.clientWidth,
);
}
};

checkTruncation();

const resizeObserver = new ResizeObserver(checkTruncation);
if (titleRef.current) {
resizeObserver.observe(titleRef.current);
}

return () => resizeObserver.disconnect();
}, [displayName]);

const isSubgraphSpec = isSubgraph(spec);

const onDragStart = useCallback(
Expand Down Expand Up @@ -217,7 +237,10 @@ const ComponentMarkup = ({
onMouseLeave={onMouseLeave}
onClick={onMouseClick}
>
<span className="truncate text-xs text-gray-800">
<span
ref={titleRef}
className="truncate text-xs text-gray-800"
>
{displayName}
</span>
{author && author.length > 0 && (
Expand All @@ -242,9 +265,11 @@ const ComponentMarkup = ({
</InlineStack>
</li>
</TooltipTrigger>
<TooltipContent side="right" sideOffset={8}>
{displayName}
</TooltipContent>
{isTruncated && (
<TooltipContent side="right" sideOffset={8}>
{displayName}
</TooltipContent>
)}
</Tooltip>
);
};
Expand Down