import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { Controller, useFormContext } from "react-hook-form"; import { Button, Chip, ChipGroup, FormGroup, TextInput, } from "@patternfly/react-core"; import { HelpItem } from "../help-enabler/HelpItem"; import type { ComponentProps } from "./components"; import { AddScopeDialog } from "../../clients/scopes/AddScopeDialog"; import { useAdminClient, useFetch } from "../../context/auth/AdminClient"; import type ClientScopeRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientScopeRepresentation"; import { useParams } from "react-router"; import type { EditClientPolicyConditionParams } from "../../realm-settings/routes/EditCondition"; import { GroupPickerDialog } from "../group/GroupPickerDialog"; export const MultivaluedChipsComponent = ({ defaultValue, name, label, helpText, }: ComponentProps) => { const { t } = useTranslation("dynamic"); const { control } = useFormContext(); const { conditionName } = useParams(); const adminClient = useAdminClient(); const [open, setOpen] = useState(false); const [clientScopes, setClientScopes] = useState( [] ); useFetch( () => adminClient.clientScopes.find(), (clientScopes) => { setClientScopes(clientScopes); }, [] ); const toggleModal = () => { setOpen(!open); }; return ( } fieldId={name!} > ( <> {open && name === "scopes" && ( !value.includes(scope.name!) )} isClientScopesConditionType open={open} toggleDialog={() => setOpen(!open)} onAdd={(scopes) => { onChange([ ...value, ...scopes .map((scope) => scope.scope) .map((item) => item.name!), ]); }} /> )} {open && name === "groups" && ( { onChange([...value, ...groups.map((group) => group.name)]); setOpen(false); }} onClose={() => { setOpen(false); }} filterGroups={value} /> )} {value.length === 0 && !conditionName && ( )} { onChange([]); }} > {value.map((currentChip: string) => ( { onChange( value.filter((item: string) => item !== currentChip) ); }} > {currentChip} ))} )} /> ); };