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

Commit 3c2f827

Browse files
committed
visual fixed
1 parent 65ae508 commit 3c2f827

File tree

5 files changed

+73
-47
lines changed

5 files changed

+73
-47
lines changed

docs/changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.2.1
2+
### Improved
3+
- Now when you press enter inside a text cell, it will ends the modification with onBlur event.
4+
### No longer broken
5+
- Create a column now adjust width automatically.
6+
- total width of columns not broken anymore. This bug was introduced in 0.2.0
17
## 0.2.0
28
*Published on 2022/05/07*
39
### Shiny new things

src/components/HeaderMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
206206
settingsReferenceElement,
207207
settingsPopperElement,
208208
{
209-
placement: "right",
209+
placement: "auto",
210210
strategy: "fixed",
211211
}
212212
);

src/components/reducers/DatabaseDispatch.tsx

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -100,49 +100,50 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
100100
// trim label will get a valid yaml key
101101
const update_col_key: string = dbTrim(action.label);
102102
// Update configuration & row files on disk
103-
state.view.diskConfig.updateColumnProperties(action.columnId, {
104-
label: action.label,
105-
accessor: update_col_key,
106-
key: update_col_key,
107-
});
108-
// Once the column is updated, update the rows in case the key is changed
109-
Promise.all(
110-
state.data.map(async (row: RowDataType) => {
111-
updateRowFile(
112-
row.note.getFile(),
113-
state.columns[update_column_label_index].key,
114-
update_col_key,
115-
state,
116-
UpdateRowOptions.COLUMN_KEY
103+
104+
state.view.diskConfig
105+
.updateColumnKey(action.columnId, update_col_key, action.label)
106+
.then(async () => {
107+
// Once the column is updated, update the rows in case the key is changed
108+
109+
await Promise.all(
110+
state.data.map(async (row: RowDataType) => {
111+
await updateRowFile(
112+
row.note.getFile(),
113+
action.columnId,
114+
update_col_key,
115+
state,
116+
UpdateRowOptions.COLUMN_KEY
117+
);
118+
})
117119
);
118-
})
119-
);
120-
// Update state
121-
return {
122-
...state,
123-
skipReset: true,
124-
// Add column visually into the new label
125-
columns: [
126-
...state.columns.slice(0, update_column_label_index),
127-
{
128-
...state.columns[update_column_label_index],
129-
label: action.label,
130-
id: update_col_key,
131-
key: update_col_key,
132-
accessor: update_col_key,
133-
},
134-
...state.columns.slice(
135-
update_column_label_index + 1,
136-
state.columns.length
137-
),
138-
],
139-
// Add data visually into the new label
140-
data: state.data.map((row: RowDataType) => {
141-
row[update_col_key] = row[action.columnId];
142-
delete row[action.columnId];
143-
return row;
144-
}),
145-
};
120+
// Update state
121+
return {
122+
...state,
123+
skipReset: true,
124+
// Add column visually into the new label
125+
columns: [
126+
...state.columns.slice(0, update_column_label_index),
127+
{
128+
...state.columns[update_column_label_index],
129+
label: action.label,
130+
id: update_col_key,
131+
key: update_col_key,
132+
accessor: update_col_key,
133+
},
134+
...state.columns.slice(
135+
update_column_label_index + 1,
136+
state.columns.length
137+
),
138+
],
139+
// Add data visually into the new label
140+
data: state.data.map((row: RowDataType) => {
141+
row[update_col_key] = row[action.columnId];
142+
delete row[action.columnId];
143+
return row;
144+
}),
145+
};
146+
});
146147

147148
/**
148149
* Modify type of column and adapt the data.

src/helpers/VaultManagement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export async function updateRowFile(file: TFile, columnId: string, newValue: str
129129
// assign an empty value to the new key
130130
rowFields.frontmatter[newValue] = rowFields.frontmatter[columnId] ?? "";
131131
delete rowFields.frontmatter[columnId];
132-
await persistFrontmatter();
132+
await persistFrontmatter(columnId);
133133
}
134134

135135
// Remove a column

src/services/DatabaseInfo.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import {
66
import { LOGGER } from 'services/Logger';
77
import { VaultManagerDB } from 'services/FileManagerService';
88
import DatabaseYamlToStringParser from 'parsers/DatabaseYamlToStringParser';
9-
import { NoteContentAction, RowDataType, TableDataType } from 'cdm/FolderModel';
9+
import { NoteContentAction } from 'cdm/FolderModel';
1010
import { LocalSettings } from 'Settings';
11-
import { isDatabaseNote, updateRowFile } from 'helpers/VaultManagement';
12-
import { UpdateRowOptions } from 'helpers/Constants';
11+
import { isDatabaseNote } from 'helpers/VaultManagement';
1312
import DatabaseStringToYamlParser from 'parsers/DatabaseStringToYamlParser';
1413

1514
export default class DatabaseInfo {
@@ -67,6 +66,25 @@ export default class DatabaseInfo {
6766
LOGGER.debug(`<=setDatabaseconfigYaml`, `set file ${databaseFilePath} with ${databaseConfigUpdated}`);
6867
}
6968

69+
/**
70+
* modify column key
71+
* @param oldColumnId
72+
* @param newColumnId
73+
*/
74+
async updateColumnKey(oldColumnId: string, newColumnId: string, newLabel: string): Promise<void> {
75+
// clone current column configuration
76+
const currentCol = this.yaml.columns[oldColumnId];
77+
// update column id
78+
currentCol.label = newColumnId;
79+
currentCol.accessor = newColumnId;
80+
currentCol.key = newColumnId;
81+
currentCol.id = newColumnId;
82+
delete this.yaml.columns[oldColumnId];
83+
this.yaml.columns[newColumnId] = currentCol;
84+
// save on disk
85+
await this.saveOnDisk();
86+
}
87+
7088
/**
7189
* Modify or add properties to a column
7290
* @param columnId
@@ -81,6 +99,7 @@ export default class DatabaseInfo {
8199
await this.saveOnDisk();
82100
}
83101

102+
84103
/**
85104
* Given an array of column ids, reorder yaml columns to match the order of the array
86105
* @param columnIds

0 commit comments

Comments
 (0)