Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 2c20510

Browse files
committed
Update documentation
1 parent aaaf147 commit 2c20510

File tree

6 files changed

+44
-72
lines changed

6 files changed

+44
-72
lines changed

src/cdm/TableStateInterface.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ export interface ColumnSortingState {
7272
sortBy: SortingState;
7373
actions: {
7474
alterSorting: (alternativeSorting: SortingState) => void;
75-
},
76-
info: {
77-
generateSorting: (currentCol: TableColumn, isSortedDesc: boolean) => SortingState;
7875
}
7976
}
8077
export interface RowTemplateState {

src/components/behavior/SortingColumns.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/components/headerActions/handlers/buttons/SortHandlerAction.tsx

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,33 @@ function sortingUpButton(headerActionResponse: HeaderActionResponse) {
4343
const { table, column } = headerActionResponse.headerMenuProps.headerProps;
4444

4545
const tablecolumn = column.columnDef as TableColumn;
46-
const [sortingInfo, sortingActions] = table.options.meta.tableState.sorting(
47-
(store) => [store.info, store.actions]
48-
);
4946
const columnActions = table.options.meta.tableState.columns(
5047
(store) => store.actions
5148
);
5249

53-
const sortingUpOnClick = (e: any) => {
54-
const sortArray = sortingInfo.generateSorting(tablecolumn, false);
50+
const sortingUpOnClick = () => {
5551
tablecolumn.isSorted =
5652
tablecolumn.isSorted && !tablecolumn.isSortedDesc ? false : true;
5753
tablecolumn.isSortedDesc = false;
5854
hooks.setExpanded(false);
5955
// Update state
6056
columnActions.alterSorting(tablecolumn);
61-
sortingActions.alterSorting(sortArray);
62-
table.setSorting(sortArray);
57+
58+
let currentSorting = [...table.options.state.sorting];
59+
if (tablecolumn.isSorted) {
60+
currentSorting.remove(
61+
currentSorting.find((s) => s.id === tablecolumn.id)
62+
);
63+
currentSorting.push({
64+
id: tablecolumn.id,
65+
desc: tablecolumn.isSortedDesc,
66+
});
67+
} else {
68+
currentSorting.remove(
69+
currentSorting.find((s) => s.id === tablecolumn.id)
70+
);
71+
}
72+
table.setSorting(currentSorting);
6373
};
6474
const isAscSorted = column.getIsSorted() === "asc";
6575
return headerButtonComponent({
@@ -75,25 +85,36 @@ function sortingDownButton(headerActionResponse: HeaderActionResponse) {
7585
headerActionResponse.headerMenuProps.headerProps;
7686

7787
const tablecolumn = column.columnDef as TableColumn;
78-
const [sortingInfo, sortingActions] = table.options.meta.tableState.sorting(
79-
(store) => [store.info, store.actions]
80-
);
88+
8189
const columnActions = table.options.meta.tableState.columns(
8290
(store) => store.actions
8391
);
8492

85-
const sortingDownOnClick = (e: any) => {
86-
const sortArray = sortingInfo.generateSorting(tablecolumn, true);
93+
const sortingDownOnClick = () => {
8794
tablecolumn.isSorted =
8895
tablecolumn.isSorted && tablecolumn.isSortedDesc ? false : true;
8996
tablecolumn.isSortedDesc = true;
9097

9198
hooks.setExpanded(false);
9299
// Update state
93100
columnActions.alterSorting(tablecolumn);
94-
sortingActions.alterSorting(sortArray);
95-
table.setSorting(sortArray);
101+
let currentSorting = [...table.options.state.sorting];
102+
if (tablecolumn.isSorted) {
103+
currentSorting.remove(
104+
currentSorting.find((s) => s.id === tablecolumn.id)
105+
);
106+
currentSorting.push({
107+
id: tablecolumn.id,
108+
desc: tablecolumn.isSortedDesc,
109+
});
110+
} else {
111+
currentSorting.remove(
112+
currentSorting.find((s) => s.id === tablecolumn.id)
113+
);
114+
}
115+
table.setSorting(currentSorting);
96116
};
117+
97118
return headerButtonComponent({
98119
onClick: sortingDownOnClick,
99120
icon:

src/helpers/InitialType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ColumnSort } from "@tanstack/react-table";
2-
import { InitialType, RowDataType, TableColumn } from "cdm/FolderModel";
2+
import { InitialType, TableColumn } from "cdm/FolderModel";
33

44
function obtainInitialType(columns: TableColumn[]): InitialType {
55
const initialType: InitialType = {};

src/stateManagement/columns/handlers/AlterSortingColumnAction.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ import { AbstractTableAction } from "stateManagement/AbstractTableAction";
44

55
export default class AlterSortingColumnHandlerAction extends AbstractTableAction<ColumnsState> {
66
handle(tableActionResponse: TableActionResponse<ColumnsState>): TableActionResponse<ColumnsState> {
7-
const { set, implementation } = tableActionResponse;
7+
const { view, set, implementation } = tableActionResponse;
88
implementation.actions.alterSorting = (column: TableColumn) =>
99
set((updater) => {
1010
const newColumns = [...updater.columns];
1111
const index = newColumns.findIndex((c) => c.id === column.id);
1212
newColumns[index].isSorted = column.isSorted;
1313
newColumns[index].isSortedDesc = column.isSortedDesc;
14+
view.diskConfig.updateColumnProperties(
15+
column.id,
16+
{
17+
isSorted: column.isSorted,
18+
isSortedDesc: column.isSortedDesc,
19+
}
20+
);
1421
return { columns: newColumns };
1522
});
1623

src/stateManagement/useSortingStore.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { SortingState } from "@tanstack/react-table";
2-
import { TableColumn } from "cdm/FolderModel";
32
import { ColumnSortingState } from "cdm/TableStateInterface"
4-
import { generateSortedColumns } from "components/behavior/SortingColumns";
53
import { DatabaseView } from "DatabaseView";
64
import create from "zustand"
75

@@ -11,15 +9,6 @@ const useSortingStore = (view: DatabaseView) => {
119
sortBy: view.initial.sortBy,
1210
actions: {
1311
alterSorting: (alternativeSorting: SortingState) => set(() => ({ sortBy: alternativeSorting }))
14-
},
15-
info: {
16-
generateSorting: (currentCol: TableColumn, isSortedDesc: boolean) => {
17-
return generateSortedColumns(
18-
view,
19-
currentCol,
20-
isSortedDesc
21-
)
22-
}
2312
}
2413
}),
2514
);

0 commit comments

Comments
 (0)