Skip to content

Commit

Permalink
fix cluster info types
Browse files Browse the repository at this point in the history
  • Loading branch information
Safouene1 committed May 9, 2024
1 parent 902c1c9 commit 1859ac0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function App() {
toast.error(`Something went wrong: ${error.message}`);
}
},
staleTime: 10000,

refetchOnWindowFocus: "always",
},
});
Expand Down
15 changes: 10 additions & 5 deletions src/modules/clusters/cluster-information/ClusterInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ResourceTable } from "@/modules/clusters/cluster-information/components
import { ClusterConfig } from "@/modules/clusters/cluster-information/components/ClusterConfig";
import useClusterInfo from "@/modules/clusters/cluster-information/hooks/useClusterInfo";
import { useParams } from "react-router-dom";
import { ClusterType } from "@/types/cluster";
import { ClusterInfoType, ClusterType, Label } from "@/types/cluster";
import { useEffect, useState } from "react";

export const data = {
Expand Down Expand Up @@ -89,13 +89,17 @@ export const data = {

export function ClusterInfo() {
const { tab: type, name, namespace } = useParams();
const [infoData, setInfoData] = useState(null);
const [infoData, setInfoData] = useState<ClusterInfoType | null>(null);
const queries = useClusterInfo(namespace, name, type as ClusterType);

const [resourcesQuery, helmChartQuery, InfoQuery] = queries;
useEffect(() => {
if(resourcesQuery.isSuccess && helmChartQuery.isSuccess && InfoQuery.isSuccess){
setInfoData(InfoQuery.data.managedClusters[0])
if (
resourcesQuery.isSuccess &&
helmChartQuery.isSuccess &&
InfoQuery.isSuccess
) {
setInfoData(InfoQuery.data.managedClusters[0]);
}
}, [InfoQuery]);

Expand All @@ -111,6 +115,7 @@ export function ClusterInfo() {
<ClusterHeading
name={infoData.name}
status={infoData?.clusterInfo.ready}
namespace={infoData.namespace}
version={infoData?.clusterInfo.version}
/>
)}
Expand All @@ -119,7 +124,7 @@ export function ClusterInfo() {

<div className="grid auto-rows-max items-start gap-4 lg:gap-8">
{InfoQuery.isSuccess && infoData && (
<LabelsCard labels={infoData?.clusterInfo?.labels} />
<LabelsCard labels={infoData?.clusterInfo?.labels} />
)}
<ClusterConfig />
<Card x-chunk="dashboard-07-chunk-5">
Expand Down
22 changes: 10 additions & 12 deletions src/modules/clusters/cluster-information/components/LabelsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ type LabelsCardProps = {
export const LabelsCard = ({ labels }: LabelsCardProps) => {
useEffect(() => {
console.log("LabelsCard", labels);

}, [labels]);
const labelEntries = Object.entries(labels || {});
return (

<>
<div>
<Card x-chunk="dashboard-07-chunk-3">
Expand All @@ -28,16 +26,16 @@ export const LabelsCard = ({ labels }: LabelsCardProps) => {

<CardContent>
<div className="flex flex-wrap ">
{labelEntries.length>0 && labelEntries.map(([key, value]) => (
<Badge
key={key}
className={"m-2 p-2 rounded"}
variant="secondary"
>

<p>{`${key}: ${value}`}</p>
</Badge>
))}
{labelEntries.length > 0 &&
labelEntries.map(([key, value]) => (
<Badge
key={key}
className={"m-2 p-2 rounded"}
variant="secondary"
>
<p>{`${key}: ${value}`}</p>
</Badge>
))}
</div>
</CardContent>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ type ClusterHeadingProps = {
name: string;
version: string;
status: boolean;
namespace?: string;
};

export const ClusterHeading = ({
name,
version,
status,
namespace,
}: ClusterHeadingProps) => {
const navigate = useNavigate();
return (
Expand All @@ -37,13 +39,20 @@ export const ClusterHeading = ({
>
version : {version}
</Badge>
<Badge
variant="outline"
className="ml-auto sm:ml-0 flex items-center "
>
namespace : {namespace}
</Badge>
<Badge
variant="outline"
className={`ml-auto sm:ml-0 ${status ? "bg-main-500" : "bg-red-500"} flex items-center text-white`}
>
<Icons.k8s className="w-4 h-4 mr-1" />
{status ? "Healthy" : "Failed"}
</Badge>

<div className="hidden items-center gap-2 md:ml-auto md:flex">
<Button variant="outline" size="sm">
<RefreshCcw className={"w-3 h-3 mx-1"} /> Refresh
Expand Down
16 changes: 10 additions & 6 deletions src/modules/clusters/clusters-list/ClustersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ export default function ClustersPage() {
const [currentPage, setCurrentPage] = useState<number>(() => {
return urlPage ? parseInt(urlPage) : defaultPage;
});
const { data, isLoading, isError, isSuccess, error, refetch } = useClusters(
currentTab,
currentPage,
searchParams,
);
const {
data,
isLoading,
isPreviousData,
isError,
isSuccess,
error,
refetch,
} = useClusters(currentTab, currentPage, searchParams);
const handleTabChange = (value: ClusterType) => {
setCurrentTab(value);
navigate(`/clusters/${value}/${currentPage}`);
Expand Down Expand Up @@ -65,7 +69,7 @@ export default function ClustersPage() {
</TabsList>
</Tabs>
<SearchFields updateQueryParams={updateQueryParams} />
{isLoading && <LoadingCards />}
{(isLoading || isPreviousData) && <LoadingCards />}
{isError && <ErrorQuery name={"clusters"} error={error} />}
{isSuccess && data && (
<>
Expand Down
17 changes: 6 additions & 11 deletions src/types/cluster.d.ts → src/types/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
export type Label = {
id?: number;
designation: string;
};

export type SveltosClusterType = "SveltosCluster";
export type ClusterApiType = "ClusterAPI";
export type ClusterType = SveltosClusterType | ClusterApiType;

interface Label {
export interface Label {
[key: string]: string;
}

interface ClusterInfo {
export interface ClusterInfoType {
namespace: string;
name: string;
clusterInfo: {
labels?: Label[];
version?: string;
ready?: boolean;
labels: Label[];
version: string;
ready: boolean;
failureMessage?: string | null;
};
}

export type ClusterListResponse = {
totalClusters: number;
managedClusters: ClusterInfo[];
managedClusters: ClusterInfoType[];
};

0 comments on commit 1859ac0

Please sign in to comment.