From 8ef7bd7ddb0c4a0c125a24a8f020844752ee4a19 Mon Sep 17 00:00:00 2001 From: jenny-s51 Date: Fri, 4 Dec 2020 15:37:29 -0500 Subject: [PATCH] WIP role attributes fix storybook demos add attributes tab to realm roles section use TableComposable fix formatting css updates fix up styling of role attributes table fix check-types erros logic from call with Jeff clean up, format, make eslint proud delete roledetails call with Erik add delete function and css changes fix storybook demos and format make key input disabled once new attribute is created minus icon gray address PR feedback from Sarah set add and save buttons to disabled when new input field is empty fix save/add fix onChange formState rebase with resolved conflicts fix formatting remove !important Update RealmRolesSection.css Update src/realm-roles/RoleAttributes.tsx Co-authored-by: Erik Jan de Wit address PR feedback from Sarah and Erik fix paths and use error msg from response remove log stmt fix lint remove minLength --- src/realm-roles/RealmRoleDetails.tsx | 140 -------------- src/realm-roles/RealmRoleForm.tsx | 172 ++--------------- src/realm-roles/RealmRoleTabs.tsx | 223 ++++++++++++---------- src/realm-roles/RealmRolesSection.css | 7 + src/realm-roles/__tests__/mock-roles.json | 6 +- src/realm-roles/messages.json | 4 +- src/route-config.ts | 6 +- src/stories/RoleAttributes.stories.tsx | 8 +- src/stories/RoleDetails.stories.tsx | 6 +- yarn.lock | 4 +- 10 files changed, 163 insertions(+), 413 deletions(-) delete mode 100644 src/realm-roles/RealmRoleDetails.tsx diff --git a/src/realm-roles/RealmRoleDetails.tsx b/src/realm-roles/RealmRoleDetails.tsx deleted file mode 100644 index 58a5cdb9b1..0000000000 --- a/src/realm-roles/RealmRoleDetails.tsx +++ /dev/null @@ -1,140 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { useHistory, useParams } from "react-router-dom"; -import { - ActionGroup, - AlertVariant, - Button, - FormGroup, - PageSection, - Tab, - Tabs, - TabTitleText, - TextArea, - TextInput, - ValidatedOptions, -} from "@patternfly/react-core"; -import { useTranslation } from "react-i18next"; -import { Controller, useForm } from "react-hook-form"; -import { FormAccess } from "../components/form-access/FormAccess"; - -import { useAlerts } from "../components/alert/Alerts"; -import { ViewHeader } from "../components/view-header/ViewHeader"; - -import { useAdminClient } from "../context/auth/AdminClient"; -import RoleRepresentation from "keycloak-admin/lib/defs/roleRepresentation"; -import { RoleAttributes } from "./RoleAttributes"; - -export const RolesForm = () => { - const { t } = useTranslation("roles"); - const { register, handleSubmit, errors, control, setValue } = useForm< - RoleRepresentation - >(); - const history = useHistory(); - const [name, setName] = useState(""); - const [activeTab, setActiveTab] = useState(0); - - const adminClient = useAdminClient(); - const form = useForm(); - - - const { id } = useParams<{ id: string }>(); - - const { addAlert } = useAlerts(); - - useEffect(() => { - (async () => { - const fetchedRole = await adminClient.roles.findOneById({ id }); - setName(fetchedRole.name!); - setupForm(fetchedRole); - })(); - }, []); - - const setupForm = (role: RoleRepresentation) => { - Object.entries(role).map((entry) => { - setValue(entry[0], entry[1]); - }); - }; - - const save = async (role: RoleRepresentation) => { - try { - await adminClient.roles.updateById({ id }, role); - setupForm(role as RoleRepresentation); - addAlert(t("roleSaveSuccess"), AlertVariant.success); - } catch (error) { - addAlert(`${t("roleSaveError")} '${error}'`, AlertVariant.danger); - } - }; - - return ( - <> - - - - setActiveTab(key as number)} - isBox - > - {t("details")}}> - - - {name ? ( - - ) : undefined} - - - ( -