Skip to content

fix(common): table unsorting will be in descending order #2107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions shell/app/common/components/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function WrappedTable<T extends object = any>({
const sortCompareRef = React.useRef<((a: T, b: T) => number) | null>(null);
const [defaultPagination, setDefaultPagination] = React.useState<TablePaginationConfig>({
current: 1,
total: dataSource.length,
total: dataSource?.length || 0,
...PAGINATION,
});
const isFrontendPaging = !(paginationProps && paginationProps.current) && paginationProps !== false; // Determine whether front-end paging
Expand All @@ -82,7 +82,7 @@ function WrappedTable<T extends object = any>({
const { current = 1, pageSize = PAGINATION.pageSize } = pagination;

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

const onTableChange = React.useCallback(
Expand Down Expand Up @@ -136,7 +136,7 @@ function WrappedTable<T extends object = any>({
const onSort = (order?: 'ascend' | 'descend') => {
setSort({ ...sorter, order });
const { sorter: columnSorter } = column as { sorter: { compare: (a: T, b: T) => number } };
if (columnSorter?.compare) {
if (order && columnSorter?.compare) {
sortCompareRef.current = (a: T, b: T) => {
if (order === 'ascend') {
return columnSorter?.compare?.(a, b);
Expand Down Expand Up @@ -250,7 +250,7 @@ function WrappedTable<T extends object = any>({
);
}, [allColumns, sorterMenu, sort, onRow]);

let data = [...dataSource] as T[];
let data: T[] = dataSource ? [...dataSource] : [];

if (sortCompareRef.current) {
data = data.sort(sortCompareRef.current);
Expand Down