Skip to content

Commit 0aeec99

Browse files
committed
fix(FR-1412): optimize agent filtering and fix pagination count (#4192)
resolves #4191 ([FR-1412](https://lablup.atlassian.net/browse/FR-1412)) ## Summary Fixes pagination issue in the Resource Summary tab (AgentSummaryList component) where pagination would be stuck at 1 when selecting small page sizes like 10 or 20. This was caused by incorrect client-side filtering that affected the pagination total count. ## Changes Made 1. **Moved sFTP resource group filtering from client-side to server-side**: - Added `mergeFilterValues` import from `backend.ai-ui` - Created `sftpExclusionFilter` using `!(scaling_group in ["group1", "group2"])` syntax - Updated GraphQL query to merge user filter with sFTP exclusion filter 2. **Removed inefficient client-side filtering logic**: - Removed `filteredAgentSummaryList` that was filtering after data fetch - Updated table `dataSource` to use `agent_summary_list?.items` directly 3. **Fixed pagination total count**: - Changed pagination total from `filteredAgentSummaryList?.length` to `agent_summary_list?.total_count` - This ensures pagination uses the correct server-side filtered count ## Impact - ✅ Fixes pagination issue where list wouldn't appear with small page sizes - ✅ Improves performance by filtering on server-side instead of client-side - ✅ Reduces data transfer by excluding sFTP agents at query level - ✅ Maintains existing filtering functionality ## Testing - Verify pagination works correctly with different page sizes (10, 20, 50, etc.) - Confirm sFTP resource groups are still properly excluded from the list - Check that user filters (ID, schedulable status) still work as expected **Checklist:** - [x] Fix addresses the root cause of pagination issue - [x] Server-side filtering implementation follows existing patterns - [x] No breaking changes to existing functionality - [x] Performance improvement through reduced client-side processing [FR-1412]: https://lablup.atlassian.net/browse/FR-1412?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent b3b520b commit 0aeec99

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

react/src/components/AgentSummaryList.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
BAITable,
3131
BAIFlex,
3232
BAIPropertyFilter,
33+
mergeFilterValues,
3334
} from 'backend.ai-ui';
3435
import _ from 'lodash';
3536
import React, { useState, useTransition } from 'react';
@@ -82,6 +83,11 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
8283
});
8384
const { sftpResourceGroups } = useResourceGroupsForCurrentProject();
8485

86+
const sftpExclusionFilter =
87+
sftpResourceGroups && sftpResourceGroups.length > 0
88+
? `!(scaling_group in [${sftpResourceGroups.map((group) => `"${group}"`).join(', ')}])`
89+
: undefined;
90+
8591
const { agent_summary_list } = useLazyLoadQuery<AgentSummaryListQuery>(
8692
graphql`
8793
query AgentSummaryListQuery(
@@ -114,7 +120,7 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
114120
{
115121
limit: baiPaginationOption.limit,
116122
offset: baiPaginationOption.offset,
117-
filter: filterString,
123+
filter: mergeFilterValues([filterString, sftpExclusionFilter]),
118124
order,
119125
status: selectedStatus,
120126
},
@@ -124,12 +130,6 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
124130
},
125131
);
126132

127-
// Hide sFTP upload agents
128-
const filteredAgentSummaryList = _.filter(
129-
agent_summary_list?.items,
130-
(item) => !_.includes(sftpResourceGroups, item?.scaling_group),
131-
);
132-
133133
const columns: ColumnsType<AgentSummary> = [
134134
{
135135
title: <>ID</>,
@@ -421,7 +421,7 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
421421
bordered
422422
scroll={{ x: 'max-content' }}
423423
rowKey={'id'}
424-
dataSource={filterOutNullAndUndefined(filteredAgentSummaryList)}
424+
dataSource={filterOutNullAndUndefined(agent_summary_list?.items)}
425425
showSorterTooltip={false}
426426
columns={
427427
_.filter(
@@ -431,7 +431,7 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
431431
}
432432
pagination={{
433433
pageSize: tablePaginationOption.pageSize,
434-
total: filteredAgentSummaryList?.length || 0,
434+
total: agent_summary_list?.total_count || 0,
435435
current: tablePaginationOption.current,
436436
onChange(page, pageSize) {
437437
startPageChangeTransition(() => {

0 commit comments

Comments
 (0)