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

Commit 7b8d04e

Browse files
committed
adding state config global and local
needs to work at local yet
1 parent 885590f commit 7b8d04e

File tree

15 files changed

+257
-133
lines changed

15 files changed

+257
-133
lines changed

dist/main.js

Lines changed: 163 additions & 100 deletions
Large diffs are not rendered by default.

src/DatabaseView.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export class DatabaseView extends TextFileView implements HoverParent {
2626
plugin: DBFolderPlugin;
2727
hoverPopover: HoverPopover | null;
2828
tableContainer: HTMLDivElement | null = null;
29+
diskConfig: DatabaseInfo;
30+
2931
constructor(leaf: WorkspaceLeaf, plugin: DBFolderPlugin) {
3032
super(leaf);
3133
this.plugin = plugin;
@@ -107,9 +109,9 @@ export class DatabaseView extends TextFileView implements HoverParent {
107109

108110
async initDatabase(): Promise<void> {
109111
LOGGER.info(`=>initDatabase ${this.file.path}`);
110-
const databaseInfo = new DatabaseInfo(this.file);
111-
await databaseInfo.initDatabaseconfigYaml();
112-
const columns = await obtainColumnsFromFolder(databaseInfo.yaml.columns);
112+
this.diskConfig = new DatabaseInfo(this.file);
113+
await this.diskConfig.initDatabaseconfigYaml();
114+
const columns = await obtainColumnsFromFolder(this.diskConfig.yaml.columns);
113115
const metatadaColumns = await obtainMetadataColumns();
114116
columns.push(...metatadaColumns);
115117
const rows = await adapterTFilesToRows(this.file.parent.path);
@@ -119,8 +121,7 @@ export class DatabaseView extends TextFileView implements HoverParent {
119121
data: rows,
120122
skipReset: false,
121123
view: this,
122-
stateManager: this.plugin.getStateManager(this.file),
123-
diskConfig: databaseInfo
124+
stateManager: this.plugin.getStateManager(this.file)
124125
}
125126

126127
let table = createDatabase(tableProps);

src/Settings.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,27 @@ export interface SettingsManagerConfig {
6161
this.config = config;
6262
this.settings = settings;
6363
}
64-
constructUI(containerEl: HTMLElement, heading: string, local: boolean) {
64+
65+
/**
66+
* Render settings window
67+
* @param containerEl
68+
* @param heading
69+
* @param local
70+
* @param view optional. Used only for local settings
71+
*/
72+
constructUI(containerEl: HTMLElement, heading: string, local: boolean,view?: DatabaseView) {
6573
/** Common modal headings */
6674
containerEl.empty();
6775
containerEl.addClass('database-settings-modal');
6876
add_setting_header(containerEl,heading,'h2');
6977
const settingsBody:HTMLDivElement = containerEl.createDiv('database-settings-body');
70-
this.constructSettingBody(settingsBody, local);
78+
this.constructSettingBody(settingsBody, local, view);
7179
}
7280

73-
constructSettingBody(containerEl: HTMLElement, local: boolean) {
81+
constructSettingBody(containerEl: HTMLElement, local: boolean, view?: DatabaseView) {
7482
containerEl.empty();
7583
/** Developer section */
76-
developer_settings_section(this, containerEl, local);
84+
developer_settings_section(this, containerEl, local, view);
7785
}
7886
cleanUp() {
7987
this.cleanupFns.forEach((fn) => fn());

src/cdm/DatabaseModel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ export type DatabaseYaml = {
2020
description: string,
2121
/** database columns */
2222
columns: Record<string, DatabaseColumn>
23+
/** database local configuration
24+
* TODO typing*/
25+
config?: Record<string, any>
2326
}

src/cdm/FolderModel.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ export type TableDataType={
5959
skipReset: boolean,
6060
view: DatabaseView,
6161
stateManager?: StateManager,
62-
dispatch?: Dispatch<any>,
63-
diskConfig: DatabaseInfo
62+
dispatch?: Dispatch<any>
6463
}
6564
export interface DatabaseHeaderProps{
6665
columns:any,

src/components/Table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export function Table(initialState: TableDataType){
241241
}}
242242
onDragEnd={() => {
243243
// save on disk
244-
initialState.diskConfig.reorderColumns((state as any).columnOrder);
244+
initialState.view.diskConfig.reorderColumns((state as any).columnOrder);
245245
// clear the current order
246246
currentColOrder.current = null;
247247
}}

src/components/reducers/DatabaseDispatch.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function databaseReducer(state:TableDataType, action:ActionType) {
7676
// trim label will get a valid yaml key
7777
const update_col_key:string = action.label.trim();
7878
// Update configuration on disk
79-
state.diskConfig.updateColumnProperties(
79+
state.view.diskConfig.updateColumnProperties(
8080
action.columnId,
8181
{label: action.label, accessor: update_col_key, key: update_col_key}
8282
);
@@ -108,7 +108,7 @@ export function databaseReducer(state:TableDataType, action:ActionType) {
108108
column => column.id === action.columnId
109109
);
110110
// Update configuration on disk
111-
state.diskConfig.updateColumnProperties(action.columnId, {input: action.dataType});
111+
state.view.diskConfig.updateColumnProperties(action.columnId, {input: action.dataType});
112112
// Update state
113113
switch (action.dataType) {
114114
case DataTypes.NUMBER:
@@ -217,7 +217,7 @@ export function databaseReducer(state:TableDataType, action:ActionType) {
217217
position: leftId
218218
};
219219
// Update configuration on disk
220-
state.diskConfig.addColumn(`newColumn${leftId}`, newLeftColumn);
220+
state.view.diskConfig.addColumn(`newColumn${leftId}`, newLeftColumn);
221221

222222
Promise.all(state.data.map(async (row:TableRow) => {
223223
updateRowFile(
@@ -262,7 +262,7 @@ export function databaseReducer(state:TableDataType, action:ActionType) {
262262
label: `new Column ${rightId}`
263263
};
264264
// Update configuration on disk
265-
state.diskConfig.addColumn(rightId, newRIghtColumn);
265+
state.view.diskConfig.addColumn(rightId, newRIghtColumn);
266266

267267
Promise.all(state.data.map(async (row:TableRow) => {
268268
updateRowFile(
@@ -294,7 +294,7 @@ export function databaseReducer(state:TableDataType, action:ActionType) {
294294
(column) => column.id === action.columnId
295295
);
296296
// Update configuration on disk
297-
state.diskConfig.removeColumn(action.columnId);
297+
state.view.diskConfig.removeColumn(action.columnId);
298298
Promise.all(state.data.map(async (row:TableRow) => {
299299
updateRowFile(
300300
row.note.getFile(),

src/helpers/Constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const DatabaseFrontmatterOptions = Object.freeze({
5050
' key: column1',
5151
' accessor: column1',
5252
' label: Column 1',
53-
'%%>'
53+
' position: 0',
5454
].join('\n')
5555
});
5656

src/main.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ export default class DBFolderPlugin extends Plugin {
187187
this.app.fileManager as any
188188
).createNewMarkdownFile(targetFolder, 'Untitled database');
189189

190-
await this.app.vault.modify(database, DatabaseFrontmatterOptions.BASIC);
190+
await this.app.vault.modify(
191+
database,
192+
DatabaseFrontmatterOptions.BASIC
193+
.concat('\n')
194+
.concat(this.defaultConfiguration())
195+
);
191196
await this.app.workspace.activeLeaf.setViewState({
192197
type: DatabaseCore.FRONTMATTER_KEY,
193198
state: { file: database.path },
@@ -197,6 +202,17 @@ export default class DBFolderPlugin extends Plugin {
197202
}
198203
}
199204

205+
/**
206+
* Returns the default configuration for a database file.
207+
*/
208+
defaultConfiguration():string{
209+
const local_settings = this.settings.local_settings;
210+
return [
211+
`configuration:`,
212+
` enable_show_state: ${local_settings.enable_show_state}`,
213+
'%%>'
214+
].join('\n');
215+
}
200216
registerEvents() {
201217
this.registerEvent(
202218
this.app.workspace.on('file-menu', (menu, file: TFile) => {

src/mock/mockUtils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ export function makeData(count:number):TableDataType {
5858
options: options,
5959
}
6060
];
61-
return { columns: columns, metadataColumns:[], data: data, skipReset: false, diskConfig:null, view:null };
61+
return { columns: columns, metadataColumns:[], data: data, skipReset: false, view:null };
6262
}
6363

0 commit comments

Comments
 (0)