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

Commit 389de9e

Browse files
committed
Merge branch '247-21x-beta-column-name-and-order-bug'
2 parents 4d0eaf6 + 3d4b321 commit 389de9e

File tree

9 files changed

+49
-47
lines changed

9 files changed

+49
-47
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"react-dom": "18.2.0",
6363
"react-csv": "2.2.2",
6464
"react-popper": "2.3.0",
65-
"@tanstack/react-table": "8.5.10",
65+
"@tanstack/react-table": "8.5.11",
6666
"@tanstack/match-sorter-utils": "8.1.1",
6767
"react-select": "5.4.0",
6868
"react-color": "2.19.3",

src/cdm/TableStateInterface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface DataState {
3232
addRow: (filename: string, columns: TableColumn[], ddbbConfig: LocalSettings) => void;
3333
updateCell: (rowIndex: number, column: TableColumn, value: Literal, columns: TableColumn[], ddbbConfig: LocalSettings, isMovingFile?: boolean) => void;
3434
parseDataOfColumn: (column: TableColumn, input: string, ddbbConfig: LocalSettings) => void;
35-
updateDataAfterLabelChange: (column: TableColumn, label: string, columns: TableColumn[], ddbbConfig: LocalSettings) => void;
35+
updateDataAfterLabelChange: (column: TableColumn, label: string, columns: TableColumn[], ddbbConfig: LocalSettings) => Promise<void>;
3636
removeRow: (row: RowDataType) => void;
3737
removeDataOfColumn: (column: TableColumn) => void;
3838
}
@@ -46,7 +46,7 @@ export interface ColumnsState {
4646
alterSorting: (column: TableColumn) => void;
4747
addOptionToColumn: (column: TableColumn, option: string, backgroundColor: string) => void;
4848
alterColumnType: (column: TableColumn, input: string, parsedRows?: RowDataType[]) => void;
49-
alterColumnLabel: (column: TableColumn, label: string) => void;
49+
alterColumnLabel: (column: TableColumn, label: string) => Promise<void>;
5050
alterColumnSize: (id: string, width: number) => void;
5151
}
5252
export interface ColumnSortingState {

src/components/HeaderMenu.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
118118
table.setColumnOrder(updateOrderWithNewKey);
119119

120120
setkeyState(newKey);
121-
updateDataAfterLabelChange(
122-
column.columnDef as TableColumn,
123-
labelState,
124-
columns,
125-
ddbbConfig
126-
);
127-
128-
alterColumnLabel(column.columnDef as TableColumn, labelState);
121+
alterColumnLabel(column.columnDef as TableColumn, labelState).then(() => {
122+
updateDataAfterLabelChange(
123+
column.columnDef as TableColumn,
124+
labelState,
125+
columns,
126+
ddbbConfig
127+
);
128+
});
129129
}
130130

131131
function handleKeyDown(e: any) {
132132
if (e.key === "Enter") {
133-
persistLabelChange();
133+
inputRef.blur();
134134
}
135135
}
136136

src/components/Table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function Table(tableData: TableDataType) {
9696
);
9797
const findColumn = React.useCallback(
9898
(id: string) => {
99-
const findedColumn = columns.filter((c) => `${c.id}` === id)[0];
99+
const findedColumn = columns.find((c) => c.id === id);
100100
return {
101101
findedColumn,
102102
index: columns.indexOf(findedColumn),

src/components/TableHeader.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ export default function TableHeader(headerProps: TableHeaderProps) {
1717
headerProps;
1818
const { id } = header.column.columnDef as TableColumn;
1919
const { view, tableState } = table.options.meta;
20+
const { columnOrder } = table.options.state;
2021
const columns = tableState.columns((state) => state.columns);
22+
2123
const originalIndex = React.useMemo(() => {
22-
return columns.findIndex((col) => col.id === id);
23-
}, [columns]);
24+
return columnOrder.findIndex((colId) => colId === id);
25+
}, [columnOrder]);
26+
2427
//DnD
2528
const DnDref = React.useRef<HTMLDivElement>(null);
2629

27-
const initialOrder = React.useMemo(() => {
28-
return columns.map((d) => d.id);
29-
}, [columns]);
30-
3130
function moveColumn(source: number, destinationKey: string) {
3231
const { index: destIndex } = findColumn(destinationKey);
33-
initialOrder.splice(destIndex, 1);
34-
initialOrder.splice(source, 0, columns[destIndex].id);
35-
setColumnOrder(initialOrder);
36-
view.diskConfig.reorderColumns(initialOrder);
32+
const newColumnOrder = [...columnOrder];
33+
newColumnOrder.splice(destIndex, 1);
34+
newColumnOrder.splice(source, 0, columns[destIndex].id);
35+
setColumnOrder(newColumnOrder);
36+
view.diskConfig.reorderColumns(newColumnOrder);
3737
}
3838

3939
const [{ isDragging, handlerId }, drag] = useDrag(

src/helpers/VaultManagement.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
184184
const content = await VaultManagerDB.obtainContentFromTfile(file);
185185
const frontmatterKeys = VaultManagerDB.obtainFrontmatterKeys(content);
186186
const rowFields = obtainRowDatabaseFields(file, columns, frontmatterKeys);
187-
const column = columns.find(c => c.key === columnId);
187+
const column = columns.find(
188+
c => c.key === (UpdateRowOptions.COLUMN_KEY === option ? newValue : columnId)
189+
);
188190
// Adds an empty frontmatter at the beginning of the file
189191
async function addFrontmatter(): Promise<void> {
190192
/* Regex explanation
@@ -344,7 +346,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: Lit
344346
throw `Error: option ${option} not supported yet`;
345347
}
346348
} catch (e) {
347-
LOGGER.error(`${EditionError.YamlRead} - ${e}`);
349+
LOGGER.error(`${EditionError.YamlRead}`, e);
348350
new Notice(`${EditionError.YamlRead} : ${e.message}`, 6000);
349351
}
350352
LOGGER.info(`<= updateRowFile.asociatedFilePathToCell: ${file.path} | columnId: ${columnId} | newValue: ${newValue} | option: ${option} `);

src/services/DatabaseInfo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default class DatabaseInfo {
7171
* @param oldColumnId
7272
* @param newColumnId
7373
*/
74-
updateColumnKey(oldColumnId: string, newColumnId: string, newLabel: string) {
74+
async updateColumnKey(oldColumnId: string, newColumnId: string, newLabel: string) {
7575
// clone current column configuration
7676
const currentCol = this.yaml.columns[oldColumnId];
7777
// update column id
@@ -81,7 +81,7 @@ export default class DatabaseInfo {
8181
delete this.yaml.columns[oldColumnId];
8282
this.yaml.columns[newColumnId] = currentCol;
8383
// save on disk
84-
this.saveOnDisk();
84+
await this.saveOnDisk();
8585
}
8686

8787
/**

src/stateManagement/columns/handlers/AlterColumnLabelAction.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ import { AbstractTableAction } from "stateManagement/AbstractTableAction";
66
export default class AlterColumnLabelHandlerAction extends AbstractTableAction<ColumnsState> {
77
handle(tableActionResponse: TableActionResponse<ColumnsState>): TableActionResponse<ColumnsState> {
88
const { view, set, implementation } = tableActionResponse;
9-
implementation.alterColumnLabel = (column: TableColumn, label: string) =>
9+
implementation.alterColumnLabel = async (column: TableColumn, newLabel: string) =>
1010
set((updater) => {
1111
const labelIndex = updater.columns.findIndex(
1212
(col: TableColumn) => col.id === column.id
1313
);
14-
const newKey = dbTrim(label);
15-
updater.columns[labelIndex].label = label;
16-
updater.columns[labelIndex].id = newKey;
17-
updater.columns[labelIndex].key = newKey;
18-
updater.columns[labelIndex].accessorKey = newKey;
14+
const alteredColumns = [...updater.columns];
15+
const newKey = dbTrim(newLabel);
16+
alteredColumns[labelIndex].label = newLabel;
17+
alteredColumns[labelIndex].id = newKey;
18+
alteredColumns[labelIndex].key = newKey;
19+
alteredColumns[labelIndex].accessorKey = newKey;
1920
// Update configuration & row files on disk
20-
view.diskConfig.updateColumnKey(column.id, newKey, label);
21-
return { columns: updater.columns };
21+
view.diskConfig.updateColumnKey(column.id, newKey, newLabel);
22+
return { columns: alteredColumns };
2223
});
2324
tableActionResponse.implementation = implementation;
2425
return this.goNext(tableActionResponse);

src/stateManagement/data/handlers/UpdateDataAfterLabelChangeHandlerAction.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ import { AbstractTableAction } from "stateManagement/AbstractTableAction";
99
export default class UpdateDataAfterLabelChangeHandlerAction extends AbstractTableAction<DataState> {
1010
handle(tableActionResponse: TableActionResponse<DataState>): TableActionResponse<DataState> {
1111
const { set, implementation } = tableActionResponse;
12-
implementation.updateDataAfterLabelChange = (column: TableColumn, label: string, columns: TableColumn[], ddbbConfig: LocalSettings) => set((state) => {
12+
implementation.updateDataAfterLabelChange = async (column: TableColumn, label: string, columns: TableColumn[], ddbbConfig: LocalSettings) => set((state) => {
1313
const newKey = dbTrim(label);
1414
// Save on disk
15-
Promise.all(
16-
state.rows.map(async (row: RowDataType) => {
17-
updateRowFileProxy(
18-
row.__note__.getFile(),
19-
column.id,
20-
newKey,
21-
columns,
22-
ddbbConfig,
23-
UpdateRowOptions.COLUMN_KEY
24-
);
25-
}));
15+
state.rows.map(async (row: RowDataType) => {
16+
await updateRowFileProxy(
17+
row.__note__.getFile(),
18+
column.id,
19+
newKey,
20+
columns,
21+
ddbbConfig,
22+
UpdateRowOptions.COLUMN_KEY
23+
);
24+
});
2625

2726
// Save on memory
2827
const alterRows = state.rows.map((row) => {

0 commit comments

Comments
 (0)