forked from agentic-review-benchmarks/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Code Review Bench PR #26556 - feat: limit badges to 2 with hover/click popover in UserListTable #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ketkarameya
wants to merge
2
commits into
base_pr_26556_20260125_2421
from
corrupted_pr_26556_20260125_2421
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ))} | ||
| </div> | ||
| </PopoverContent> | ||
| </Popover> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export { LimitedBadges }; | ||
| export type { BadgeItem }; | ||
52 changes: 8 additions & 44 deletions
52
apps/web/modules/insights/components/ResponseValueCell.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
LimitedBadgescomponent acceptsonClickin eachBadgeItem, but only the visible badges wire uponClick. The hidden items rendered inside the popover are plain<span>elements with no click handler, despite havingcursor-pointerstyling that suggests they should be interactive.This is a functional regression in the teams column of
UserListTable, where clicking a team badge triggerstable.getColumn("teams")?.setFilterValue([team.name]). If a user has 3+ teams, the overflow teams in the popover won't be clickable to filter — breaking the existing click-to-filter behavior for those items.Was this helpful? React with 👍 / 👎