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

Commit d311462

Browse files
committed
Merge branch '28-fr-option-to-delete-a-column-without-delete-the-field-into-all-the-rows'
2 parents f8cf1d2 + 6bca508 commit d311462

File tree

12 files changed

+66
-58
lines changed

12 files changed

+66
-58
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Database folder plugin
22
This plugin is a Notion like database based on folders.
3+
**[Roadmap](https://github.com/RafaelGB/obsidian-db-folder/projects/1)**
34
### How can I add a database?
45
This plugin is based on folders. You can add a folder database y by right clicking on the folder where you want to store your table
56

@@ -15,7 +16,6 @@ The information you add or edit will be saved into the target obsidian note.
1516
## Index
1617
- [Whats inside database view](docs/docs/Whats%20inside%20database%20view.md)
1718
- [Obsidian dbfolder Features](docs/docs/Obsidian%20dbfolder%20Features.md)
18-
- [Roadmap](https://github.com/RafaelGB/obsidian-db-folder/projects/1)
1919
- [changelog](docs/changelog.md)
2020

2121
## Sources

src/Settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface GlobalSettings {
1717
export interface LocalSettings {
1818
enable_show_state: boolean;
1919
group_folder_column: string;
20+
remove_field_when_delete_column: boolean;
2021
}
2122
export interface DatabaseSettings {
2223
global_settings: GlobalSettings;
@@ -30,6 +31,7 @@ export const DEFAULT_SETTINGS: DatabaseSettings = {
3031
},
3132
local_settings: {
3233
enable_show_state: false,
34+
remove_field_when_delete_column: false,
3335
group_folder_column: ''
3436
}
3537
};

src/__mocks__/StateManager.ts

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

src/cdm/DatabaseModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface DatabaseYaml {
2626
/** database local configuration */
2727
config: LocalSettings;
2828
/** dataview filters */
29-
filters?: FilterCondition[];
29+
filters: FilterCondition[];
3030
}
3131

3232
export type RowDatabaseFields = {

src/components/Header.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function Header(headerProps: DatabaseHeaderProps) {
4949
/** Properties of header */
5050
const { setSortBy, rows, initialState } = headerProps;
5151
/** Column values */
52-
const { id, dataType, options } = headerProps.column;
52+
const { id, dataType, options, position } = headerProps.column;
5353
/** reducer asociated to database */
5454
// TODO typying improve
5555
const dataDispatch = (headerProps as any).dataDispatch;
@@ -83,7 +83,7 @@ export default function Header(headerProps: DatabaseHeaderProps) {
8383
break;
8484
}
8585

86-
function adjustWidthOfTheColumn() {
86+
function adjustWidthOfTheColumn(position: number) {
8787
const columnNumber =
8888
initialState.columns.length + 1 - initialState.shadowColumns.length;
8989
const columnName = `newColumn${columnNumber}`;
@@ -93,15 +93,15 @@ export default function Header(headerProps: DatabaseHeaderProps) {
9393
(columnLabel.length + WidthVariables.ICON_SPACING) *
9494
WidthVariables.MAGIC_SPACING;
9595
setColumnWidthState(columnWidthState);
96-
return { name: columnName, position: columnNumber, label: columnLabel };
96+
return { name: columnName, position: position, label: columnLabel };
9797
}
9898

9999
function handlerAddColumnToLeft(e: any) {
100100
dataDispatch({
101101
type: ActionTypes.ADD_COLUMN_TO_LEFT,
102102
columnId: MetadataColumns.ADD_COLUMN,
103103
focus: true,
104-
columnInfo: adjustWidthOfTheColumn(),
104+
columnInfo: adjustWidthOfTheColumn(position - 1),
105105
});
106106
}
107107

src/components/Table.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ export function Table(initialState: TableDataType) {
173173
setGlobalFilter,
174174
allColumns,
175175
setColumnOrder,
176-
totalColumnsWidth,
177176
} = useTable(
178177
// Table properties
179178
propsUseTable,
@@ -191,6 +190,7 @@ export function Table(initialState: TableDataType) {
191190
const [columnsWidthState, setColumnsWidthState] = React.useState(
192191
getColumnsWidthStyle(rows, columns)
193192
);
193+
const totalWidth = getTotalWidth(columnsWidthState);
194194
// Manage DnD
195195
const currentColOrder = React.useRef(null);
196196
// Manage input of new row
@@ -230,7 +230,7 @@ export function Table(initialState: TableDataType) {
230230
{...getTableProps({
231231
style: {
232232
...getTableProps().style,
233-
minWidth: totalColumnsWidth,
233+
width: totalWidth,
234234
},
235235
})}
236236
className={`${c("table noselect")}`}
@@ -296,7 +296,7 @@ export function Table(initialState: TableDataType) {
296296
style: {
297297
...getDndListStyle(snapshot.isDraggingOver),
298298
width:
299-
getTotalWidth(columnsWidthState) -
299+
totalWidth -
300300
columnsWidthState.widthRecord[
301301
MetadataColumns.ADD_COLUMN
302302
],
@@ -365,7 +365,7 @@ export function Table(initialState: TableDataType) {
365365
<div
366366
{...row.getRowProps({
367367
style: {
368-
minWidth: `${totalColumnsWidth}px`,
368+
width: `${totalWidth}px`,
369369
},
370370
})}
371371
className={`${c("tr")}`}

src/components/reducers/DatabaseDispatch.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,19 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
323323
);
324324
// Update configuration on disk
325325
state.view.diskConfig.removeColumn(action.columnId);
326-
Promise.all(
327-
state.data.map(async (row: RowDataType) => {
328-
updateRowFile(
329-
row.note.getFile(),
330-
action.key,
331-
undefined, // delete does not need this field
332-
state,
333-
UpdateRowOptions.REMOVE_COLUMN
334-
);
335-
})
336-
);
326+
if (state.view.diskConfig.yaml.config.remove_field_when_delete_column) {
327+
Promise.all(
328+
state.data.map(async (row: RowDataType) => {
329+
updateRowFile(
330+
row.note.getFile(),
331+
action.key,
332+
undefined, // delete does not need this field
333+
state,
334+
UpdateRowOptions.REMOVE_COLUMN
335+
);
336+
})
337+
);
338+
}
337339
// Update state
338340
return update(state, {
339341
skipReset: { $set: true },

src/parsers/DatabaseYamlToStringParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const DatabaseYamlToStringParser = (databaseConfig: DatabaseYaml): string[] => {
2424
databaseConfigString.push(`config:`);
2525
databaseConfigString.push(`${yamlIndent.repeat(1)}enable_show_state: ${databaseConfig.config.enable_show_state}`);
2626
databaseConfigString.push(`${yamlIndent.repeat(1)}group_folder_column: ${databaseConfig.config.group_folder_column}`);
27+
databaseConfigString.push(`${yamlIndent.repeat(1)}remove_field_when_delete_column: ${databaseConfig.config.remove_field_when_delete_column}`);
2728

2829
// Database filters
2930
if (databaseConfig.filters) {

src/parsers/handlers/ConfigHandler.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export class ConfigHandler extends AbstractYamlHandler {
1818
this.addError(`There was not group_folder_column key in yaml. Default will be loaded`);
1919
this.localYaml.config.group_folder_column = '';
2020
}
21+
// if remove_field_when_delete_column is not defined, load default
22+
if (handlerResponse.yaml.config.remove_field_when_delete_column === undefined) {
23+
this.addError(`There was not remove_field_when_delete_column key in yaml. Default will be loaded`);
24+
this.localYaml.config.remove_field_when_delete_column = false;
25+
}
26+
2127
}
2228
return this.goNext(handlerResponse);
2329
}

0 commit comments

Comments
 (0)