From a7fd36369e4a11570183d1a508d3c6896b2dd81c 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 paths and use error msg from response WIP readOnly try setting readonly add defaultState prop use keycloak tabs default values WIP reload WIP cleanup function add shouldUnregister fix for adding empty line on form load removed debug small fix for `isValid` role attributes tab format --- src/clients/ClientsSection.tsx | 2 + src/clients/add/NewClientForm.tsx | 2 + src/realm-roles/RealmRoleDetails.tsx | 140 --------------------------- src/realm-roles/RealmRoleForm.tsx | 9 +- src/realm-roles/RealmRoleTabs.tsx | 109 ++++++++++----------- src/realm-roles/RoleAttributes.tsx | 74 ++++++++------ 6 files changed, 105 insertions(+), 231 deletions(-) delete mode 100644 src/realm-roles/RealmRoleDetails.tsx diff --git a/src/clients/ClientsSection.tsx b/src/clients/ClientsSection.tsx index e2b39040df..f40ef8efd7 100644 --- a/src/clients/ClientsSection.tsx +++ b/src/clients/ClientsSection.tsx @@ -22,6 +22,8 @@ export const ClientsSection = () => { const history = useHistory(); const { url } = useRouteMatch(); + // console.log(form.errors) + const adminClient = useAdminClient(); const baseUrl = getBaseUrl(adminClient); diff --git a/src/clients/add/NewClientForm.tsx b/src/clients/add/NewClientForm.tsx index 4217590205..9abec3b5e3 100644 --- a/src/clients/add/NewClientForm.tsx +++ b/src/clients/add/NewClientForm.tsx @@ -38,6 +38,8 @@ export const NewClientForm = () => { const { addAlert } = useAlerts(); const methods = useForm({ defaultValues: client }); + console.log(methods.errors.description); + const save = async () => { try { await adminClient.clients.create({ ...client }); 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} - - - ( -