fix formatting
This commit is contained in:
parent
28b16e9770
commit
a405dc9e13
3 changed files with 24 additions and 29 deletions
|
@ -1,4 +1,4 @@
|
||||||
import React, {useContext} from "react";
|
import React, { useContext } from "react";
|
||||||
import {
|
import {
|
||||||
AlertVariant,
|
AlertVariant,
|
||||||
Button,
|
Button,
|
||||||
|
@ -6,7 +6,7 @@ import {
|
||||||
FormGroup,
|
FormGroup,
|
||||||
Modal,
|
Modal,
|
||||||
ModalVariant,
|
ModalVariant,
|
||||||
TextInput
|
TextInput,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { HttpClientContext } from "../http-service/HttpClientContext";
|
import { HttpClientContext } from "../http-service/HttpClientContext";
|
||||||
|
@ -22,8 +22,13 @@ type GroupsCreateModalProps = {
|
||||||
setCreateGroupName: (createGroupName: string) => void;
|
setCreateGroupName: (createGroupName: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GroupsCreateModal = ({handleModalToggle, isCreateModalOpen, setIsCreateModalOpen, createGroupName, setCreateGroupName}: GroupsCreateModalProps) => {
|
export const GroupsCreateModal = ({
|
||||||
|
handleModalToggle,
|
||||||
|
isCreateModalOpen,
|
||||||
|
setIsCreateModalOpen,
|
||||||
|
createGroupName,
|
||||||
|
setCreateGroupName,
|
||||||
|
}: GroupsCreateModalProps) => {
|
||||||
const { t } = useTranslation("groups");
|
const { t } = useTranslation("groups");
|
||||||
const httpClient = useContext(HttpClientContext)!;
|
const httpClient = useContext(HttpClientContext)!;
|
||||||
const { realm } = useContext(RealmContext);
|
const { realm } = useContext(RealmContext);
|
||||||
|
@ -32,19 +37,21 @@ export const GroupsCreateModal = ({handleModalToggle, isCreateModalOpen, setIsCr
|
||||||
const { register, errors } = form;
|
const { register, errors } = form;
|
||||||
|
|
||||||
const valueChange = (createGroupName: string) => {
|
const valueChange = (createGroupName: string) => {
|
||||||
setCreateGroupName(createGroupName)
|
setCreateGroupName(createGroupName);
|
||||||
}
|
};
|
||||||
|
|
||||||
const submitForm = async () => {
|
const submitForm = async () => {
|
||||||
try {
|
try {
|
||||||
await httpClient.doPost(`/admin/realms/${realm}/groups`, {name: createGroupName});
|
await httpClient.doPost(`/admin/realms/${realm}/groups`, {
|
||||||
|
name: createGroupName,
|
||||||
|
});
|
||||||
setIsCreateModalOpen(false);
|
setIsCreateModalOpen(false);
|
||||||
setCreateGroupName("");
|
setCreateGroupName("");
|
||||||
add(t("groupCreated"), AlertVariant.success);
|
add(t("groupCreated"), AlertVariant.success);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
add(`${t("couldNotCreateGroup")} ': '${error}'`, AlertVariant.danger);
|
add(`${t("couldNotCreateGroup")} ': '${error}'`, AlertVariant.danger);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
@ -57,7 +64,7 @@ export const GroupsCreateModal = ({handleModalToggle, isCreateModalOpen, setIsCr
|
||||||
actions={[
|
actions={[
|
||||||
<Button key="confirm" variant="primary" onClick={() => submitForm()}>
|
<Button key="confirm" variant="primary" onClick={() => submitForm()}>
|
||||||
{t("create")}
|
{t("create")}
|
||||||
</Button>
|
</Button>,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Form isHorizontal>
|
<Form isHorizontal>
|
||||||
|
|
|
@ -5,10 +5,7 @@ import {
|
||||||
TableBody,
|
TableBody,
|
||||||
TableVariant,
|
TableVariant,
|
||||||
} from "@patternfly/react-table";
|
} from "@patternfly/react-table";
|
||||||
import {
|
import { Button, AlertVariant } from "@patternfly/react-core";
|
||||||
Button,
|
|
||||||
AlertVariant
|
|
||||||
} from "@patternfly/react-core";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { GroupRepresentation } from "./models/groups";
|
import { GroupRepresentation } from "./models/groups";
|
||||||
import { UsersIcon } from "@patternfly/react-icons";
|
import { UsersIcon } from "@patternfly/react-icons";
|
||||||
|
@ -31,7 +28,6 @@ export const GroupsList = ({ list }: GroupsListProps) => {
|
||||||
{ cells: [<Button key="0">Test</Button>], selected: false },
|
{ cells: [<Button key="0">Test</Button>], selected: false },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
const formatData = (data: GroupRepresentation[]) =>
|
const formatData = (data: GroupRepresentation[]) =>
|
||||||
data.map((group: { [key: string]: any }, index) => {
|
data.map((group: { [key: string]: any }, index) => {
|
||||||
const groupName = group[columnGroupName];
|
const groupName = group[columnGroupName];
|
||||||
|
@ -81,21 +77,21 @@ export const GroupsList = ({ list }: GroupsListProps) => {
|
||||||
{
|
{
|
||||||
title: t("common:Delete"),
|
title: t("common:Delete"),
|
||||||
onClick: (_: React.MouseEvent<Element, MouseEvent>, rowId: number) => {
|
onClick: (_: React.MouseEvent<Element, MouseEvent>, rowId: number) => {
|
||||||
try { httpClient.doDelete(
|
try {
|
||||||
|
httpClient.doDelete(
|
||||||
`/admin/realms/${realm}/groups/${list![rowId].id}`
|
`/admin/realms/${realm}/groups/${list![rowId].id}`
|
||||||
);
|
);
|
||||||
add(t("Group deleted"), AlertVariant.success);
|
add(t("Group deleted"), AlertVariant.success);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
add(`${t("clientDeleteError")} ${error}`, AlertVariant.danger);
|
add(`${t("clientDeleteError")} ${error}`, AlertVariant.danger);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
}
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Alerts/>
|
<Alerts />
|
||||||
{formattedData && (
|
{formattedData && (
|
||||||
<Table
|
<Table
|
||||||
actions={actions}
|
actions={actions}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import {
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import "./GroupsSection.css";
|
import "./GroupsSection.css";
|
||||||
|
|
||||||
|
|
||||||
export const GroupsSection = () => {
|
export const GroupsSection = () => {
|
||||||
const { t } = useTranslation("groups");
|
const { t } = useTranslation("groups");
|
||||||
const httpClient = useContext(HttpClientContext)!;
|
const httpClient = useContext(HttpClientContext)!;
|
||||||
|
@ -37,8 +36,6 @@ export const GroupsSection = () => {
|
||||||
|
|
||||||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const loader = async () => {
|
const loader = async () => {
|
||||||
const groups = await httpClient.doGet<ServerGroupsArrayRepresentation[]>(
|
const groups = await httpClient.doGet<ServerGroupsArrayRepresentation[]>(
|
||||||
"/admin/realms/master/groups",
|
"/admin/realms/master/groups",
|
||||||
|
@ -97,15 +94,12 @@ export const GroupsSection = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleModalToggle = () => {
|
const handleModalToggle = () => {
|
||||||
setIsCreateModalOpen(!isCreateModalOpen)
|
setIsCreateModalOpen(!isCreateModalOpen);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<ViewHeader
|
<ViewHeader titleKey="groups:groups" subKey="groups:groupsDescription" />
|
||||||
titleKey="groups:groups"
|
|
||||||
subKey="groups:groupsDescription"
|
|
||||||
/>
|
|
||||||
<PageSection variant={PageSectionVariants.light}>
|
<PageSection variant={PageSectionVariants.light}>
|
||||||
<TableToolbar
|
<TableToolbar
|
||||||
count={10}
|
count={10}
|
||||||
|
@ -144,9 +138,7 @@ export const GroupsSection = () => {
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{rawData && filteredData && (
|
{rawData && filteredData && (
|
||||||
<GroupsList
|
<GroupsList list={filteredData ? filteredData : rawData} />
|
||||||
list={filteredData ? filteredData : rawData}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</TableToolbar>
|
</TableToolbar>
|
||||||
<GroupsCreateModal
|
<GroupsCreateModal
|
||||||
|
|
Loading…
Reference in a new issue