import { memo, useCallback, useMemo, } from 'react' import { useTranslation } from 'react-i18next' import { RiDeleteBinLine, RiEditLine, RiEqualizer2Line, RiHome9Line, RiStickyNoteAddLine, } from '@remixicon/react' import Dropdown from '@/app/components/base/dropdown' import type { Item } from '@/app/components/base/dropdown' import type { DataSourceCredential, } from './types' import { CredentialTypeEnum } from '@/app/components/plugins/plugin-auth/types' type OperatorProps = { credentialItem: DataSourceCredential onAction: (action: string, credentialItem: DataSourceCredential) => void onRename?: () => void } const Operator = ({ credentialItem, onAction, onRename, }: OperatorProps) => { const { t } = useTranslation() const { type, } = credentialItem const items = useMemo(() => { const commonItems = [ { value: 'setDefault', text: (
{t('plugin.auth.setDefault')}
), }, ...( type === CredentialTypeEnum.OAUTH2 ? [ { value: 'rename', text: (
{t('common.operation.rename')}
), }, ] : [] ), ...( type === CredentialTypeEnum.API_KEY ? [ { value: 'edit', text: (
{t('common.operation.edit')}
), }, ] : [] ), ] if (type === CredentialTypeEnum.OAUTH2) { const oAuthItems = [ { value: 'change', text: (
{t('common.dataSource.notion.changeAuthorizedPages')}
), }, ] commonItems.push(...oAuthItems) } return commonItems }, [t, type]) const secondItems = useMemo(() => { return [ { value: 'delete', text: (
{t('common.operation.remove')}
), }, ] }, []) const handleSelect = useCallback((item: Item) => { if (item.value === 'rename') { onRename?.() return } onAction( item.value as string, credentialItem, ) }, [onAction, credentialItem, onRename]) return ( ) } export default memo(Operator)