Skip to content

Commit

Permalink
cleaned, tested + changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalabbad committed Jan 13, 2025
1 parent c2afbcb commit 756d480
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 24 deletions.
1 change: 1 addition & 0 deletions changelog/5431.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed text overflow when there is too many options when selecting a relationship with a hierarchical model
4 changes: 2 additions & 2 deletions frontend/app/src/entities/ipam/ip-namespace-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ const IpNamespaceSelectorContent = ({ namespaces }: IpNamespaceSelectorContentPr
{selectedNamespace?.display_label ?? defaultNamespace?.display_label}
</ComboboxTrigger>

<ComboboxContent align="start">
<ComboboxList fitTriggerWidth={false} className="max-w-md">
<ComboboxContent align="start" fitTriggerWidth={false}>
<ComboboxList className="max-w-md">
{namespaces.map((namespace) => (
<ComboboxItem
key={namespace.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,41 @@ describe("RelationshipHierarchicalComboboxList", () => {
expect(onSelect).toHaveBeenCalledOnce();
expect(onSelect).toHaveBeenCalledWith(childRelationships[1]);
});

it("displays load more button when there are more results", async () => {
// GIVEN
const manyRelationships = Array.from({ length: 20 }, (_, i) => ({
id: `test-id-${i}`,
display_label: `Test Relationship ${i}`,
__typename: rootSchema.kind,
}));
vi.mocked(getRelationships).mockResolvedValue(manyRelationships);

// WHEN
const component = render(
<RelationshipHierarchicalComboboxList peer={rootSchema.kind} onSelect={vi.fn()} />
);

// THEN
await expect.element(component.getByRole("option", { name: "Load more" })).toBeVisible();
});

it("shows scrollbar when there are many options", async () => {
// GIVEN
const manyRelationships = Array.from({ length: 30 }, (_, i) => ({
id: `test-id-${i}`,
display_label: `Test Relationship ${i}`,
__typename: rootSchema.kind,
}));
vi.mocked(getRelationships).mockResolvedValue(manyRelationships);

// WHEN
const component = render(
<RelationshipHierarchicalComboboxList peer={rootSchema.kind} onSelect={vi.fn()} />
);

// THEN
const listbox = component.getByRole("listbox");
expect(listbox.element().scrollHeight).toBeGreaterThan(listbox.element().clientHeight);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ const HierarchicalExplorer = ({

return (
<Command
style={{
maxHeight: "min(var(--radix-popover-content-available-height), 300px)",
width: "var(--radix-popover-trigger-width)",
}}
shouldFilter={false}
onKeyDown={(e: React.KeyboardEvent) => {
if (search.length) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export default function BreadcrumbBranchSelector({
{value}
</ComboboxTrigger>

<ComboboxContent align="start">
<ComboboxList fitTriggerWidth={false}>
<ComboboxContent align="start" fitTriggerWidth={false}>
<ComboboxList>
<CommandEmpty>No branch found.</CommandEmpty>
{branches.map((branch) => {
const branchUrl = constructPath(`/branches/${branch.name}`);
Expand Down
31 changes: 16 additions & 15 deletions frontend/app/src/shared/components/ui/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,33 @@ export const ComboboxTrigger = React.forwardRef<HTMLButtonElement, ComboboxTrigg

export const ComboboxContent = React.forwardRef<
React.ElementRef<typeof PopoverContent>,
React.ComponentPropsWithoutRef<typeof PopoverContent>
>(({ className, ...props }, ref) => {
React.ComponentPropsWithoutRef<typeof PopoverContent> & { fitTriggerWidth?: boolean }
>(({ className, fitTriggerWidth = true, style, ...props }, ref) => {
return (
<PopoverContent ref={ref} className={classNames("p-0", className)} portal={false} {...props} />
<PopoverContent
ref={ref}
className={classNames("p-0", className)}
portal={false}
style={{
...(fitTriggerWidth
? { width: "var(--radix-popover-trigger-width)" }
: { minWidth: "var(--radix-popover-trigger-width)" }),
...style,
}}
{...props}
/>
);
});

export const ComboboxList = React.forwardRef<
React.ElementRef<typeof CommandList>,
React.ComponentPropsWithoutRef<typeof CommandList> & {
fitTriggerWidth?: boolean;
shouldFilter?: boolean;
onValueChange?: (search: string) => void;
}
>(({ fitTriggerWidth = true, style, shouldFilter, autoFocus, onValueChange, ...props }, ref) => {
>(({ shouldFilter, autoFocus, onValueChange, ...props }, ref) => {
return (
<Command
style={{
maxHeight: "min(var(--radix-popover-content-available-height), 300px)",
...(fitTriggerWidth
? { width: "var(--radix-popover-trigger-width)" }
: { minWidth: "var(--radix-popover-trigger-width)" }),
...style,
}}
shouldFilter={shouldFilter}
>
<Command shouldFilter={shouldFilter}>
<CommandInput placeholder="Filter..." autoFocus={autoFocus} onValueChange={onValueChange} />
<CommandList ref={ref} {...props} />
</Command>
Expand Down
5 changes: 4 additions & 1 deletion frontend/app/src/shared/components/ui/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export const CommandList = React.forwardRef<
>(({ className, ...props }, ref) => (
<CommandPrimitive.List
ref={ref}
className={classNames("flex-grow p-2 rounded-md overflow-y-auto overflow-x-hidden", className)}
className={classNames(
"max-h-[300px] flex-grow p-2 rounded-md overflow-y-auto overflow-x-hidden",
className
)}
asChild
{...props}
/>
Expand Down

0 comments on commit 756d480

Please sign in to comment.