feat: add tag and q filter

pull/12372/head
Joel 2 years ago
parent 910d5df513
commit 1573f6f6aa

@ -23,6 +23,7 @@ import { useMarketplacePlugins } from '../../plugins/marketplace/hooks'
type AllToolsProps = { type AllToolsProps = {
className?: string className?: string
searchText: string searchText: string
tags: string[]
buildInTools: ToolWithProvider[] buildInTools: ToolWithProvider[]
customTools: ToolWithProvider[] customTools: ToolWithProvider[]
workflowTools: ToolWithProvider[] workflowTools: ToolWithProvider[]
@ -34,6 +35,7 @@ type AllToolsProps = {
const AllTools = ({ const AllTools = ({
className, className,
searchText, searchText,
tags = [],
onSelect, onSelect,
buildInTools, buildInTools,
workflowTools, workflowTools,
@ -45,7 +47,7 @@ const AllTools = ({
const tabs = useToolTabs() const tabs = useToolTabs()
const [activeTab, setActiveTab] = useState(ToolTypeEnum.All) const [activeTab, setActiveTab] = useState(ToolTypeEnum.All)
const [activeView, setActiveView] = useState<ViewType>(ViewType.flat) const [activeView, setActiveView] = useState<ViewType>(ViewType.flat)
const hasFilter = searchText || tags.length > 0
const tools = useMemo(() => { const tools = useMemo(() => {
let mergedTools: ToolWithProvider[] = [] let mergedTools: ToolWithProvider[] = []
if (activeTab === ToolTypeEnum.All) if (activeTab === ToolTypeEnum.All)
@ -57,7 +59,7 @@ const AllTools = ({
if (activeTab === ToolTypeEnum.Workflow) if (activeTab === ToolTypeEnum.Workflow)
mergedTools = workflowTools mergedTools = workflowTools
if (!searchText) if (!hasFilter)
return mergedTools.filter(toolWithProvider => toolWithProvider.tools.length > 0) return mergedTools.filter(toolWithProvider => toolWithProvider.tools.length > 0)
return mergedTools.filter((toolWithProvider) => { return mergedTools.filter((toolWithProvider) => {
@ -65,7 +67,7 @@ const AllTools = ({
return tool.label[language].toLowerCase().includes(searchText.toLowerCase()) return tool.label[language].toLowerCase().includes(searchText.toLowerCase())
}) })
}) })
}, [activeTab, buildInTools, customTools, workflowTools, searchText, language]) }, [activeTab, buildInTools, customTools, workflowTools, searchText, language, hasFilter])
const { const {
queryPluginsWithDebounced: fetchPlugins, queryPluginsWithDebounced: fetchPlugins,
@ -73,14 +75,15 @@ const AllTools = ({
} = useMarketplacePlugins() } = useMarketplacePlugins()
useEffect(() => { useEffect(() => {
if (searchText) { if (searchText || tags.length > 0) {
fetchPlugins({ fetchPlugins({
query: searchText, query: searchText,
tags,
category: PluginType.tool, category: PluginType.tool,
}) })
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchText]) }, [searchText, tags])
const pluginRef = useRef(null) const pluginRef = useRef(null)
const wrapElemRef = useRef<HTMLDivElement>(null) const wrapElemRef = useRef<HTMLDivElement>(null)
@ -134,6 +137,7 @@ const AllTools = ({
wrapElemRef={wrapElemRef} wrapElemRef={wrapElemRef}
list={notInstalledPlugins as any} ref={pluginRef} list={notInstalledPlugins as any} ref={pluginRef}
searchText={searchText} searchText={searchText}
tags={tags}
/> />
</div> </div>
</div> </div>

@ -14,16 +14,19 @@ type Props = {
wrapElemRef: React.RefObject<HTMLElement> wrapElemRef: React.RefObject<HTMLElement>
list: Plugin[] list: Plugin[]
searchText: string searchText: string
tags: string[]
} }
const List = ({ const List = ({
wrapElemRef, wrapElemRef,
searchText, searchText,
tags,
list, list,
}: Props, ref: any) => { }: Props, ref: any) => {
const { t } = useTranslation() const { t } = useTranslation()
const hasSearchText = !searchText const hasFilter = !searchText
const urlWithSearchText = `${marketplaceUrlPrefix}/plugins?q=${searchText}` const hasRes = list.length > 0
const urlWithSearchText = `${marketplaceUrlPrefix}/marketplace?q=${searchText}&tags=${tags.join(',')}`
const nextToStickyELemRef = useRef<HTMLDivElement>(null) const nextToStickyELemRef = useRef<HTMLDivElement>(null)
const { handleScroll, scrollPosition } = useStickyScroll({ const { handleScroll, scrollPosition } = useStickyScroll({
@ -58,7 +61,7 @@ const List = ({
window.open(urlWithSearchText, '_blank') window.open(urlWithSearchText, '_blank')
} }
if (hasSearchText) { if (hasFilter) {
return ( return (
<Link <Link
className='sticky bottom-0 z-10 flex h-8 px-4 py-1 system-sm-medium items-center border-t border-[0.5px] border-components-panel-border bg-components-panel-bg-blur rounded-b-lg shadow-lg text-text-accent-light-mode-only cursor-pointer' className='sticky bottom-0 z-10 flex h-8 px-4 py-1 system-sm-medium items-center border-t border-[0.5px] border-components-panel-border bg-components-panel-bg-blur rounded-b-lg shadow-lg text-text-accent-light-mode-only cursor-pointer'
@ -73,6 +76,7 @@ const List = ({
return ( return (
<> <>
{hasRes && (
<div <div
className={cn('sticky z-10 flex justify-between h-8 px-4 py-1 text-text-primary system-sm-medium cursor-pointer', stickyClassName)} className={cn('sticky z-10 flex justify-between h-8 px-4 py-1 text-text-primary system-sm-medium cursor-pointer', stickyClassName)}
onClick={handleHeadClick} onClick={handleHeadClick}
@ -88,6 +92,7 @@ const List = ({
<RiArrowRightUpLine className='ml-0.5 w-3 h-3' /> <RiArrowRightUpLine className='ml-0.5 w-3 h-3' />
</Link> </Link>
</div> </div>
)}
<div className='p-1' ref={nextToStickyELemRef}> <div className='p-1' ref={nextToStickyELemRef}>
{list.map((item, index) => ( {list.map((item, index) => (
<Item <Item

@ -48,6 +48,7 @@ const ToolPicker: FC<Props> = ({
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const [searchText, setSearchText] = useState('') const [searchText, setSearchText] = useState('')
const [tags, setTags] = useState<string[]>([])
const { data: buildInTools } = useAllBuiltInTools() const { data: buildInTools } = useAllBuiltInTools()
const { data: customTools } = useAllCustomTools() const { data: customTools } = useAllCustomTools()
@ -111,14 +112,15 @@ const ToolPicker: FC<Props> = ({
<SearchBox <SearchBox
search={searchText} search={searchText}
onSearchChange={setSearchText} onSearchChange={setSearchText}
tags={[]} tags={tags}
onTagsChange={() => { }} onTagsChange={setTags}
size='small' size='small'
placeholder={t('plugin.searchTools')!} placeholder={t('plugin.searchTools')!}
/> />
</div> </div>
<AllTools <AllTools
className='mt-1' className='mt-1'
tags={tags}
searchText={searchText} searchText={searchText}
onSelect={handleSelect} onSelect={handleSelect}
buildInTools={buildInTools || []} buildInTools={buildInTools || []}

Loading…
Cancel
Save