Skip to content

Commit

Permalink
clusteer stattus update
Browse files Browse the repository at this point in the history
  • Loading branch information
tulsiojha committed Sep 5, 2024
1 parent 3d035b3 commit 1aa7b16
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
29 changes: 23 additions & 6 deletions src/apps/console/hooks/use-cluster-status-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from 'react';
Expand Down Expand Up @@ -36,10 +37,13 @@ const ClusterStatusProvider = ({ children }: { children: ReactNode }) => {
const listCluster = useCallback(async () => {
try {
const cl = await api.listAllClusters();
const parsed = parseNodes(cl.data).reduce((acc, c) => {
acc[c.metadata.name] = c;
return acc;
}, {} as { [key: string]: ExtractNodeType<IByocClusters> });
const parsed = parseNodes(cl.data).reduce(
(acc, c) => {
acc[c.metadata.name] = c;
return acc;
},
{} as { [key: string]: ExtractNodeType<IByocClusters> },
);
setClusters(parsed);
return clusters;
} catch (err) {
Expand All @@ -48,23 +52,36 @@ const ClusterStatusProvider = ({ children }: { children: ReactNode }) => {
}
}, []);

useEffect(() => {
const interval = setInterval(() => {
listCluster();
}, 30 * 1000);
return () => {
clearInterval(interval);
};
}, []);

useDebounce(
() => {
listCluster();
},
3000,
[update]
[update],
);

useSocketWatch(() => {
setUpdate((p) => !p);
}, topic);

useEffect(() => {
console.log('helre', topic);
}, [topic]);

return (
<ClusterStatusContext.Provider
value={useMemo(
() => ({ clusters, setClusters }),
[clusters, setClusters]
[clusters, setClusters],
)}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,16 @@ const ListView = ({ items, onAction }: IResource) => {
const { account } = useParams();
const { clusters } = useClusterStatusV2();

const [clusterOnlineStatus, setClusterOnlineStatus] = useState<
Record<string, boolean>
>({});
useEffect(() => {
const states: Record<string, boolean> = {};
Object.entries(clusters).forEach(([key, value]) => {
states[key] = findClusterStatus(value);
});
setClusterOnlineStatus(states);
}, [clusters]);
// const [clusterOnlineStatus, setClusterOnlineStatus] = useState<
// Record<string, boolean>
// >({});
// useEffect(() => {
// const states: Record<string, boolean> = {};
// Object.entries(clusters).forEach(([key, value]) => {
// states[key] = findClusterStatus(value);
// });
// setClusterOnlineStatus(states);
// }, [clusters]);

return (
<ListV2.Root
Expand Down Expand Up @@ -244,7 +244,7 @@ const ListView = ({ items, onAction }: IResource) => {
],
rows: items.map((i) => {
const { name, id, updateInfo } = parseItem(i);
const isClusterOnline = clusterOnlineStatus[i.clusterName];
const isClusterOnline = findClusterStatus(clusters[i.clusterName]);

return {
columns: {
Expand Down Expand Up @@ -312,7 +312,7 @@ const EnvironmentResourcesV2 = ({ items = [] }: { items: BaseType[] }) => {
useWatchReload(
items.map((i) => {
return `account:${parseName(account)}.environment:${parseName(i)}`;
})
}),
);

const suspendEnvironment = async (item: BaseType, suspend: boolean) => {
Expand All @@ -338,7 +338,7 @@ const EnvironmentResourcesV2 = ({ items = [] }: { items: BaseType[] }) => {
suspend
? 'Environment suspended successfully'
: 'Environment resumed successfully'
}`
}`,
);
reloadPage();
} catch (err) {
Expand All @@ -347,7 +347,7 @@ const EnvironmentResourcesV2 = ({ items = [] }: { items: BaseType[] }) => {
};

const [showDeleteDialog, setShowDeleteDialog] = useState<BaseType | null>(
null
null,
);
const [visible, setVisible] = useState<BaseType | null>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ const ListView = ({ items, templates, onAction }: IResource) => {
const { account } = useOutletContext<IAccountContext>();
const { clusters } = useClusterStatusV2();

const [clusterOnlineStatus, setClusterOnlineStatus] = useState<
Record<string, boolean>
>({});
useEffect(() => {
const states: Record<string, boolean> = {};
Object.entries(clusters).forEach(([key, value]) => {
states[key] = findClusterStatus(value);
});
setClusterOnlineStatus(states);
}, [clusters]);
// const [clusterOnlineStatus, setClusterOnlineStatus] = useState<
// Record<string, boolean>
// >({});
// useEffect(() => {
// const states: Record<string, boolean> = {};
// Object.entries(clusters).forEach(([key, value]) => {
// states[key] = findClusterStatus(value);
// });
// setClusterOnlineStatus(states);
// }, [clusters]);

return (
<ListV2.Root
Expand Down Expand Up @@ -213,7 +213,7 @@ const ListView = ({ items, templates, onAction }: IResource) => {
},
],
rows: items.map((i) => {
const isClusterOnline = clusterOnlineStatus[i.clusterName];
const isClusterOnline = clusters[i.clusterName];
const { name, id, logo, updateInfo } = parseItem(i, templates);
return {
columns: {
Expand Down Expand Up @@ -282,11 +282,11 @@ const BackendServicesResourcesV2 = ({
return `account:${parseName(account)}.cluster:${
i.clusterName
}.cluster_managed_service:${parseName(i)}`;
})
}),
);

const [showDeleteDialog, setShowDeleteDialog] = useState<BaseType | null>(
null
null,
);
const [visible, setVisible] = useState<BaseType | null>(null);
const api = useConsoleApi();
Expand Down

0 comments on commit 1aa7b16

Please sign in to comment.