Skip to content

Commit fb76c04

Browse files
committed
fix(common): table unsorting will be in descending order
1 parent a130d7b commit fb76c04

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

shell/app/common/components/table/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function WrappedTable<T extends object = any>({
7171
const sortCompareRef = React.useRef<((a: T, b: T) => number) | null>(null);
7272
const [defaultPagination, setDefaultPagination] = React.useState<TablePaginationConfig>({
7373
current: 1,
74-
total: dataSource.length,
74+
total: dataSource?.length || 0,
7575
...PAGINATION,
7676
});
7777
const isFrontendPaging = !(paginationProps && paginationProps.current) && paginationProps !== false; // Determine whether front-end paging
@@ -82,7 +82,7 @@ function WrappedTable<T extends object = any>({
8282
const { current = 1, pageSize = PAGINATION.pageSize } = pagination;
8383

8484
React.useEffect(() => {
85-
setDefaultPagination((before) => ({ ...before, current: 1, total: dataSource.length }));
85+
setDefaultPagination((before) => ({ ...before, current: 1, total: dataSource?.length || 0 }));
8686
}, [dataSource]);
8787

8888
const onTableChange = React.useCallback(
@@ -136,7 +136,7 @@ function WrappedTable<T extends object = any>({
136136
const onSort = (order?: 'ascend' | 'descend') => {
137137
setSort({ ...sorter, order });
138138
const { sorter: columnSorter } = column as { sorter: { compare: (a: T, b: T) => number } };
139-
if (columnSorter?.compare) {
139+
if (order && columnSorter?.compare) {
140140
sortCompareRef.current = (a: T, b: T) => {
141141
if (order === 'ascend') {
142142
return columnSorter?.compare?.(a, b);
@@ -250,7 +250,7 @@ function WrappedTable<T extends object = any>({
250250
);
251251
}, [allColumns, sorterMenu, sort, onRow]);
252252

253-
let data = [...dataSource] as T[];
253+
let data: T[] = dataSource ? [...dataSource] : [];
254254

255255
if (sortCompareRef.current) {
256256
data = data.sort(sortCompareRef.current);

shell/app/modules/org/pages/projects/project-list.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export const ProjectList = () => {
182182
</BootPrompt>
183183
<Table
184184
rowKey="id"
185-
dataSource={list}
185+
dataSource={null}
186186
columns={getColumns()}
187187
rowClassName={() => 'cursor-pointer'}
188188
slot={

0 commit comments

Comments
 (0)