/* eslint-disable */ // @ts-nocheck import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Dropdown, DropdownItem, DropdownList, MenuToggle, Select, SelectList, SelectOption, ToolbarItem, } from "../../../shared/@patternfly/react-core"; import { FilterIcon } from "../../../shared/@patternfly/react-icons"; import { AllClientScopes, AllClientScopeType, clientScopeTypesSelectOptions, } from "../../components/client-scope/ClientScopeTypes"; import type { Row } from "../../clients/scopes/ClientScopes"; import useIsFeatureEnabled, { Feature } from "../../utils/useIsFeatureEnabled"; import { useMemo } from "react"; export type SearchType = "name" | "type" | "protocol"; export const PROTOCOLS = ["all", "saml", "openid-connect"] as const; export type ProtocolType = (typeof PROTOCOLS)[number] | "oid4vc"; export const nameFilter = (search = "") => (scope: Row) => scope.name?.includes(search); export const typeFilter = (type: AllClientScopeType) => (scope: Row) => type === AllClientScopes.none || scope.type === type; export const protocolFilter = (protocol: ProtocolType) => (scope: Row) => protocol === "all" || scope.protocol === protocol; type SearchToolbarProps = Omit & { type: AllClientScopeType; onType: (value: AllClientScopes) => void; protocol?: ProtocolType; onProtocol?: (value: ProtocolType) => void; }; type SearchDropdownProps = { searchType: SearchType; onSelect: (value: SearchType) => void; withProtocol?: boolean; }; export const SearchDropdown = ({ searchType, withProtocol = false, onSelect, }: SearchDropdownProps) => { const { t } = useTranslation(); const [searchToggle, setSearchToggle] = useState(false); const createDropdown = (searchType: SearchType) => ( { onSelect(searchType); setSearchToggle(false); }} > {t(`clientScopeSearch.${searchType}`)} ); const options = [createDropdown("name"), createDropdown("type")]; if (withProtocol) { options.push(createDropdown("protocol")); } return ( setSearchToggle(isOpen)} toggle={(ref) => ( setSearchToggle(!searchToggle)} > {t(`clientScopeSearch.${searchType}`)} )} isOpen={searchToggle} > {options} ); }; export const SearchToolbar = ({ searchType, onSelect, type, onType, protocol, onProtocol, }: SearchToolbarProps) => { const { t } = useTranslation(); const [open, setOpen] = useState(false); const isFeatureEnabled = useIsFeatureEnabled(); const protocols = useMemo( () => isFeatureEnabled(Feature.OpenId4VCI) ? ([...PROTOCOLS, "oid4vc"] as const) : PROTOCOLS, [isFeatureEnabled], ); return ( <> {searchType === "type" && ( <> )} {searchType === "protocol" && !!protocol && ( <> )} ); };