Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI representation for Roles #532

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions cyclops-ui/src/components/k8s-resources/Roles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React, { useEffect, useState } from "react";
import axios from "axios";
import { Alert, Table } from "antd";
import { mapResponseError } from "../../utils/api/errors";

interface Props {
name: string;
namespace: string;
}

interface RoleData {
name: string;
apiGroup: string;
get: boolean;
list: boolean;
watch: boolean;
create: boolean;
patch: boolean;
update: boolean;
delete: boolean;
deleteList: boolean;
}

const Roles = ({ name, namespace }: Props) => {
const [roles, setRoles] = useState<RoleData[]>([]);
const [error, setError] = useState({
message: "",
description: "",
});

useEffect(() => {
function fetchRoles() {
axios
.get(`/api/resources`, {
params: {
group: `rbac.authorization.k8s.io`,
version: `v1`,
kind: `Role`,
name: name,
namespace: namespace,
},
})
.then((res) => {
// Process and map the response data to the RoleData structure
const mappedRoles: RoleData[] = res.data.map((role: any) => ({
name: role.metadata.name,
apiGroup: role.apiGroup,
get: role.get,
list: role.list,
watch: role.watch,
create: role.create,
patch: role.patch,
update: role.update,
delete: role.delete,
deleteList: role.deleteList,
}));
setRoles(mappedRoles);
})
.catch((error) => {
setError(mapResponseError(error));
});
}

fetchRoles();
const interval = setInterval(() => fetchRoles(), 15000);
return () => {
clearInterval(interval);
};
}, [name, namespace]);

const columns = [
{ title: "NAME", dataIndex: "name", key: "name" },
{ title: "API-GROUP", dataIndex: "apiGroup", key: "apiGroup" },
{ title: "GET", dataIndex: "get", key: "get", render: (text: boolean) => (text ? "βœ“" : "x") },
{ title: "LIST", dataIndex: "list", key: "list", render: (text: boolean) => (text ? "βœ“" : "x") },
{ title: "WATCH", dataIndex: "watch", key: "watch", render: (text: boolean) => (text ? "βœ“" : "x") },
{ title: "CREATE", dataIndex: "create", key: "create", render: (text: boolean) => (text ? "βœ“" : "x") },
{ title: "PATCH", dataIndex: "patch", key: "patch", render: (text: boolean) => (text ? "βœ“" : "x") },
{ title: "UPDATE", dataIndex: "update", key: "update", render: (text: boolean) => (text ? "βœ“" : "x") },
{ title: "DELETE", dataIndex: "delete", key: "delete", render: (text: boolean) => (text ? "βœ“" : "x") },
{ title: "DEL-LIST", dataIndex: "deleteList", key: "deleteList", render: (text: boolean) => (text ? "βœ“" : "x") },
];

return (
<div>
{error.message.length !== 0 && (
<Alert
message={error.message}
description={error.description}
type="error"
closable
afterClose={() => {
setError({
message: "",
description: "",
});
}}
style={{ marginBottom: "20px" }}
/>
)}
<Table columns={columns} dataSource={roles} rowKey="name" />
</div>
);
};

export default Roles;
7 changes: 7 additions & 0 deletions cyclops-ui/src/components/pages/ModuleDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
import { gvkString } from "../../utils/k8s/gvk";
import { mapResponseError } from "../../utils/api/errors";
import Secret from "../k8s-resources/Secret";
import Roles from "../k8s-resources/Roles";
import { CheckboxChangeEvent } from "antd/es/checkbox";
import {
canRestart,
Expand Down Expand Up @@ -498,6 +499,12 @@ const ModuleDetails = () => {
<Secret name={resource.name} namespace={resource.namespace} />
);
break;

case "Roles":
resourceDetails = (
<Roles name={resource.name} namespace={resource.namespace}/>
)
break;
}

let deletedWarning = <p />;
Expand Down
Loading