Skip to content

Commit a9af38b

Browse files
committed
fix(FR-764): increase agent select page size and add search functionality (#3455)
Resolves #3454 (FR-764) # Add search functionality to AgentSelect component This PR enhances the AgentSelect component by adding search functionality that allows users to filter agents by ID. The implementation: - Adds a search box to the agent selection dropdown - Implements search filtering using the `ilike` operator to match agent IDs - Uses React's `useTransition` hook to handle search state updates without blocking the UI - Increases the default page size from 20 to 50 agents - Disables the default filtering option in favor of the custom search implementation
1 parent 75ede7b commit a9af38b

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

react/src/components/AgentSelect.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import { filterEmptyItem } from '../helper';
12
import { useBAIPaginationOptionState } from '../hooks/reactPaginationQueryOptions';
3+
import { mergeFilterValues } from './BAIPropertyFilter';
24
import Flex from './Flex';
35
import ResourceNumber from './ResourceNumber';
46
import { AgentSelectQuery } from './__generated__/AgentSelectQuery.graphql';
57
import { useControllableValue } from 'ahooks';
68
import { Select, SelectProps } from 'antd';
79
import graphql from 'babel-plugin-relay/macro';
810
import _ from 'lodash';
9-
import React from 'react';
11+
import React, { useDeferredValue, useState } from 'react';
1012
import { useTranslation } from 'react-i18next';
1113
import { useLazyLoadQuery } from 'react-relay';
1214

@@ -23,10 +25,12 @@ const AgentSelect: React.FC<Props> = ({
2325
}) => {
2426
const { t } = useTranslation();
2527
const [value, setValue] = useControllableValue(selectProps);
28+
const [searchStr, setSearchStr] = useState<string | undefined>(undefined);
29+
const deferredSearchStr = useDeferredValue(searchStr);
2630

2731
const { baiPaginationOption } = useBAIPaginationOptionState({
2832
current: 1,
29-
pageSize: 20,
33+
pageSize: 50,
3034
});
3135

3236
const { agent_summary_list } = useLazyLoadQuery<AgentSelectQuery>(
@@ -61,7 +65,10 @@ const AgentSelect: React.FC<Props> = ({
6165
limit: baiPaginationOption.limit,
6266
offset: baiPaginationOption.offset,
6367
status: 'ALIVE',
64-
filter: 'schedulable is true', // true, false, null
68+
filter: mergeFilterValues([
69+
'schedulable is true',
70+
deferredSearchStr ? `id ilike "%${deferredSearchStr}%"` : null,
71+
]),
6572
scaling_group: resourceGroup,
6673
},
6774
{
@@ -111,17 +118,26 @@ const AgentSelect: React.FC<Props> = ({
111118
};
112119
});
113120

121+
const autoSelectIfMatch = t('session.launcher.AutoSelect')
122+
.toLowerCase()
123+
.includes(deferredSearchStr?.toLowerCase() ?? '')
124+
? { label: t('session.launcher.AutoSelect'), value: 'auto' }
125+
: undefined;
114126
return (
115127
<Select
116128
onChange={(value, option) => {
117129
setValue(value, option);
118130
}}
131+
loading={searchStr !== deferredSearchStr}
132+
filterOption={false}
133+
showSearch
134+
searchValue={searchStr}
135+
onSearch={(v) => {
136+
setSearchStr(v);
137+
}}
119138
{...selectProps}
120139
value={value}
121-
options={[
122-
{ label: t('session.launcher.AutoSelect'), value: 'auto' },
123-
...agentOptions,
124-
]}
140+
options={filterEmptyItem([autoSelectIfMatch, ...agentOptions])}
125141
/>
126142
);
127143
};

0 commit comments

Comments
 (0)