import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { Button, ButtonVariant, Dropdown, DropdownToggle, Modal, ModalVariant, DropdownDirection, } from "@patternfly/react-core"; import { CaretUpIcon } from "@patternfly/react-icons"; import ClientScopeRepresentation from "keycloak-admin/lib/defs/clientScopeRepresentation"; import { ClientScopeType, clientScopeTypesDropdown, } from "../../components/client-scope/ClientScopeTypes"; import { KeycloakDataTable } from "../../components/table-toolbar/KeycloakDataTable"; import "./client-scopes.css"; export type AddScopeDialogProps = { clientScopes: ClientScopeRepresentation[]; open: boolean; toggleDialog: () => void; onAdd: ( scopes: { scope: ClientScopeRepresentation; type: ClientScopeType }[] ) => void; }; export const AddScopeDialog = ({ clientScopes, open, toggleDialog, onAdd, }: AddScopeDialogProps) => { const { t } = useTranslation("clients"); const [addToggle, setAddToggle] = useState(false); const [rows, setRows] = useState([]); const loader = () => Promise.resolve(clientScopes); const action = (scope: ClientScopeType) => { const scopes = rows.map((row) => { return { scope: row, type: scope }; }); onAdd(scopes); setAddToggle(false); toggleDialog(); }; return ( setAddToggle(!addToggle)} isPrimary toggleIndicator={CaretUpIcon} id="add-scope-toggle" > {t("common:add")} } dropdownItems={clientScopeTypesDropdown(t, action)} />, , ]} > setRows(rows)} columns={[ { name: "name", }, { name: "description", }, ]} /> ); };