'use client' import { useTranslation } from 'react-i18next' import React, { Fragment, useMemo } from 'react' import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react' import { RiArrowDownSLine } from '@remixicon/react' import NotionIcon from '../../notion-icon' export type NotionCredential = { credentialId: string credentialName: string workspaceIcon?: string workspaceName?: string } type CredentialSelectorProps = { value: string items: NotionCredential[] onSelect: (v: string) => void } const CredentialSelector = ({ value, items, onSelect, }: CredentialSelectorProps) => { const { t } = useTranslation() const currentCredential = items.find(item => item.credentialId === value)! const getDisplayName = (item: NotionCredential) => { return item.workspaceName || t('datasetPipeline.credentialSelector.name', { credentialName: item.credentialName, pluginName: 'Notion', }) } const currentDisplayName = useMemo(() => { return getDisplayName(currentCredential) }, [currentCredential]) return ( { ({ open }) => ( <>
{currentDisplayName}
{ items.map((item) => { const displayName = getDisplayName(item) return (
onSelect(item.credentialId)} >
{displayName}
{/* // ?Cannot get page length with new auth system */} {/*
{item.pages.length} {t('common.dataSource.notion.selector.pageSelected')}
*/}
) }) }
) }
) } export default React.memo(CredentialSelector)