fix: cancel sorting

This commit is contained in:
jialin
2025-12-24 15:40:19 +08:00
parent a9b58a5564
commit b25189feea
16 changed files with 51 additions and 12 deletions
@@ -7,11 +7,12 @@ interface HeaderProps {
columns: SealColumnProps[]; columns: SealColumnProps[];
sortDirections?: ('ascend' | 'descend' | null)[]; sortDirections?: ('ascend' | 'descend' | null)[];
sorterList: TableOrder | Array<TableOrder>; sorterList: TableOrder | Array<TableOrder>;
showSorterTooltip?: boolean;
onSort?: OnSortFn; onSort?: OnSortFn;
} }
const Header: React.FC<HeaderProps> = (props) => { const Header: React.FC<HeaderProps> = (props) => {
const { onSort, sortDirections, sorterList } = props; const { onSort, sortDirections, sorterList, showSorterTooltip } = props;
return ( return (
<Row className="row"> <Row className="row">
@@ -31,6 +32,7 @@ const Header: React.FC<HeaderProps> = (props) => {
<Col span={span} key={dataIndex || i}> <Col span={span} key={dataIndex || i}>
<TableHeader <TableHeader
onSort={onSort} onSort={onSort}
showSorterTooltip={showSorterTooltip}
sorter={sorter} sorter={sorter}
sorterList={sorterList} sorterList={sorterList}
dataIndex={dataIndex} dataIndex={dataIndex}
@@ -1,5 +1,6 @@
import AutoTooltip from '@/components/auto-tooltip'; import AutoTooltip from '@/components/auto-tooltip';
import { CaretDownOutlined, CaretUpOutlined } from '@ant-design/icons'; import { CaretDownOutlined, CaretUpOutlined } from '@ant-design/icons';
import { useIntl } from '@umijs/max';
import classNames from 'classnames'; import classNames from 'classnames';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import '../styles/header.less'; import '../styles/header.less';
@@ -22,6 +23,7 @@ const TableHeader: React.FC<TableHeaderProps> = (props) => {
width, width,
dataIndex dataIndex
} = props; } = props;
const intl = useIntl();
const [currentSortOrder, setCurrentSortOrder] = React.useState< const [currentSortOrder, setCurrentSortOrder] = React.useState<
'ascend' | 'descend' | null 'ascend' | 'descend' | null
@@ -33,6 +35,16 @@ const TableHeader: React.FC<TableHeaderProps> = (props) => {
return sortDirections[nextIndex]; return sortDirections[nextIndex];
}; };
const nextSortTips = () => {
if (!currentSortOrder) {
return intl.formatMessage({ id: 'common.sorter.tips.ascend' });
}
if (currentSortOrder === 'ascend') {
return intl.formatMessage({ id: 'common.sorter.tips.descend' });
}
return intl.formatMessage({ id: 'common.sorter.tips.cancel' });
};
const handleOnSort = () => { const handleOnSort = () => {
setCurrentSortOrder((prev) => { setCurrentSortOrder((prev) => {
const next = getNextSortOrder(prev); const next = getNextSortOrder(prev);
+2
View File
@@ -45,6 +45,7 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
pagination, pagination,
empty, empty,
sortDirections, sortDirections,
showSorterTooltip,
renderChildren, renderChildren,
loadChildren, loadChildren,
loadChildrenAPI loadChildrenAPI
@@ -167,6 +168,7 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
columns={parsedColumns} columns={parsedColumns}
sortDirections={sortDirections} sortDirections={sortDirections}
sorterList={sorterList} sorterList={sorterList}
showSorterTooltip={showSorterTooltip}
></Header> ></Header>
</div> </div>
<Spin spinning={loading}> <Spin spinning={loading}>
@@ -41,6 +41,7 @@
.sorter-header { .sorter-header {
display: flex; display: flex;
flex: 1; flex: 1;
width: 100%;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
cursor: pointer; cursor: pointer;
+2
View File
@@ -44,6 +44,7 @@ export interface SealColumnProps {
} }
export interface TableHeaderProps { export interface TableHeaderProps {
showSorterTooltip?: boolean;
sorterList?: TableOrder | Array<TableOrder>; sorterList?: TableOrder | Array<TableOrder>;
sorter?: boolean | { multiple?: number }; sorter?: boolean | { multiple?: number };
sortDirections?: ('ascend' | 'descend' | null)[]; sortDirections?: ('ascend' | 'descend' | null)[];
@@ -78,6 +79,7 @@ export type TableOrder = {
order: 'ascend' | 'descend' | null; order: 'ascend' | 'descend' | null;
}; };
export interface SealTableProps { export interface SealTableProps {
showSorterTooltip?: boolean;
sortDirections?: ('ascend' | 'descend' | null)[]; sortDirections?: ('ascend' | 'descend' | null)[];
columns?: SealColumnProps[]; columns?: SealColumnProps[];
childParentKey?: string; childParentKey?: string;
+1 -1
View File
@@ -15,7 +15,7 @@ type SortDirection = 'ascend' | 'descend' | null;
export const TABLE_SORT_DIRECTIONS: SortDirection[] = [ export const TABLE_SORT_DIRECTIONS: SortDirection[] = [
'ascend', 'ascend',
'descend', 'descend',
'ascend' null
]; ];
export const tableSorter = (order: number | boolean) => { export const tableSorter = (order: number | boolean) => {
+4 -1
View File
@@ -266,5 +266,8 @@ export default {
'common.form.rule.selectInput': 'Please select or enter a {name}', 'common.form.rule.selectInput': 'Please select or enter a {name}',
'common.tag.experimental': 'Experimental', 'common.tag.experimental': 'Experimental',
'common.title.example': 'Example', 'common.title.example': 'Example',
'common.button.dontshowagain': "Don't show again" 'common.button.dontshowagain': "Don't show again",
'common.sorter.tips.ascend': 'Click to sort ascending',
'common.sorter.tips.descend': 'Click to sort descending',
'common.sorter.tips.cancel': 'Click to cancel sorting'
}; };
+8 -2
View File
@@ -266,7 +266,10 @@ export default {
'common.form.rule.selectInput': 'Please select or enter a {name}', 'common.form.rule.selectInput': 'Please select or enter a {name}',
'common.tag.experimental': 'Experimental', 'common.tag.experimental': 'Experimental',
'common.title.example': 'Example', 'common.title.example': 'Example',
'common.button.dontshowagain': "Don't show again" 'common.button.dontshowagain': "Don't show again",
'common.sorter.tips.ascend': 'Click to sort ascending',
'common.sorter.tips.descend': 'Click to sort descending',
'common.sorter.tips.cancel': 'Click to cancel sorting'
}; };
// ========== To-Do: Translate Keys (Remove After Translation) ========== // ========== To-Do: Translate Keys (Remove After Translation) ==========
@@ -298,5 +301,8 @@ export default {
// 26. 'common.form.rule.selectInput': 'Please select or enter a {name}', // 26. 'common.form.rule.selectInput': 'Please select or enter a {name}',
// 27. 'common.tag.experimental': 'Experimental', // 27. 'common.tag.experimental': 'Experimental',
// 28. 'common.title.example': 'Example', // 28. 'common.title.example': 'Example',
// 29. 'common.button.dontshowagain': "Don't show again" // 29. 'common.button.dontshowagain': "Don't show again",
// 30. 'common.sorter.tips.ascend': 'Click to sort ascending',
// 31. 'common.sorter.tips.descend': 'Click to sort descending',
// 32. 'common.sorter.tips.cancel': 'Click to cancel sorting'
// ========== End of To-Do List ========== // ========== End of To-Do List ==========
+1 -1
View File
@@ -133,5 +133,5 @@ export default {
// 12. 'clusters.form.serverUrl.tips': 'Specify the server URL accessible from your cloud provider.' // 12. 'clusters.form.serverUrl.tips': 'Specify the server URL accessible from your cloud provider.'
// 13. 'clusters.addworker.specifyWorkerIP': 'Specify Worker IP <span class="text-tertiary">{type}</span>', // 13. 'clusters.addworker.specifyWorkerIP': 'Specify Worker IP <span class="text-tertiary">{type}</span>',
// 14. 'clusters.form.setDefault': 'Set as Default', // 14. 'clusters.form.setDefault': 'Set as Default',
// 15. 'clusters.form.setDefault.tips': 'Default for deployment' // 15. 'clusters.form.setDefault.tips': 'Default for deployment',
// ================================================================ // ================================================================
+8 -2
View File
@@ -265,9 +265,15 @@ export default {
'common.form.rule.selectInput': 'Выберите или введите {name}', 'common.form.rule.selectInput': 'Выберите или введите {name}',
'common.tag.experimental': 'Экспериментальный', 'common.tag.experimental': 'Экспериментальный',
'common.title.example': 'Пример', 'common.title.example': 'Пример',
'common.button.dontshowagain': "Don't show again" 'common.button.dontshowagain': "Don't show again",
'common.sorter.tips.ascend': 'Click to sort ascending',
'common.sorter.tips.descend': 'Click to sort descending',
'common.sorter.tips.cancel': 'Click to cancel sorting'
}; };
// ========== To-Do: Translate Keys (Remove After Translation) ========== // ========== To-Do: Translate Keys (Remove After Translation) ==========
// 1. 'common.button.dontshowagain': "Don't show again" // 1. 'common.button.dontshowagain': "Don't show again",
// 2. 'common.sorter.tips.ascend': 'Click to sort ascending',
// 3. 'common.sorter.tips.descend': 'Click to sort descending',
// 4. 'common.sorter.tips.cancel': 'Click to cancel sorting'
// ========== End of To-Do List ========== // ========== End of To-Do List ==========
+4 -1
View File
@@ -258,5 +258,8 @@ export default {
'common.form.rule.selectInput': '请选择或输入{name}', 'common.form.rule.selectInput': '请选择或输入{name}',
'common.tag.experimental': '实验性', 'common.tag.experimental': '实验性',
'common.title.example': '示例', 'common.title.example': '示例',
'common.button.dontshowagain': '不再提示' 'common.button.dontshowagain': '不再提示',
'common.sorter.tips.ascend': '点击升序',
'common.sorter.tips.descend': '点击降序',
'common.sorter.tips.cancel': '取消排序'
}; };
+3 -1
View File
@@ -6,6 +6,7 @@ import SealTable from '@/components/seal-table';
import TableContext from '@/components/seal-table/table-context'; import TableContext from '@/components/seal-table/table-context';
import { TableOrder } from '@/components/seal-table/types'; import { TableOrder } from '@/components/seal-table/types';
import { PageAction } from '@/config'; import { PageAction } from '@/config';
import { TABLE_SORT_DIRECTIONS } from '@/config/settings';
import type { PageActionType } from '@/config/types'; import type { PageActionType } from '@/config/types';
import useExpandedRowKeys from '@/hooks/use-expanded-row-keys'; import useExpandedRowKeys from '@/hooks/use-expanded-row-keys';
import useTableFetch from '@/hooks/use-table-fetch'; import useTableFetch from '@/hooks/use-table-fetch';
@@ -326,12 +327,13 @@ const Clusters: React.FC = () => {
<SealTable <SealTable
rowKey="id" rowKey="id"
loadChildren={getWorkerPoolList} loadChildren={getWorkerPoolList}
sortDirections={['descend', 'ascend']} sortDirections={TABLE_SORT_DIRECTIONS}
expandedRowKeys={expandedRowKeys} expandedRowKeys={expandedRowKeys}
onExpand={handleExpandChange} onExpand={handleExpandChange}
onExpandAll={handleToggleExpandAll} onExpandAll={handleToggleExpandAll}
renderChildren={renderChildren} renderChildren={renderChildren}
onTableSort={handleOnSortChange} onTableSort={handleOnSortChange}
showSorterTooltip={false}
dataSource={dataSource.dataList} dataSource={dataSource.dataList}
loading={dataSource.loading} loading={dataSource.loading}
loadend={dataSource.loadend} loadend={dataSource.loadend}
@@ -36,7 +36,6 @@ const useCredentialColumns = (
{ {
title: intl.formatMessage({ id: 'common.table.createTime' }), title: intl.formatMessage({ id: 'common.table.createTime' }),
dataIndex: 'created_at', dataIndex: 'created_at',
showSorterTooltip: false,
sorter: tableSorter(3), sorter: tableSorter(3),
ellipsis: { ellipsis: {
showTitle: false showTitle: false
@@ -727,6 +727,7 @@ const Models: React.FC<ModelsProps> = ({
dataSource={dataSource} dataSource={dataSource}
rowSelection={rowSelection} rowSelection={rowSelection}
expandedRowKeys={expandedRowKeys} expandedRowKeys={expandedRowKeys}
showSorterTooltip={false}
onExpand={handleExpandChange} onExpand={handleExpandChange}
onExpandAll={handleToggleExpandAll} onExpandAll={handleToggleExpandAll}
loading={loading} loading={loading}
+1
View File
@@ -327,6 +327,7 @@ const Models: React.FC = () => {
setQueryParams((pre: any) => { setQueryParams((pre: any) => {
return { return {
...pre, ...pre,
page: 1,
sort_by: sortKeys.join(',') sort_by: sortKeys.join(',')
}; };
}); });
@@ -179,7 +179,6 @@ const useUsersColumns = ({
title: intl.formatMessage({ id: 'common.table.createTime' }), title: intl.formatMessage({ id: 'common.table.createTime' }),
dataIndex: 'created_at', dataIndex: 'created_at',
key: 'created_at', key: 'created_at',
showSorterTooltip: false,
sorter: tableSorter(5), sorter: tableSorter(5),
ellipsis: { ellipsis: {
showTitle: false showTitle: false