initial version of groups (#86)

This commit is contained in:
Erik Jan de Wit 2020-09-15 21:54:52 +02:00 committed by GitHub
parent 3798c41db0
commit 601bba8057
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 95 additions and 2 deletions

35
src/groups/GroupsList.tsx Normal file
View file

@ -0,0 +1,35 @@
import React from "react";
import {
Table,
TableHeader,
TableBody,
TableVariant,
} from "@patternfly/react-table";
import { GroupRepresentation } from "./models/groups";
import { useTranslation } from "react-i18next";
type GroupsListProps = {
list: GroupRepresentation[];
};
export const GroupsList = ({ list }: GroupsListProps) => {
const { t } = useTranslation("group");
const columns: (keyof GroupRepresentation)[] = ["name"];
const data = list.map((c) => {
return { cells: columns.map((col) => c[col]) };
});
console.log(list);
return (
<Table
aria-label="Simple Table"
variant={TableVariant.compact}
cells={[{ title: t("Name") }]}
rows={data}
>
<TableHeader />
<TableBody />
</Table>
);
};

View file

@ -1,5 +1,53 @@
import React from "react"; import React, { useContext, useState } from "react";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import { Button } from "@patternfly/react-core";
import { HttpClientContext } from "../http-service/HttpClientContext";
import { GroupsList } from "./GroupsList";
import { DataLoader } from "../components/data-loader/DataLoader";
import { GroupRepresentation } from "./models/groups";
import { TableToolbar } from "../components/table-toolbar/TableToolbar";
export const GroupsSection = () => { export const GroupsSection = () => {
return <>The Groups Page</>; const { t } = useTranslation("groups");
const history = useHistory();
const httpClient = useContext(HttpClientContext)!;
const [max, setMax] = useState(10);
const [first, setFirst] = useState(0);
const loader = async () => {
return await httpClient
.doGet("/admin/realms/master/groups", { params: { first, max } })
.then((r) => r.data as GroupRepresentation[]);
};
return (
<>
<DataLoader loader={loader}>
{(groups) => (
<TableToolbar
count={groups!.length}
first={first}
max={max}
onNextClick={setFirst}
onPreviousClick={setFirst}
onPerPageSelect={(f, m) => {
setFirst(f);
setMax(m);
}}
toolbarItem={
<>
<Button onClick={() => history.push("/add-group")}>
{t("Create group")}
</Button>
</>
}
>
<GroupsList list={groups} />
</TableToolbar>
)}
</DataLoader>
</>
);
}; };

View file

@ -0,0 +1,10 @@
export interface GroupRepresentation {
id?: string;
name?: string;
path?: string;
attributes?: { [index: string]: string[] };
realmRoles?: string[];
clientRoles?: { [index: string]: string[] };
subGroups?: GroupRepresentation[];
access?: { [index: string]: boolean };
}