From fae4f7784edf69d32ef1833587cc1585534c7b18 Mon Sep 17 00:00:00 2001
From: Andrew Lavery
Date: Tue, 14 Nov 2023 18:20:43 -0500
Subject: [PATCH] display roles in UI
---
.../apps/EmbeddedClusterManagement.tsx | 55 ++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)
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) => (