Skip to content

Commit

Permalink
Merge branch 'release-v1.0.5' into ui/reg-images
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtcoder19 committed Sep 5, 2024
2 parents 8340c4a + 9092ce3 commit c30586d
Show file tree
Hide file tree
Showing 6 changed files with 745 additions and 83 deletions.
682 changes: 661 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

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
@@ -1,5 +1,5 @@
import { Link, useOutletContext, useParams } from '@remix-run/react';
import { useEffect, useState } from 'react';
import { useState } from 'react';
import { Badge } from '~/components/atoms/badge';
import TooltipV2 from '~/components/atoms/tooltipV2';
import { toast } from '~/components/molecule/toast';
Expand Down Expand Up @@ -34,7 +34,7 @@ import {
parseName,
parseUpdateOrCreatedBy,
parseUpdateOrCreatedOn,
parseName as pn,
parseName as pn
} from '~/console/server/r-utils/common';
import { useReload } from '~/lib/client/helpers/reloader';
import { useWatchReload } from '~/lib/client/helpers/socket/useWatch';
Expand Down Expand Up @@ -243,16 +243,16 @@ const ListView = ({ items = [], onAction }: IResource) => {
useOutletContext<IEnvironmentContext>();
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 @@ -306,7 +306,10 @@ const ListView = ({ items = [], onAction }: IResource) => {
},
],
rows: items.map((i) => {
const isClusterOnline = clusterOnlineStatus[parseName(cluster)];
// const isClusterOnline = clusterOnlineStatus[parseName(cluster)];
const isClusterOnline = findClusterStatus(
clusters[parseName(cluster)]
);

const { name, id, updateInfo } = parseItem(i);
return {
Expand Down Expand Up @@ -399,10 +402,9 @@ const AppsResourcesV2 = ({ items = [] }: Omit<IResource, 'onAction'>) => {
}
// toast.success('app intercepted successfully');
toast.success(
`${
intercept
? 'App Intercepted successfully'
: 'App Intercept removed successfully'
`${intercept
? 'App Intercepted successfully'
: 'App Intercept removed successfully'
}`
);
reload();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useOutletContext, useParams } from '@remix-run/react';
import { useEffect, useState } from 'react';
import { useState } from 'react';
import { Badge } from '~/components/atoms/badge';
import { toast } from '~/components/molecule/toast';
import { generateKey, titleCase } from '~/components/utils';
Expand Down Expand Up @@ -137,16 +137,16 @@ const ListView = ({ items = [], onAction, templates }: IResource) => {
const { cluster } = useOutletContext<IEnvironmentContext>();
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 @@ -195,7 +195,10 @@ const ListView = ({ items = [], onAction, templates }: IResource) => {
],
rows: items.map((i) => {
const { name, id, logo, updateInfo } = parseItem(i, templates);
const isClusterOnline = clusterOnlineStatus[parseName(cluster)];
// const isClusterOnline = clusterOnlineStatus[parseName(cluster)];
const isClusterOnline = findClusterStatus(
clusters[parseName(cluster)]
);

return {
columns: {
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 = findClusterStatus(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 c30586d

Please sign in to comment.