'use client' import type { FC } from 'react' import React, { useMemo, useState } from 'react' import type { MetadataItem } from '../types' import SearchInput from '@/app/components/base/search-input' import { RiAddLine, RiArrowRightUpLine } from '@remixicon/react' import { useTranslation } from 'react-i18next' import { getIcon } from '../utils/get-icon' const i18nPrefix = 'dataset.metadata.selectMetadata' type Props = { list: MetadataItem[] onSelect: (data: MetadataItem) => void onNew: () => void onManage: () => void } const SelectMetadata: FC = ({ list: notFilteredList, onSelect, onNew, onManage, }) => { const { t } = useTranslation() const [query, setQuery] = useState('') const list = useMemo(() => { if (!query) return notFilteredList return notFilteredList.filter((item) => { return item.name.toLowerCase().includes(query.toLowerCase()) }) }, [query, notFilteredList]) return (
{list.map((item) => { const Icon = getIcon(item.type) return (
onSelect({ id: item.id, name: item.name, type: item.type, })} >
{item.name}
{item.type}
) })}
{t(`${i18nPrefix}.newAction`)}
{t(`${i18nPrefix}.manageAction`)}
) } export default React.memo(SelectMetadata)