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

Commit 85fee4e

Browse files
committed
Merge branch '324-the-new-sort-works-but-is-not-persisted-with-version-234'
2 parents bcc2136 + 9c8a33b commit 85fee4e

File tree

9 files changed

+58
-34
lines changed

9 files changed

+58
-34
lines changed

src/cdm/FolderModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type BaseColumn = {
5454
isMetadata?: boolean;
5555
isSorted?: boolean;
5656
isSortedDesc?: boolean;
57+
sortIndex?: number;
5758
isHidden?: boolean;
5859
skipPersist?: boolean;
5960
isDragDisabled?: boolean;

src/components/CsvButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import Button from "@mui/material/Button";
21
import { CsvButtonProps } from "cdm/MenuBarModel";
32
import {
43
normalizeColumnsToCsvHeader,
54
normalizeRowsToCsvData,
65
} from "parsers/NormalizeRowsToCSV";
76
import React from "react";
87
import { CSVLink } from "react-csv";
9-
import DownloadIcon from "components/img/DownloadIcon";
8+
import DownloadIcon from "@mui/icons-material/Download";
9+
import { MenuButtonStyle } from "components/styles/NavBarStyles";
1010

1111
const CsvButton = (CsvButtonProps: CsvButtonProps) => {
1212
const { columns, rows, name } = CsvButtonProps;
@@ -35,7 +35,7 @@ const CsvButton = (CsvButtonProps: CsvButtonProps) => {
3535
ref={csvLink}
3636
target="_blank"
3737
>
38-
<DownloadIcon />
38+
<DownloadIcon {...MenuButtonStyle} />
3939
Download CSV
4040
</CSVLink>
4141
</>

src/components/NavBar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Toolbar from "@mui/material/Toolbar";
1717
import { c } from "helpers/StylesHelper";
1818
import Typography from "@mui/material/Typography";
1919
import DataviewFilters from "components/reducers/DataviewFilters";
20+
import { MenuButtonStyle } from "components/styles/NavBarStyles";
2021
import { SettingsModal } from "Settings";
2122

2223
export function NavBar(navBarProps: NavBarProps) {
@@ -98,11 +99,11 @@ export function NavBar(navBarProps: NavBarProps) {
9899
}}
99100
>
100101
<MenuItem onClick={handleSettingsClick} disableRipple>
101-
<SettingsIcon />
102+
<SettingsIcon {...MenuButtonStyle} />
102103
Settings
103104
</MenuItem>
104105
<MenuItem onClick={handleOpenAsMarkdownClick} disableRipple>
105-
<InsertDriveFileIcon />
106+
<InsertDriveFileIcon {...MenuButtonStyle} />
106107
Open as Markdown
107108
</MenuItem>
108109
<MenuItem disableRipple>

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ function sortingUpButton(headerActionResponse: HeaderActionResponse) {
5252
tablecolumn.isSorted && !tablecolumn.isSortedDesc ? false : true;
5353
tablecolumn.isSortedDesc = false;
5454
hooks.setExpanded(false);
55-
// Update state
56-
columnActions.alterSorting(tablecolumn);
57-
55+
// Save on memory
5856
let currentSorting = [...table.options.state.sorting];
5957
if (tablecolumn.isSorted) {
6058
currentSorting.remove(
@@ -64,12 +62,16 @@ function sortingUpButton(headerActionResponse: HeaderActionResponse) {
6462
id: tablecolumn.id,
6563
desc: tablecolumn.isSortedDesc,
6664
});
65+
tablecolumn.sortIndex = currentSorting.length;
6766
} else {
6867
currentSorting.remove(
6968
currentSorting.find((s) => s.id === tablecolumn.id)
7069
);
70+
tablecolumn.sortIndex = -1;
7171
}
7272
table.setSorting(currentSorting);
73+
// Save on disk
74+
columnActions.alterSorting(tablecolumn);
7375
};
7476
const isAscSorted = column.getIsSorted() === "asc";
7577
return headerButtonComponent({
@@ -96,8 +98,7 @@ function sortingDownButton(headerActionResponse: HeaderActionResponse) {
9698
tablecolumn.isSortedDesc = true;
9799

98100
hooks.setExpanded(false);
99-
// Update state
100-
columnActions.alterSorting(tablecolumn);
101+
// Update on memory
101102
let currentSorting = [...table.options.state.sorting];
102103
if (tablecolumn.isSorted) {
103104
currentSorting.remove(
@@ -107,12 +108,16 @@ function sortingDownButton(headerActionResponse: HeaderActionResponse) {
107108
id: tablecolumn.id,
108109
desc: tablecolumn.isSortedDesc,
109110
});
111+
tablecolumn.sortIndex = currentSorting.length;
110112
} else {
111113
currentSorting.remove(
112114
currentSorting.find((s) => s.id === tablecolumn.id)
113115
);
116+
tablecolumn.sortIndex = -1;
114117
}
115118
table.setSorting(currentSorting);
119+
// Update on disk
120+
columnActions.alterSorting(tablecolumn);
116121
};
117122

118123
return headerButtonComponent({

src/components/img/DownloadIcon.tsx

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

src/components/styles/NavBarStyles.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,11 @@ export const PaginationButtonStyle = {
5555
},
5656
backgroundColor: StyleVariables.TEXT_ACCENT,
5757
}
58-
}
58+
}
59+
60+
export const MenuButtonStyle = {
61+
sx: {
62+
color: StyleVariables.TEXT_ACCENT_HOVER,
63+
}
64+
}
65+

src/helpers/InitialType.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@ function obtainInitialType(columns: TableColumn[]): InitialType {
88
if (column.isSorted) {
99
sortElemList.push({
1010
id: column.key,
11-
desc: column.isSortedDesc
11+
desc: column.isSortedDesc,
1212
});
1313
}
1414
});
15+
// Sort by index
16+
sortElemList.sort((a: ColumnSort, b: ColumnSort) => {
17+
const aIndex = columns.find((column: TableColumn) => column.key === a.id)?.sortIndex;
18+
const bIndex = columns.find((column: TableColumn) => column.key === b.id)?.sortIndex;
19+
if (aIndex === -1 || bIndex === -1) {
20+
return 0;
21+
}
22+
return aIndex - bIndex;
23+
});
24+
1525
initialType.sortBy = sortElemList;
1626
return initialType;
1727
}

src/parsers/handlers/marshall/MarshallColumnsHandler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class MarshallColumnsHandler extends AbstractYamlHandler {
4747
this.addError(`There was not label in column ${key}`);
4848
column.label = key;
4949
}
50+
5051
if (column.skipPersist === undefined) {
5152
column.skipPersist = false;
5253
}
@@ -55,6 +56,10 @@ export class MarshallColumnsHandler extends AbstractYamlHandler {
5556
column.isHidden = false;
5657
}
5758

59+
if (column.sortIndex === undefined || typeof column.sortIndex !== 'number') {
60+
column.sortIndex = -1;
61+
}
62+
5863
/** CONFIG COLUMN INFO */
5964
if (!column.config && !(column.config instanceof Object)) {
6065
column.config = DEFAULT_COLUMN_CONFIG;

src/stateManagement/columns/handlers/AlterSortingColumnAction.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { TableColumn } from "cdm/FolderModel";
22
import { ColumnsState, TableActionResponse } from "cdm/TableStateInterface";
3+
import obtainInitialType from "helpers/InitialType";
34
import { AbstractTableAction } from "stateManagement/AbstractTableAction";
45

56
export default class AlterSortingColumnHandlerAction extends AbstractTableAction<ColumnsState> {
@@ -11,13 +12,29 @@ export default class AlterSortingColumnHandlerAction extends AbstractTableAction
1112
const index = newColumns.findIndex((c) => c.id === column.id);
1213
newColumns[index].isSorted = column.isSorted;
1314
newColumns[index].isSortedDesc = column.isSortedDesc;
15+
newColumns[index].sortIndex = column.sortIndex;
1416
view.diskConfig.updateColumnProperties(
1517
column.id,
1618
{
1719
isSorted: column.isSorted,
1820
isSortedDesc: column.isSortedDesc,
21+
sortIndex: column.sortIndex,
1922
}
2023
);
24+
// reordering index in case of current was removed
25+
if (column.sortIndex === -1) {
26+
const sortedColumns = obtainInitialType(newColumns);
27+
sortedColumns.sortBy.forEach((sortElem, index) => {
28+
view.diskConfig.updateColumnProperties(
29+
sortElem.id,
30+
{
31+
isSorted: true,
32+
isSortedDesc: sortElem.desc,
33+
sortIndex: index,
34+
}
35+
);
36+
});
37+
}
2138
return { columns: newColumns };
2239
});
2340

0 commit comments

Comments
 (0)