-
Notifications
You must be signed in to change notification settings - Fork 12k
feat: limit badges to 2 with hover/click popover in UserListTable #26556
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2a44e95
feat: limit badges to 2 with hover tooltip in UserListTable
devin-ai-integration[bot] 9c1a82c
refactor: reuse LimitedBadges component with clickable popover for mo…
devin-ai-integration[bot] 9014057
refactor: move LimitedBadges to components/ui with hover+click support
devin-ai-integration[bot] e89e426
Merge branch 'main' into devin/user-table-badge-limit-1767805886
eunjae-lee a10e43b
refactor: fix Biome lint issues in LimitedBadges and UserListTable
devin-ai-integration[bot] e12b2b2
fix: add proper types for filterType and getFacetedUniqueValues
devin-ai-integration[bot] 0cadeae
Merge branch 'main' into devin/user-table-badge-limit-1767805886
eunjae-lee d15d3ed
add vertical gap
eunjae-lee 92a879f
fix: address code review feedback for LimitedBadges
devin-ai-integration[bot] c2b8c5f
refactor: remove id from BadgeItem type, use label as key
devin-ai-integration[bot] 1daaac4
refactor: use index for key instead of label in LimitedBadges
devin-ai-integration[bot] 5fc74cf
Revert "refactor: use index for key instead of label in LimitedBadges"
eunjae-lee a827ea8
Merge branch 'main' into devin/user-table-badge-limit-1767805886
eunjae-lee 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,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}> | ||||||||||||||
| {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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Using Prompt for AI agents
Suggested change
|
||||||||||||||
| {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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
P2: Using
item.labelas 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