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
108 changes: 108 additions & 0 deletions apps/web/components/ui/LimitedBadges.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"use client";

import useMediaQuery from "@calcom/lib/hooks/useMediaQuery";
import { Badge } from "@calcom/ui/components/badge";
import { Button } from "@calcom/ui/components/button";
import { Popover, PopoverContent, PopoverTrigger } from "@calcom/ui/components/popover";
import { useCallback, useMemo, useState, useEffect } from "react";

const MAX_VISIBLE_BADGES = 2;

type BadgeItem = {
label: string;
variant?:
| "default"
| "warning"
| "orange"
| "success"
| "green"
| "gray"
| "blue"
| "red"
| "error"
| "grayWithoutHover"
| "purple";
onClick?: () => void;
};

type LimitedBadgesProps = {
items: BadgeItem[];
maxVisible?: number;
className?: string;
};

function LimitedBadges({
items,
maxVisible = MAX_VISIBLE_BADGES,
className,
}: LimitedBadgesProps): JSX.Element | null {
const [isOpen, setIsOpen] = useState(false);
const isMobile = useMediaQuery("(max-width: 768px)");

const { visibleItems, hiddenItems } = useMemo(
() => ({
visibleItems: items.slice(0, maxVisible),
hiddenItems: items.slice(maxVisible),
}),
[items, maxVisible]
);

const handleMouseEnter = useCallback(() => {
if (!isMobile) {
setIsOpen(true);
}
}, [isMobile]);

const handleMouseLeave = useCallback(() => {
if (!isMobile) {
setIsOpen(false);
}
}, [isMobile]);

if (items.length === 0) return null;

const hasHiddenItems = hiddenItems.length > 0;

return (
<div className={`flex flex-wrap items-center gap-x-1 gap-y-1 ${className || ""}`}>
{visibleItems.map((item, index) => (
<Badge key={item.label} variant={item.variant || "gray"} onClick={item.onClick}>
{item.label}
</Badge>
))}
{hasHiddenItems && (
<Popover open={isOpen} onOpenChange={setIsOpen}>
<PopoverTrigger asChild>
<Button
color="minimal"
className="h-auto p-0 border-0 hover:border-0"
aria-label={`Show ${hiddenItems.length} more items`}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}>
<Badge variant="gray">+{hiddenItems.length}</Badge>
</Button>
</PopoverTrigger>
<PopoverContent
side="bottom"
align="start"
className="w-fit p-2"
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}>
<div className="flex flex-col gap-1">
{hiddenItems.map((item, index) => (
<span
key={item.label}
className="text-default cursor-pointer text-sm hover:text-emphasis">
{item.label}
</span>
))}
Comment on lines +91 to +98
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Hidden items lose onClick functionality in the popover.

Items in the overflow popover have cursor-pointer styling but no onClick handler attached, even though BadgeItem supports an optional onClick. This creates inconsistent behavior where visible items are clickable but hidden items are not.

Proposed fix
             <div className="flex flex-col gap-1">
               {hiddenItems.map((item, index) => (
                 <span
-                  key={item.label}
-                  className="text-default cursor-pointer text-sm hover:text-emphasis">
+                  key={`${item.label}-${index}`}
+                  role={item.onClick ? "button" : undefined}
+                  onClick={item.onClick}
+                  className={`text-default text-sm hover:text-emphasis ${item.onClick ? "cursor-pointer" : ""}`}>
                   {item.label}
                 </span>
               ))}
             </div>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className="flex flex-col gap-1">
{hiddenItems.map((item, index) => (
<span
key={item.label}
className="text-default cursor-pointer text-sm hover:text-emphasis">
{item.label}
</span>
))}
<div className="flex flex-col gap-1">
{hiddenItems.map((item, index) => (
<span
key={`${item.label}-${index}`}
role={item.onClick ? "button" : undefined}
onClick={item.onClick}
className={`text-default text-sm hover:text-emphasis ${item.onClick ? "cursor-pointer" : ""}`}>
{item.label}
</span>
))}
</div>
🤖 Prompt for AI Agents
In `@apps/web/components/ui/LimitedBadges.tsx` around lines 91 - 98, Hidden items
rendered inside the popover lose click behavior because the span uses only
item.label and never attaches the optional onClick from the BadgeItem shape;
update the render in LimitedBadges so each hidden item forwards its onClick
(e.g., use item.onClick or render the existing BadgeItem component) and keep the
cursor-pointer/hover styles, ensuring the element uses key={item.label} (or key
fallback) and calls item.onClick when present to restore consistent clickable
behavior between visible and hidden badges.

</div>
</PopoverContent>
</Popover>
)}
</div>
);
}

export { LimitedBadges };
export type { BadgeItem };
52 changes: 8 additions & 44 deletions apps/web/modules/insights/components/ResponseValueCell.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,24 @@
import { useId } from "react";

import { Badge } from "@calcom/ui/components/badge";
import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
HoverCardPortal,
} from "@calcom/ui/components/hover-card";
import { LimitedBadges } from "@calcom/web/components/ui/LimitedBadges";

import { CellWithOverflowX } from "./CellWithOverflowX";

export function ResponseValueCell({
optionMap,
values,
rowId,
}: {
optionMap: Record<string, string>;
values: string[];
rowId: number;
}) {
const cellId = useId();
}): JSX.Element {
if (values.length === 0) return <div className="h-6 w-[200px]" />;

return (
<CellWithOverflowX className="flex w-[200px] gap-1">
{values.length > 2 ? (
<>
{values.slice(0, 2).map((id: string, i: number) => (
<Badge key={`${cellId}-${i}-${rowId}`} variant="gray">
{optionMap[id] ?? id}
</Badge>
))}
<HoverCard>
<HoverCardTrigger>
<Badge variant="gray">+{values.length - 2}</Badge>
</HoverCardTrigger>
<HoverCardPortal>
<HoverCardContent side="bottom" align="start" className="w-fit">
<div className="flex flex-col gap-1">
{values.slice(2).map((id: string, i: number) => (
<span key={`${cellId}-overflow-${i}-${rowId}`} className="text-default text-sm">
{optionMap[id] ?? id}
</span>
))}
</div>
</HoverCardContent>
</HoverCardPortal>
</HoverCard>
</>
) : (
values.map((id: string, i: number) => (
<Badge key={`${cellId}-${i}-${rowId}`} variant="gray">
{optionMap[id] ?? id}
</Badge>
))
)}
<LimitedBadges
items={values.map((id) => ({
label: optionMap[id] ?? id,
variant: "gray" as const,
}))}
/>
</CellWithOverflowX>
);
}
1 change: 0 additions & 1 deletion apps/web/modules/insights/hooks/useInsightsColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ export const useInsightsColumns = ({
<ResponseValueCell
optionMap={optionMap}
values={Array.isArray(result.data) ? result.data : [result.data]}
rowId={info.row.original.id}
/>
)
);
Expand Down
Loading
Loading