diff --git a/config-ui/package.json b/config-ui/package.json index fad6ad59150..abf81fe5d69 100644 --- a/config-ui/package.json +++ b/config-ui/package.json @@ -27,6 +27,7 @@ "@blueprintjs/datetime2": "^0.9.6", "@blueprintjs/popover2": "^1.10.2", "@blueprintjs/select": "^4.8.12", + "ahooks": "^3.7.8", "axios": "^0.21.4", "classnames": "^2.3.2", "cron-parser": "^4.3.0", diff --git a/config-ui/src/components/selector/multi-selector/index.tsx b/config-ui/src/components/selector/multi-selector/index.tsx index fc186918a81..920e5fa4b7e 100644 --- a/config-ui/src/components/selector/multi-selector/index.tsx +++ b/config-ui/src/components/selector/multi-selector/index.tsx @@ -100,7 +100,6 @@ export const MultiSelector = ({ return ( - request(`/plugins/${plugin}/connections/${connectionId}/scopes`); +type ParamsType = { + searchTerm: string; +}; + +export const getDataScope = (plugin: string, connectionId: ID, params?: ParamsType) => + request(`/plugins/${plugin}/connections/${connectionId}/scopes`, { + data: params, + }); diff --git a/config-ui/src/plugins/components/data-scope-select/index.tsx b/config-ui/src/plugins/components/data-scope-select/index.tsx index 4542c7e2f6d..85bf02c62f9 100644 --- a/config-ui/src/plugins/components/data-scope-select/index.tsx +++ b/config-ui/src/plugins/components/data-scope-select/index.tsx @@ -16,10 +16,11 @@ * */ -import { useState, useEffect } from 'react'; +import { useState } from 'react'; import { Button, Intent } from '@blueprintjs/core'; +import { useDebounce } from 'ahooks'; -import { PageLoading, FormItem, ExternalLink, Message, Buttons, Table } from '@/components'; +import { PageLoading, FormItem, ExternalLink, Message, Buttons, MultiSelector, Table } from '@/components'; import { useRefreshData } from '@/hooks'; import { getPluginScopeId } from '@/plugins'; @@ -45,12 +46,15 @@ export const DataScopeSelect = ({ }: Props) => { const [version, setVersion] = useState(1); const [scopeIds, setScopeIds] = useState([]); + const [search, setSearch] = useState(''); - const { ready, data } = useRefreshData(() => API.getDataScope(plugin, connectionId), [version]); + const searchTerm = useDebounce(search, { wait: 500 }); - useEffect(() => { - setScopeIds((initialScope ?? data ?? []).map((sc: any) => getPluginScopeId(plugin, sc)) ?? []); - }, [data]); + const { ready, data } = useRefreshData(() => API.getDataScope(plugin, connectionId), [version]); + const { ready: searchReady, data: searchItems } = useRefreshData<[{ name: string }]>( + () => API.getDataScope(plugin, connectionId, { searchTerm }), + [searchTerm], + ); const handleRefresh = () => setVersion((v) => v + 1); @@ -104,6 +108,18 @@ export const DataScopeSelect = ({