fix: enable channel table server-side sorting (#4600)
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
getCoreRowModel,
|
||||
useReactTable,
|
||||
getExpandedRowModel,
|
||||
type OnChangeFn,
|
||||
type SortingState,
|
||||
type VisibilityState,
|
||||
type ExpandedState,
|
||||
@@ -33,13 +34,22 @@ import {
|
||||
getChannelTypeIcon,
|
||||
getChannelTypeLabel,
|
||||
} from '../lib'
|
||||
import type { Channel } from '../types'
|
||||
import type { Channel, ChannelSortBy } from '../types'
|
||||
import { useChannelsColumns } from './channels-columns'
|
||||
import { useChannels } from './channels-provider'
|
||||
import { DataTableBulkActions } from './data-table-bulk-actions'
|
||||
|
||||
const route = getRouteApi('/_authenticated/channels/')
|
||||
|
||||
const CHANNEL_SORTABLE_COLUMNS = new Set<ChannelSortBy>([
|
||||
'id',
|
||||
'name',
|
||||
'priority',
|
||||
'balance',
|
||||
'response_time',
|
||||
'test_time',
|
||||
])
|
||||
|
||||
function isDisabledChannelRow(channel: Channel) {
|
||||
return (
|
||||
!isTagAggregateRow(channel) && channel.status !== CHANNEL_STATUS.ENABLED
|
||||
@@ -121,6 +131,31 @@ export function ChannelsTable() {
|
||||
// Determine whether to use search or regular list API
|
||||
const shouldSearch = Boolean(globalFilter?.trim() || modelFilter.trim())
|
||||
|
||||
const sortParams = useMemo(() => {
|
||||
const activeSort = sorting[0]
|
||||
if (
|
||||
!activeSort ||
|
||||
!CHANNEL_SORTABLE_COLUMNS.has(activeSort.id as ChannelSortBy)
|
||||
) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
sort_by: activeSort.id as ChannelSortBy,
|
||||
sort_order: activeSort.desc ? 'desc' : 'asc',
|
||||
} as const
|
||||
}, [sorting])
|
||||
|
||||
const handleSortingChange: OnChangeFn<SortingState> = (updater) => {
|
||||
setSorting((previous) => {
|
||||
const next = typeof updater === 'function' ? updater(previous) : updater
|
||||
if (pagination.pageIndex > 0) {
|
||||
onPaginationChange({ ...pagination, pageIndex: 0 })
|
||||
}
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
// Fetch groups for filter
|
||||
const { data: groupsData } = useQuery({
|
||||
queryKey: ['groups'],
|
||||
@@ -156,6 +191,7 @@ export function ChannelsTable() {
|
||||
: undefined,
|
||||
tag_mode: enableTagMode,
|
||||
id_sort: idSort,
|
||||
...sortParams,
|
||||
p: pagination.pageIndex + 1,
|
||||
page_size: pagination.pageSize,
|
||||
}),
|
||||
@@ -178,6 +214,7 @@ export function ChannelsTable() {
|
||||
: undefined,
|
||||
tag_mode: enableTagMode,
|
||||
id_sort: idSort,
|
||||
...sortParams,
|
||||
p: pagination.pageIndex + 1,
|
||||
page_size: pagination.pageSize,
|
||||
})
|
||||
@@ -197,6 +234,7 @@ export function ChannelsTable() {
|
||||
: undefined,
|
||||
tag_mode: enableTagMode,
|
||||
id_sort: idSort,
|
||||
...sortParams,
|
||||
p: pagination.pageIndex + 1,
|
||||
page_size: pagination.pageSize,
|
||||
})
|
||||
@@ -238,7 +276,7 @@ export function ChannelsTable() {
|
||||
},
|
||||
enableRowSelection: (row: Row<Channel>) => !isTagAggregateRow(row.original),
|
||||
onRowSelectionChange: setRowSelection,
|
||||
onSortingChange: setSorting,
|
||||
onSortingChange: handleSortingChange,
|
||||
onColumnFiltersChange,
|
||||
onColumnVisibilityChange: setColumnVisibility,
|
||||
onPaginationChange,
|
||||
|
||||
+14
@@ -194,6 +194,16 @@ export interface MultiKeyStatusResponse {
|
||||
// API Request Parameters
|
||||
// ============================================================================
|
||||
|
||||
export type ChannelSortBy =
|
||||
| 'id'
|
||||
| 'name'
|
||||
| 'priority'
|
||||
| 'balance'
|
||||
| 'response_time'
|
||||
| 'test_time'
|
||||
|
||||
export type ChannelSortOrder = 'asc' | 'desc'
|
||||
|
||||
export interface GetChannelsParams {
|
||||
p?: number
|
||||
page_size?: number
|
||||
@@ -202,6 +212,8 @@ export interface GetChannelsParams {
|
||||
group?: string
|
||||
id_sort?: boolean
|
||||
tag_mode?: boolean
|
||||
sort_by?: ChannelSortBy
|
||||
sort_order?: ChannelSortOrder
|
||||
}
|
||||
|
||||
export interface SearchChannelsParams {
|
||||
@@ -212,6 +224,8 @@ export interface SearchChannelsParams {
|
||||
type?: number
|
||||
id_sort?: boolean
|
||||
tag_mode?: boolean
|
||||
sort_by?: ChannelSortBy
|
||||
sort_order?: ChannelSortOrder
|
||||
p?: number
|
||||
page_size?: number
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1108,7 +1108,7 @@
|
||||
"Deployment Region *": "Région de déploiement *",
|
||||
"Deployment requested": "Déploiement demandé",
|
||||
"Deployments": "Déploiements",
|
||||
"Desc": "Description",
|
||||
"Desc": "Desc.",
|
||||
"Describe": "Décrire",
|
||||
"Describe this model...": "Décrire ce modèle...",
|
||||
"Describe this vendor...": "Décrire ce fournisseur...",
|
||||
|
||||
Vendored
+1
-1
@@ -1108,7 +1108,7 @@
|
||||
"Deployment Region *": "デプロイリージョン *",
|
||||
"Deployment requested": "デプロイメントが要求されました",
|
||||
"Deployments": "デプロイ",
|
||||
"Desc": "説明",
|
||||
"Desc": "降順",
|
||||
"Describe": "説明",
|
||||
"Describe this model...": "このモデルを説明...",
|
||||
"Describe this vendor...": "このベンダーを説明...",
|
||||
|
||||
Vendored
+1
-1
@@ -1108,7 +1108,7 @@
|
||||
"Deployment Region *": "Регион развертывания *",
|
||||
"Deployment requested": "Развертывание запрошено",
|
||||
"Deployments": "Развертывания",
|
||||
"Desc": "Описание",
|
||||
"Desc": "По убыванию",
|
||||
"Describe": "Описание",
|
||||
"Describe this model...": "Опишите эту модель...",
|
||||
"Describe this vendor...": "Опишите этого поставщика...",
|
||||
|
||||
Vendored
+1
-1
@@ -1108,7 +1108,7 @@
|
||||
"Deployment Region *": "Khu vực triển khai *",
|
||||
"Deployment requested": "Yêu cầu triển khai",
|
||||
"Deployments": "Triển khai",
|
||||
"Desc": "Mô tả",
|
||||
"Desc": "Giảm dần",
|
||||
"Describe": "Mô tả",
|
||||
"Describe this model...": "Mô tả mô hình này...",
|
||||
"Describe this vendor...": "Mô tả nhà cung cấp này...",
|
||||
|
||||
Vendored
+1
-1
@@ -1108,7 +1108,7 @@
|
||||
"Deployment Region *": "部署区域 *",
|
||||
"Deployment requested": "部署已请求",
|
||||
"Deployments": "部署",
|
||||
"Desc": "描述",
|
||||
"Desc": "降序",
|
||||
"Describe": "图生文",
|
||||
"Describe this model...": "描述此模型...",
|
||||
"Describe this vendor...": "描述此供应商...",
|
||||
|
||||
Reference in New Issue
Block a user