import React from "react"; import { useTranslation } from "react-i18next"; import { ArrayField, UseFormMethods } from "react-hook-form"; import { ActionGroup, Button, TextInput } from "@patternfly/react-core"; import { TableComposable, Tbody, Td, Th, Thead, Tr, } from "@patternfly/react-table"; import { MinusCircleIcon, PlusCircleIcon } from "@patternfly/react-icons"; import { FormAccess } from "../components/form-access/FormAccess"; import { RoleFormType } from "./RealmRoleTabs"; import "./RealmRolesSection.css"; export type KeyValueType = { key: string; value: string }; type RoleAttributesProps = { form: UseFormMethods; save: (role: RoleFormType) => void; reset: () => void; array: { fields: Partial, "id">>[]; append: ( value: Partial> | Partial>[], shouldFocus?: boolean | undefined ) => void; remove: (index?: number | number[] | undefined) => void; }; }; export const RoleAttributes = ({ form: { handleSubmit, register, formState, errors, watch }, save, array: { fields, append, remove }, reset, }: RoleAttributesProps) => { const { t } = useTranslation("roles"); const columns = ["Key", "Value"]; const watchFirstKey = watch("attributes[0].key"); return ( <> {columns[0]} {columns[1]} {fields.map((attribute, rowIndex) => ( {rowIndex !== fields.length - 1 && fields.length - 1 !== 0 && ( )} {rowIndex === fields.length - 1 && ( {fields[rowIndex].key === "" && ( )} ); };