Skip to content

Commit 401b8a6

Browse files
authored
Merge pull request #79 from projectsveltos/fix-bug
fix bug matching clusters
2 parents 3bb3f2e + 9544cab commit 401b8a6

File tree

8 files changed

+147
-120
lines changed

8 files changed

+147
-120
lines changed

src/lib/components/ui/failed-flag.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
TooltipTrigger,
1111
} from "@/lib/components/ui/tooltip";
1212

13-
export const FailedFlag = ({ msg }: { msg?: string | undefined | null }) => {
13+
14+
export const FailedFlag = ({ msg }: { msg?: string | undefined | null}) => {
1415
return (
1516
<>
1617
<Tooltip>
@@ -20,17 +21,19 @@ export const FailedFlag = ({ msg }: { msg?: string | undefined | null }) => {
2021
<Icons.k8s className={"h-6 w-6 animate-pulse"} />
2122
</AvatarRectFallback>
2223
</AvatarRectangle>
24+
2325
</TooltipTrigger>
2426
<TooltipContent>
2527
<div className={"inline-flex items-baseline"}>
2628
<ServerCrash className={"w-3 h-3 mx-1 mt-1"} />
2729
<p>Unhealthy</p>
2830
</div>
31+
2932
<br />
3033

3134
{msg && <p className={"text-muted-foreground w-24"}>{msg}</p>}
3235
</TooltipContent>
3336
</Tooltip>
3437
</>
3538
);
36-
};
39+
};

src/modules/clusters/cluster-information/ClusterInfoById.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export function ClusterInfoById() {
4343
{InfoQuery.isSuccess && InfoQuery.data?.managedClusters && (
4444
<ClusterHeading
4545
name={InfoQuery.data.managedClusters[0].name}
46-
status={InfoQuery.data.managedClusters[0]?.clusterInfo.ready}
46+
ready={InfoQuery.data.managedClusters[0]?.clusterInfo.ready}
47+
failureMsg={InfoQuery.data.managedClusters[0]?.clusterInfo.failureMessage}
4748
namespace={InfoQuery.data.managedClusters[0].namespace}
4849
version={InfoQuery.data.managedClusters[0]?.clusterInfo.version}
4950
/>

src/modules/clusters/cluster-information/components/clusterHeading.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Button } from "@/lib/components/ui/button";
2-
import { ChevronLeft } from "lucide-react";
2+
import { Check, ChevronLeft } from "lucide-react";
33
import { Badge } from "@/lib/components/ui/badge";
44
import { useNavigate } from "react-router-dom";
55
import { Icons } from "@/lib/components/icons";
@@ -8,17 +8,19 @@ import { RefreshButton } from "@/lib/components/ui/RefreshButton";
88
type ClusterHeadingProps = {
99
name: string;
1010
version?: string;
11-
status?: boolean;
11+
ready?: boolean;
1212
namespace?: string;
1313
hideDetails?: boolean;
14+
failureMsg?: string | null;
1415
};
1516

1617
export const ClusterHeading = ({
1718
name,
1819
version,
19-
status,
20+
ready,
2021
hideDetails,
2122
namespace,
23+
failureMsg
2224
}: ClusterHeadingProps) => {
2325
const navigate = useNavigate();
2426
return (
@@ -53,10 +55,21 @@ export const ClusterHeading = ({
5355
{!hideDetails && (
5456
<Badge
5557
variant="outline"
56-
className={`ml-auto sm:ml-0 ${status ? "bg-main-500" : "bg-red-500"} flex items-center text-white`}
58+
className={`ml-auto sm:ml-0 ${failureMsg ?"bg-red-500": "bg-main-500" } flex items-center text-white`}
5759
>
5860
<Icons.k8s className="w-4 h-4 mr-1" />
59-
{status ? "Healthy" : "Failed"}
61+
{failureMsg ?"Unhealthy": "Healthy" }
62+
</Badge>
63+
64+
65+
)}
66+
{!hideDetails && (
67+
<Badge
68+
variant="outline"
69+
className={`ml-auto sm:ml-0 ${ready ? "bg-green-500" : "bg-yellow-400"} flex items-center text-white`}
70+
>
71+
<Check className="w-4 h-4 mr-1" />
72+
{ready ? "Ready" : "Unready"}
6073
</Badge>
6174
)}
6275

src/modules/clusters/clusters-list/components/ClusterCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const ClusterCard = ({
2929
labels,
3030
onClick,
3131
failureMsg,
32-
status,
32+
3333
}: ClusterCardProps) => {
3434
const labelEntries = Object.entries(labels || {});
3535
const displayEntries = labelEntries.slice(0, appConfig.maxBadges);
@@ -43,7 +43,7 @@ export const ClusterCard = ({
4343
onClick={onClick}
4444
>
4545
<div className=" flex items-center space-x-4 rounded-md p-4">
46-
{status ? <ReadyFlag /> : <FailedFlag msg={failureMsg} />}
46+
{failureMsg ?<FailedFlag msg={failureMsg} />: <ReadyFlag /> }
4747
<div className="flex-1 space-y-1">
4848
<p className="text-sm font-medium leading-none">
4949
{name}

src/modules/profiles/profile-information/ProfileInformation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function ProfileInformation() {
2727
</div>
2828
<div className="col-span-6">
2929
<ProfileSpecCard spec={data.spec} />
30-
<MatchingClusterTable data={data.matchingClusters} />
30+
<MatchingClusterTable data={data?.matchingClusters??[]} />
3131
</div>
3232
</div>
3333
</div>

src/modules/profiles/profile-information/components/ClusterTable/MatchingClusterTable.tsx

Lines changed: 115 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
TableRow,
88
} from "@/lib/components/ui/table";
99
import { Badge } from "@/lib/components/ui/badge";
10-
import { ChevronDown, ChevronRight, CircleEqual } from "lucide-react";
11-
import React, { useState } from "react";
10+
import { Archive, ChevronDown, ChevronRight, CircleEqual } from "lucide-react";
11+
import React, { Fragment, useState } from "react";
1212
import { cn } from "@/lib/utils";
1313
import {
1414
Card,
@@ -22,8 +22,8 @@ import { MatchingCluster } from "@/types/profile.types";
2222
import { FailureMessage } from "@/lib/components/ui/failureMessage";
2323

2424
export default function MatchingClusterTable({
25-
data,
26-
}: {
25+
data,
26+
}: {
2727
data: MatchingCluster[];
2828
}) {
2929
const [openAccordions, setOpenAccordions] = useState<number[]>([]);
@@ -47,113 +47,123 @@ export default function MatchingClusterTable({
4747
</CardDescription>
4848
</CardHeader>
4949
<CardContent>
50-
<ScrollArea className=" h-96 rounded-md border p-4">
51-
<Table>
52-
<TableHeader>
53-
<TableRow>
54-
<TableHead className="w-[50px]"></TableHead>
55-
<TableHead>Cluster Name</TableHead>
56-
<TableHead>Namespace</TableHead>
57-
<TableHead>Status</TableHead>
58-
</TableRow>
59-
</TableHeader>
60-
<TableBody>
61-
{data?.map((cluster, index) => (
62-
<React.Fragment key={index}>
63-
<TableRow
64-
onClick={() => toggleAccordion(index)}
65-
className="cursor-pointer hover:bg-muted/50"
66-
>
67-
<TableCell>
68-
{openAccordions.includes(index) ? (
69-
<ChevronDown className="h-4 w-4" />
70-
) : (
71-
<ChevronRight className="h-4 w-4" />
72-
)}
73-
</TableCell>
74-
<TableCell>{cluster.cluster.name}</TableCell>
75-
<TableCell>
76-
<Badge variant={"outline"}>
77-
{cluster.cluster.namespace}
78-
</Badge>
79-
</TableCell>
80-
<TableCell>
81-
{cluster.clusterFeatureSummaries.some(
82-
(feature) => feature.failureMessage,
83-
) ? (
84-
<Badge variant={"destructive"}>Failed</Badge>
85-
) : (
86-
<Badge variant={"success"}> Provisioned</Badge>
87-
)}
88-
</TableCell>
89-
</TableRow>
90-
<TableRow
91-
className={cn(
92-
"bg-muted/50 transition-all",
93-
openAccordions.includes(index) ? "table-row" : "hidden",
94-
)}
95-
>
96-
<TableCell colSpan={4} className="p-0">
97-
<div
98-
className={cn(
99-
"grid transition-all",
100-
openAccordions.includes(index)
101-
? "grid-rows-[1fr]"
102-
: "grid-rows-[0fr]",
50+
<ScrollArea className={data.length === 0?"":" h-96"+"rounded-md border p-4"}>
51+
{data.length === 0 ? (
52+
<span className={"flex flex-col items-center justify-center h-full mt-4"}>
53+
<Archive className="h-12 w-12 text-muted-foreground" />
54+
<div className="flex justify-center items-center h-full">
55+
56+
<p className="text-muted-foreground mt-2">No matching clusters found.</p>
57+
</div>
58+
</span>
59+
) : (
60+
<Table>
61+
<TableHeader>
62+
<TableRow>
63+
<TableHead className="w-[50px]"></TableHead>
64+
<TableHead>Cluster Name</TableHead>
65+
<TableHead>Namespace</TableHead>
66+
<TableHead>Status</TableHead>
67+
</TableRow>
68+
</TableHeader>
69+
<TableBody>
70+
{data.map((cluster, index) => (
71+
<Fragment key={index}>
72+
<TableRow
73+
onClick={() => toggleAccordion(index)}
74+
className="cursor-pointer hover:bg-muted/50"
75+
>
76+
<TableCell>
77+
{openAccordions.includes(index) ? (
78+
<ChevronDown className="h-4 w-4" />
79+
) : (
80+
<ChevronRight className="h-4 w-4" />
10381
)}
104-
>
105-
<div className="overflow-hidden">
106-
<Table>
107-
<TableHeader>
108-
<TableRow>
109-
<TableHead>Feature ID</TableHead>
110-
<TableHead>Status</TableHead>
111-
<TableHead>Failure Message</TableHead>
112-
</TableRow>
113-
</TableHeader>
114-
<TableBody>
115-
{cluster.clusterFeatureSummaries.map(
116-
(feature, featureIndex) => (
117-
<TableRow
118-
className={
119-
feature.failureMessage != null
120-
? "bg-red-200 dark:bg-red-500"
121-
: ""
122-
}
123-
key={featureIndex}
124-
>
125-
<TableCell>{feature.featureID}</TableCell>
126-
<TableCell
127-
className={
128-
"break-words whitespace-normal"
129-
}
130-
>
131-
{feature.status}
132-
</TableCell>
133-
<TableCell
82+
</TableCell>
83+
<TableCell>{cluster.cluster.name}</TableCell>
84+
<TableCell>
85+
<Badge variant={"outline"}>
86+
{cluster.cluster.namespace}
87+
</Badge>
88+
</TableCell>
89+
<TableCell>
90+
{cluster.clusterFeatureSummaries.some(
91+
(feature) => feature.failureMessage,
92+
) ? (
93+
<Badge variant={"destructive"}>Failed</Badge>
94+
) : (
95+
<Badge variant={"success"}> Provisioned</Badge>
96+
)}
97+
</TableCell>
98+
</TableRow>
99+
<TableRow
100+
className={cn(
101+
"bg-muted/50 transition-all",
102+
openAccordions.includes(index) ? "table-row" : "hidden",
103+
)}
104+
>
105+
<TableCell colSpan={4} className="p-0">
106+
<div
107+
className={cn(
108+
"grid transition-all",
109+
openAccordions.includes(index)
110+
? "grid-rows-[1fr]"
111+
: "grid-rows-[0fr]",
112+
)}
113+
>
114+
<div className="overflow-hidden">
115+
<Table>
116+
<TableHeader>
117+
<TableRow>
118+
<TableHead>Feature ID</TableHead>
119+
<TableHead>Status</TableHead>
120+
<TableHead>Failure Message</TableHead>
121+
</TableRow>
122+
</TableHeader>
123+
<TableBody>
124+
{cluster.clusterFeatureSummaries.map(
125+
(feature, featureIndex) => (
126+
<TableRow
134127
className={
135-
"break-words whitespace-normal"
128+
feature.failureMessage != null
129+
? "bg-red-200 dark:bg-red-500"
130+
: ""
136131
}
132+
key={featureIndex}
137133
>
138-
<FailureMessage
139-
msg={feature.failureMessage}
140-
/>
141-
</TableCell>
142-
</TableRow>
143-
),
144-
)}
145-
</TableBody>
146-
</Table>
134+
<TableCell>{feature.featureID}</TableCell>
135+
<TableCell
136+
className={
137+
"break-words whitespace-normal"
138+
}
139+
>
140+
{feature.status}
141+
</TableCell>
142+
<TableCell
143+
className={
144+
"break-words whitespace-normal"
145+
}
146+
>
147+
<FailureMessage
148+
msg={feature.failureMessage}
149+
/>
150+
</TableCell>
151+
</TableRow>
152+
),
153+
)}
154+
</TableBody>
155+
</Table>
156+
</div>
147157
</div>
148-
</div>
149-
</TableCell>
150-
</TableRow>
151-
</React.Fragment>
152-
))}
153-
</TableBody>
154-
</Table>
158+
</TableCell>
159+
</TableRow>
160+
</Fragment>
161+
))}
162+
</TableBody>
163+
</Table>
164+
)}
155165
</ScrollArea>
156166
</CardContent>
157167
</Card>
158168
);
159-
}
169+
}

src/modules/profiles/profile-information/components/ProfileInfo/ProfileSpec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { FileSliders } from "lucide-react";
1010

1111
type ProfileSpecCardProps = {
1212
spec: {
13-
clusterSelector: {
13+
clusterSelector?: {
1414
matchLabels: {
1515
env: string;
1616
};
@@ -47,7 +47,7 @@ export const ProfileSpecCard = ({ spec }: ProfileSpecCardProps) => {
4747
<dt className="text-sm text-muted-foreground">Cluster Selector</dt>
4848
<dd className="font-medium">
4949
<Badge variant={"outline"}>
50-
{Object.entries(spec.clusterSelector.matchLabels).map(
50+
{Object.entries(spec.clusterSelector?.matchLabels ?? {}).map(
5151
([key, value]) => `${key}: ${value}`,
5252
)}
5353
</Badge>

src/modules/profiles/profiles-list/components/tier/TierCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export function TierCard({ tier }: { tier: Tier }) {
3232
<EllipsisVertical />
3333
</Button>
3434
</CardHeader>
35-
<CardContent className={"h-[500px] "}>
35+
<CardContent className={"h-[400px] "}>
3636
<ScrollArea
37-
className={"grid grid-cols-1 gap-4 h-[500px] overflow-auto"}
37+
className={"grid grid-cols-1 gap-4 h-[400px] overflow-auto"}
3838
>
3939
{tier?.profiles.map((profile, index) => (
4040
<div key={index} className={"flex items-center my-2"}>

0 commit comments

Comments
 (0)