Skip to content

Commit af72693

Browse files
committed
fix(config): address swimlane review comments
Avoid modifying the base shadcn hover-card by moving portaled content into a project wrapper used by the swimlane. Gate the config changes infinite query so table view does not issue the extra swimlane request, and clone fallback icons with the same className and forwarded props as normal icons.
1 parent b8dfc9e commit af72693

6 files changed

Lines changed: 68 additions & 17 deletions

File tree

src/api/query-hooks/useConfigChangesHooks.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ export function useGetConfigChangesByIDQuery(
174174

175175
export function useGetAllConfigsChangesInfiniteQuery({
176176
pageSize = 200,
177-
paramPrefix
177+
paramPrefix,
178+
enabled = true
178179
}: {
179180
pageSize?: number;
180181
paramPrefix?: string;
182+
enabled?: boolean;
181183
} = {}) {
182184
const showChangesFromDeletedConfigs = useShowDeletedConfigs();
183185
const { timeRangeValue } = useTimeRangeParams(
@@ -221,6 +223,7 @@ export function useGetAllConfigsChangesInfiniteQuery({
221223
lastPage.changes && lastPage.changes.length < pageSize
222224
? undefined
223225
: allPages.length,
224-
keepPreviousData: true
226+
keepPreviousData: true,
227+
enabled
225228
});
226229
}

src/components/Configs/Changes/ConfigChangesSwimlane.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ConfigChange } from "@flanksource-ui/api/types/configs";
22
import {
33
HoverCard,
4-
HoverCardContent,
54
HoverCardTrigger
65
} from "@flanksource-ui/components/ui/hover-card";
6+
import { PortaledHoverCardContent as HoverCardContent } from "@flanksource-ui/components/ui/portaled-hover-card";
77
import { Age } from "@flanksource-ui/ui/Age";
88
import { ChangeIcon } from "@flanksource-ui/ui/Icons/ChangeIcon";
99
import { relativeDateTime } from "@flanksource-ui/utils/date";

src/components/ui/hover-card.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ const HoverCardContent = React.forwardRef<
1111
React.ElementRef<typeof HoverCardPrimitive.Content>,
1212
React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>
1313
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
14-
<HoverCardPrimitive.Portal>
15-
<HoverCardPrimitive.Content
16-
ref={ref}
17-
align={align}
18-
sideOffset={sideOffset}
19-
className={cn(
20-
"z-50 w-64 origin-[--radix-hover-card-content-transform-origin] rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
21-
className
22-
)}
23-
{...props}
24-
/>
25-
</HoverCardPrimitive.Portal>
14+
<HoverCardPrimitive.Content
15+
ref={ref}
16+
align={align}
17+
sideOffset={sideOffset}
18+
className={cn(
19+
"z-50 w-64 origin-[--radix-hover-card-content-transform-origin] rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
20+
className
21+
)}
22+
{...props}
23+
/>
2624
));
2725
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName;
2826

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from "react";
2+
import * as HoverCardPrimitive from "@radix-ui/react-hover-card";
3+
4+
import { cn } from "@flanksource-ui/lib/utils";
5+
6+
const PortaledHoverCardContent = React.forwardRef<
7+
React.ElementRef<typeof HoverCardPrimitive.Content>,
8+
React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>
9+
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
10+
<HoverCardPrimitive.Portal>
11+
<HoverCardPrimitive.Content
12+
ref={ref}
13+
align={align}
14+
sideOffset={sideOffset}
15+
className={cn(
16+
"z-50 w-64 origin-[--radix-hover-card-content-transform-origin] rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
17+
className
18+
)}
19+
{...props}
20+
/>
21+
</HoverCardPrimitive.Portal>
22+
));
23+
PortaledHoverCardContent.displayName = HoverCardPrimitive.Content.displayName;
24+
25+
export { PortaledHoverCardContent };

src/pages/config/ConfigChangesPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ export function ConfigChangesPage() {
9292

9393
// Graph view: infinite query
9494
const infiniteQuery = useGetAllConfigsChangesInfiniteQuery({
95-
pageSize: parseInt(pageSize)
95+
pageSize: parseInt(pageSize),
96+
enabled: isGraphView
9697
});
9798

9899
// Initialize cursor from base data when live tail is turned on

src/ui/Icons/Icon.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IconType } from "@flanksource/icons";
22
import { IconMap as Icons } from "@flanksource/icons/mi";
33
import { isEmpty } from "lodash";
4+
import { cloneElement, isValidElement } from "react";
45

56
type IconMap = Record<string, string>;
67
export const aliases: IconMap = {
@@ -1005,7 +1006,30 @@ export function Icon({
10051006
const Icon = findIcon(name, secondary, iconWithColor);
10061007

10071008
if (!Icon || !Icon.SVG) {
1008-
return fallback ? (fallback as React.ReactElement) : null;
1009+
if (!fallback) {
1010+
return null;
1011+
}
1012+
1013+
if (isValidElement(fallback)) {
1014+
const fallbackElement = fallback as React.ReactElement<{
1015+
className?: string;
1016+
}>;
1017+
return (
1018+
<>
1019+
{prefix}{" "}
1020+
{cloneElement(fallbackElement, {
1021+
...props,
1022+
className: `inline-block fill-current object-center ${className} ${fallbackElement.props.className ?? ""}`
1023+
})}
1024+
</>
1025+
);
1026+
}
1027+
1028+
return (
1029+
<>
1030+
{prefix} {fallback}
1031+
</>
1032+
);
10091033
}
10101034

10111035
return (

0 commit comments

Comments
 (0)