From 601bba8057e3acc1196f232817dccaba3085b498 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 15 Sep 2020 21:54:52 +0200 Subject: [PATCH] initial version of groups (#86) --- src/groups/GroupsList.tsx | 35 ++++++++++++++++++++++++ src/groups/GroupsSection.tsx | 52 ++++++++++++++++++++++++++++++++++-- src/groups/models/groups.tsx | 10 +++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/groups/GroupsList.tsx create mode 100644 src/groups/models/groups.tsx diff --git a/src/groups/GroupsList.tsx b/src/groups/GroupsList.tsx new file mode 100644 index 0000000000..352a0ccbfd --- /dev/null +++ b/src/groups/GroupsList.tsx @@ -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 ( + + + +
+ ); +}; diff --git a/src/groups/GroupsSection.tsx b/src/groups/GroupsSection.tsx index 93c4a78237..1f9f895419 100644 --- a/src/groups/GroupsSection.tsx +++ b/src/groups/GroupsSection.tsx @@ -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 = () => { - 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 ( + <> + + {(groups) => ( + { + setFirst(f); + setMax(m); + }} + toolbarItem={ + <> + + + } + > + + + )} + + + ); }; diff --git a/src/groups/models/groups.tsx b/src/groups/models/groups.tsx new file mode 100644 index 0000000000..63127542b5 --- /dev/null +++ b/src/groups/models/groups.tsx @@ -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 }; +}