diff --git a/web/src/components/apps/EmbeddedClusterManagement.tsx b/web/src/components/apps/EmbeddedClusterManagement.tsx index 2ff33617d0..f846f69144 100644 --- a/web/src/components/apps/EmbeddedClusterManagement.tsx +++ b/web/src/components/apps/EmbeddedClusterManagement.tsx @@ -129,6 +129,49 @@ const EmbeddedClusterManagement = ({ retry: false, }); + type RolesResponse = { + roles: string[]; + }; + + const { + data: rolesData, + isInitialLoading: rolesLoading, + error: rolesError, + } = useQuery({ + queryKey: ["embeddedClusterRoles"], + queryFn: async () => { + const res = await fetch( + `${process.env.API_ENDPOINT}/embedded-cluster/roles`, + { + headers: { + Accept: "application/json", + }, + credentials: "include", + method: "GET", + } + ); + if (!res.ok) { + if (res.status === 401) { + Utilities.logoutUser(); + } + console.log( + "failed to get role list, unexpected status code", + res.status + ); + try { + const error = await res.json(); + throw new Error( + error?.error?.message || error?.error || error?.message + ); + } catch (err) { + throw new Error("Unable to fetch roles, please try again later."); + } + } + return res.json(); + }, + retry: false, + }); + type AddNodeCommandResponse = { command: string; expiry: string; @@ -421,7 +464,17 @@ const EmbeddedClusterManagement = ({ page.

- {NODE_TYPES.map((nodeType) => ( + {rolesLoading && ( +

+ Loading roles... +

+ )} + {!rolesData && rolesError && ( +

+ {rolesError?.message} +

+ )} + {(rolesData?.roles || NODE_TYPES).map((nodeType) => (