Skip to content
Merged
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
109 changes: 109 additions & 0 deletions apps/web/components/ui/LimitedBadges.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"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 } 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) => (
<Badge key={item.label} variant={item.variant || "gray"} onClick={item.onClick}>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Jan 9, 2026

Choose a reason for hiding this comment

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

P2: Using item.label as React key can cause duplicate key issues if multiple badges share the same label (e.g., two teams with the same name or attribute values with identical labels). Consider using a combination of label and index to ensure uniqueness.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/web/components/ui/LimitedBadges.tsx, line 69:

<comment>Using `item.label` as React key can cause duplicate key issues if multiple badges share the same label (e.g., two teams with the same name or attribute values with identical labels). Consider using a combination of label and index to ensure uniqueness.</comment>

<file context>
@@ -65,8 +65,8 @@ function LimitedBadges({
-      {visibleItems.map((item, index) => (
-        <Badge key={index} variant={item.variant || "gray"} onClick={item.onClick}>
+      {visibleItems.map((item) => (
+        <Badge key={item.label} variant={item.variant || "gray"} onClick={item.onClick}>
           {item.label}
         </Badge>
</file context>
Fix with Cubic

{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) => (
<span
key={item.label}
className="text-default cursor-pointer text-sm hover:text-emphasis"
onClick={item.onClick}>
Comment on lines +94 to +96
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Jan 9, 2026

Choose a reason for hiding this comment

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

P2: Using item.label as React key for hidden items has the same duplicate key issue as the visible badges. Consider using ${item.label}-${index} to ensure uniqueness while maintaining label-based stability.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/web/components/ui/LimitedBadges.tsx, line 94:

<comment>Using `item.label` as React key for hidden items has the same duplicate key issue as the visible badges. Consider using `${item.label}-${index}` to ensure uniqueness while maintaining label-based stability.</comment>

<file context>
@@ -89,9 +89,9 @@ function LimitedBadges({
+              {hiddenItems.map((item) => (
                 <span
-                  key={index}
+                  key={item.label}
                   className="text-default cursor-pointer text-sm hover:text-emphasis"
                   onClick={item.onClick}>
</file context>
Suggested change
key={item.label}
className="text-default cursor-pointer text-sm hover:text-emphasis"
onClick={item.onClick}>
{hiddenItems.map((item, index) => (
<span
key={`${item.label}-${index}`}
Fix with Cubic

{item.label}
</span>
))}
</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