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

Commit 6f094fa

Browse files
committed
manage refresh on startup
1 parent a4323cf commit 6f094fa

File tree

7 files changed

+70
-80
lines changed

7 files changed

+70
-80
lines changed

src/automations/core/modules/NumbersFn.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ export class NumbersFn extends DbModule {
1414
async create_dynamic_functions(): Promise<void> { }
1515

1616
private parseRaw(rawValues: Literal[]): number[] {
17-
return rawValues.map((value) => {
18-
return parseFloat(value.toString());
19-
}).filter((value) => {
20-
return !isNaN(value);
21-
});
17+
return rawValues
18+
.filter((value) => value &&
19+
typeof value === "string" ||
20+
typeof value === "number")
21+
.map((value) => {
22+
return parseFloat(value.toString());
23+
}).filter((value) => {
24+
return !isNaN(value);
25+
});
2226
}
2327

2428
/**

src/cdm/TableStateInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface DataState {
4747
rows: RowDataType[];
4848
actions: {
4949
addRow: (filename: string, columns: TableColumn[], ddbbConfig: LocalSettings) => Promise<void>;
50-
updateCell: (rowIndex: number, column: TableColumn, value: Literal, columns: TableColumn[], ddbbConfig: LocalSettings, isMovingFile?: boolean) => Promise<void>;
50+
updateCell: (rowIndex: number, column: TableColumn, value: Literal, columns: TableColumn[], ddbbConfig: LocalSettings, isMovingFile?: boolean, saveOnDisk?: boolean) => Promise<void>;
5151
parseDataOfColumn: (column: TableColumn, input: string, ddbbConfig: LocalSettings) => void;
5252
updateDataAfterLabelChange: (column: TableColumn, label: string, columns: TableColumn[], ddbbConfig: LocalSettings) => Promise<void>;
5353
removeRow: (row: RowDataType) => Promise<void>;

src/components/cellTypes/FormulaCell.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CellComponentProps } from "cdm/ComponentsModel";
22
import { TableColumn } from "cdm/FolderModel";
3+
import { MetadataColumns } from "helpers/Constants";
34
import { c, getAlignmentClassname } from "helpers/StylesHelper";
45
import React, { useEffect, useRef } from "react";
56
import { MarkdownService } from "services/MarkdownRenderService";
@@ -18,10 +19,9 @@ const FormulaCell = (mdProps: CellComponentProps) => {
1819
const formulaInfo = tableState.automations((state) => state.info);
1920

2021
useEffect(() => {
21-
setTimeout(async () => {
22+
Promise.resolve().then(async () => {
2223
// If formula cell is empty, do nothing
2324
if (formulaRef.current === null) return;
24-
2525
const formulaResponse = formulaInfo
2626
.runFormula(
2727
tableColumn.config.formula_query,
@@ -39,14 +39,8 @@ const FormulaCell = (mdProps: CellComponentProps) => {
3939
formulaRef.current,
4040
5
4141
);
42-
4342
// If formula cell is not configured to persist, exit
44-
if (
45-
!tableColumn.config.persist_formula ||
46-
cell.getValue() === formulaResponse
47-
)
48-
return;
49-
43+
if (cell.getValue() === formulaResponse) return;
5044
// Save formula response on disk
5145
const newCell = ParseService.parseRowToLiteral(
5246
formulaRow,
@@ -59,10 +53,17 @@ const FormulaCell = (mdProps: CellComponentProps) => {
5953
tableColumn,
6054
newCell,
6155
columnsInfo.getAllColumns(),
62-
configInfo.getLocalSettings()
56+
configInfo.getLocalSettings(),
57+
false,
58+
tableColumn.config.persist_formula
6359
);
64-
}, 0);
65-
}, [row]);
60+
});
61+
}, [
62+
Object.entries(formulaRow)
63+
.filter(([key]) => key !== MetadataColumns.MODIFIED && key !== column.id)
64+
.map(([, value]) => (value ? value.toString() : ""))
65+
.join(""),
66+
]);
6667

6768
return (
6869
<span

src/components/cellTypes/RollupCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ const RollupCell = (mdProps: CellComponentProps) => {
2727
configInfo.getLocalSettings()
2828
) as string
2929
);
30+
const relation = formulaRow[tableColumn.config.asociated_relation_id];
3031

3132
useEffect(() => {
3233
if (formulaRef.current !== null) {
3334
formulaRef.current.innerHTML = "";
34-
const relation = formulaRow[tableColumn.config.asociated_relation_id];
3535
if (!relation) {
3636
return;
3737
}

src/main.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ export default class DBFolderPlugin extends Plugin {
5959

6060
databaseFileModes: Record<string, string> = {};
6161

62-
viewMap: Map<string, DatabaseView> = new Map();
63-
6462
_loaded = false;
6563

6664
stateManagers: Map<TFile, StateManager> = new Map();
@@ -189,8 +187,8 @@ export default class DBFolderPlugin extends Plugin {
189187
return;
190188
}
191189

192-
if (!this.viewMap.has(view.id)) {
193-
this.viewMap.set(view.id, view);
190+
if (!reg.viewMap.has(view.id)) {
191+
reg.viewMap.set(view.id, view);
194192
}
195193

196194
const file = view.file;
@@ -408,27 +406,30 @@ export default class DBFolderPlugin extends Plugin {
408406
*/
409407
this.registerEvent(
410408
app.metadataCache.on("dataview:index-ready", async () => {
411-
// Refresh all database views
412-
this.viewMap.forEach(async (view) => {
413-
await view.reloadDatabase();
414-
});
409+
for (const [win, { viewMap }] of Array.from(this.windowRegistry.entries())) {
410+
// Refresh all database views
411+
for (const view of viewMap.values()) {
412+
await view.reloadDatabase();
413+
}
414+
}
415415
/**
416416
* Once the index is ready, we can start listening for metadata changes.
417417
*/
418418
if (this.settings.global_settings.enable_auto_update) {
419419
this.registerEvent(app.metadataCache.on("dataview:metadata-change",
420420
(type, file, oldPath?) => {
421421
const activeView = app.workspace.getActiveViewOfType(DatabaseView);
422-
// Iterate through all the views and reload the database if the file is the same
423-
this.viewMap.forEach(async (view) => {
424-
const isActive = activeView && (view.file.path === activeView.file.path);
425-
view.handleExternalMetadataChange(type, file, isActive, oldPath);
422+
Array.from(this.windowRegistry.entries()).forEach(async ([, { viewMap }]) => {
423+
// Iterate through all the views and reload the database if the file is the same
424+
viewMap.forEach(async (view) => {
425+
const isActive = activeView && (view.file.path === activeView?.file.path);
426+
view.handleExternalMetadataChange(type, file, isActive, oldPath);
427+
});
426428
});
427429
})
428430
);
429431
}
430-
})
431-
);
432+
}));
432433

433434
/**
434435
* Check when the active view focus changes and update bar status

src/services/Logger.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ class Log implements LogInterface {
4141

4242
private configureLogger() {
4343
if (this.levelInfo >= LevelInfoRecord.debug && this.isDebugModeEnabled) {
44-
this.debug = console.log.bind(window.console, `[debug] ${new Date().toISOString()}`);
44+
this.debug = console.log.bind(window.console, `[DEBUG]`);
4545
} else {
4646
this.debug = () => { };
4747
}
4848

4949
if (this.levelInfo >= LevelInfoRecord.info && this.isDebugModeEnabled) {
50-
this.info = console.log.bind(window.console, `[info] ${new Date().toISOString()}`);
50+
this.info = console.log.bind(window.console, `[INFO]`);
5151
} else {
5252
this.info = () => { };
5353
}
5454

5555
if (this.levelInfo >= LevelInfoRecord.warn && this.isDebugModeEnabled) {
56-
this.warn = console.log.bind(window.console, `[warn] ${new Date().toISOString()}`);
56+
this.warn = console.log.bind(window.console, `[WARN]`);
5757
} else {
5858
this.warn = () => { };
5959
}
6060

6161
if (this.levelInfo >= LevelInfoRecord.error && this.isDebugModeEnabled) {
62-
this.error = console.log.bind(window.console, `[error] ${new Date().toISOString()}`);
62+
this.error = console.log.bind(window.console, `[ERROR]`);
6363
} else {
6464
this.error = () => { };
6565
}
@@ -69,22 +69,8 @@ class Log implements LogInterface {
6969
if (!Log.instance) {
7070
Log.instance = new Log();
7171
}
72-
7372
return Log.instance;
7473
}
75-
76-
private emitLogMessage(level: "debug" | "info" | "warn" | "error", message: string, ...supportingData: unknown[]): void {
77-
// Do not log if debug mode is disabled
78-
if (!this.isDebugModeEnabled) {
79-
return;
80-
}
81-
const moment: string = new Date().toISOString();
82-
if (supportingData.length > 0) {
83-
console.log(`[${moment}] [${level}] ${message}`, supportingData);
84-
} else {
85-
console.log(`[${moment}] [${level}] ${message}`);
86-
}
87-
}
8874
}
8975

9076
export const LOGGER = Log.getInstance();

src/stateManagement/data/handlers/UpdateCellHandlerAction.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,48 @@ export default class UpdateCellHandlerAction extends AbstractTableAction<DataSta
1818
value: Literal,
1919
columns: TableColumn[],
2020
ddbbConfig: LocalSettings,
21-
isMovingFile?: boolean) => {
21+
isMovingFile?: boolean,
22+
saveOnDisk = false) => {
2223
const modifiedRow = get().rows[rowIndex];
2324
let rowTFile = modifiedRow.__note__.getFile();
2425

2526
// Update the row on memory
2627
modifiedRow[column.key] = value;
2728

28-
// Row Rules
29-
if (ddbbConfig.show_metadata_modified) {
30-
modifiedRow[MetadataColumns.MODIFIED] = DateTime.now();
31-
}
29+
if (saveOnDisk) {
30+
const pathColumns: string[] =
31+
ddbbConfig.group_folder_column
32+
.split(",")
33+
.filter(Boolean);
34+
// Update the row on disk
35+
if (isMovingFile && pathColumns.includes(column.key)) {
36+
const folderPath = destination_folder(view, ddbbConfig);
37+
const newFilePath = resolveNewFilePath({
38+
pathColumns,
39+
row: modifiedRow,
40+
ddbbConfig,
41+
folderPath,
42+
});
43+
await FileGroupingService.moveFile(newFilePath, modifiedRow);
44+
await FileGroupingService.removeEmptyFolders(folderPath, ddbbConfig);
45+
}
3246

33-
const pathColumns: string[] =
34-
ddbbConfig.group_folder_column
35-
.split(",")
36-
.filter(Boolean);
37-
// Update the row on disk
38-
if (isMovingFile && pathColumns.includes(column.key)) {
39-
const folderPath = destination_folder(view, ddbbConfig);
40-
const newFilePath = resolveNewFilePath({
41-
pathColumns,
42-
row: modifiedRow,
47+
await EditEngineService.updateRowFileProxy(
48+
rowTFile,
49+
column.key,
50+
value,
51+
columns,
4352
ddbbConfig,
44-
folderPath,
45-
});
46-
await FileGroupingService.moveFile(newFilePath, modifiedRow);
47-
await FileGroupingService.removeEmptyFolders(folderPath, ddbbConfig);
53+
UpdateRowOptions.COLUMN_VALUE
54+
);
4855
}
4956

50-
await EditEngineService.updateRowFileProxy(
51-
rowTFile,
52-
column.key,
53-
value,
54-
columns,
55-
ddbbConfig,
56-
UpdateRowOptions.COLUMN_VALUE
57-
);
58-
5957
set((state) => {
6058
// Save on memory
6159
return {
6260
rows: [
6361
...state.rows.slice(0, rowIndex),
64-
modifiedRow,
62+
{ ...state.rows[rowIndex], [column.key]: value, [MetadataColumns.MODIFIED]: DateTime.now() },
6563
...state.rows.slice(rowIndex + 1),
6664
]
6765
};

0 commit comments

Comments
 (0)