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

Commit 4c7cb76

Browse files
committed
Merge branch 'improved_rollup_and_footer'
2 parents 625e9fb + 72a95e0 commit 4c7cb76

File tree

20 files changed

+160
-149
lines changed

20 files changed

+160
-149
lines changed

src/DatabaseView.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
Menu,
3838
} from "obsidian";
3939
import { createRoot, Root } from "react-dom/client";
40-
import { DbAutomationService } from "services/AutomationService";
40+
import { Db } from "services/CoreService";
4141
import DatabaseInfo from "services/DatabaseInfo";
4242
import { LOGGER } from "services/Logger";
4343
import { SettingsModal } from "Settings";
@@ -172,9 +172,7 @@ export class DatabaseView extends TextFileView implements HoverParent {
172172
);
173173
this.initial = obtainInitialType(this.columns);
174174

175-
this.formulas = await DbAutomationService.buildFns(
176-
this.diskConfig.yaml.config
177-
);
175+
this.formulas = await Db.buildFns(this.diskConfig.yaml.config);
178176
// Define table properties
179177
this.shadowColumns = this.columns.filter((col) => col.skipPersist);
180178
const tableProps: TableDataType = {

src/automations/Footer.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { DEFAULT_SETTINGS, FooterType } from "helpers/Constants";
22
import { Literal } from "obsidian-dataview";
33
import { DataviewService } from "services/DataviewService";
4-
import { DateTime } from "luxon";
5-
import { DbAutomationService } from "services/AutomationService";
4+
import { Db } from "services/CoreService";
65

76
export default class Footer {
87
constructor(public readonly colValues: Literal[]) { }
@@ -120,7 +119,7 @@ export default class Footer {
120119
* @returns
121120
*/
122121
public sum(): string {
123-
const total = DbAutomationService.coreFns.numbers.sum(this.colValues);
122+
const total = Db.coreFns.numbers.sum(this.colValues);
124123
return `Total: ${total}`;
125124
}
126125

@@ -129,7 +128,7 @@ export default class Footer {
129128
* @returns
130129
*/
131130
public min(): string {
132-
const min = DbAutomationService.coreFns.numbers.min(this.colValues);
131+
const min = Db.coreFns.numbers.min(this.colValues);
133132
return `Min: ${min}`;
134133
}
135134

@@ -138,7 +137,7 @@ export default class Footer {
138137
* @returns
139138
*/
140139
public max(): string {
141-
const max = DbAutomationService.coreFns.numbers.max(this.colValues);
140+
const max = Db.coreFns.numbers.max(this.colValues);
142141
return `Max: ${max}`;
143142
}
144143

@@ -150,7 +149,7 @@ export default class Footer {
150149
* @returns
151150
*/
152151
public earliestDate(): string {
153-
const earliest = DbAutomationService.coreFns.luxon.earliest(this.colValues);
152+
const earliest = Db.coreFns.luxon.earliest(this.colValues);
154153
return earliest.isValid ?
155154
`Earliest: ${earliest.toFormat(DEFAULT_SETTINGS.local_settings.datetime_format)}` :
156155
null;
@@ -161,7 +160,7 @@ export default class Footer {
161160
* @returns
162161
*/
163162
public latestDate(): string {
164-
const latest = DbAutomationService.coreFns.luxon.latest(this.colValues);
163+
const latest = Db.coreFns.luxon.latest(this.colValues);
165164
return latest.isValid ?
166165
`Latest: ${latest.toFormat(DEFAULT_SETTINGS.local_settings.datetime_format)}` :
167166
null;
@@ -172,7 +171,7 @@ export default class Footer {
172171
* @returns
173172
*/
174173
public rangeDate(): string {
175-
const range = DbAutomationService.coreFns.luxon.range(this.colValues);
174+
const range = Db.coreFns.luxon.range(this.colValues);
176175
return `Range: ${range} days`
177176
}
178177

src/automations/Rollup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LocalSettings } from "cdm/SettingsModel";
22
import { DEFAULT_SETTINGS, InputType, ROLLUP_ACTIONS } from "helpers/Constants";
33
import { Link, Literal, SMarkdownPage } from "obsidian-dataview";
4-
import { DbAutomationService } from "services/AutomationService";
4+
import { Db } from "services/CoreService";
55
import { DataviewService } from "services/DataviewService";
66
import { LOGGER } from "services/Logger";
77
import { ParseService } from "services/ParseService";
@@ -97,7 +97,7 @@ class Rollup {
9797
return NaN;
9898
}
9999
const rawValues = this.rawValues(key);
100-
return DbAutomationService.coreFns.numbers.sum(rawValues)
100+
return Db.coreFns.numbers.sum(rawValues)
101101
}
102102

103103
/**

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/Columns.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ export async function obtainColumnsFromFile(
149149
}
150150

151151
export async function obtainColumnsFromRows(
152-
view: DatabaseView,
152+
folderPath: string,
153153
ddbbConfig: LocalSettings,
154154
filters: FilterSettings,
155155
tableColumns: TableColumn[]
156156
): Promise<string[]> {
157157
const columns: string[] = [];
158158
const rows = await obtainAllPossibleRows(
159-
view.file.parent.path,
159+
folderPath,
160160
ddbbConfig,
161161
filters,
162162
tableColumns

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: 2 additions & 2 deletions
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
}
@@ -67,7 +67,7 @@ const RollupCell = (mdProps: CellComponentProps) => {
6767
);
6868
}
6969
}
70-
}, [cell, row, column]);
70+
}, [relation]);
7171
return (
7272
<span
7373
ref={formulaRef}

src/components/modals/columnSettings/handlers/automations/FormulaInputHandler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ export class FormulaInputHandler extends AbstractHandlerClass<ColumnSettingsHand
4343
textArea.setPlaceholder(t("column_settings_modal_formula_input_textarea_placeholder"));
4444
textArea.onChange(formula_promise);
4545
textArea.inputEl.addClass(c("textarea-setting"));
46+
textArea.inputEl.onkeydown = (e: KeyboardEvent) => {
47+
switch (e.key) {
48+
case "Enter":
49+
e.preventDefault();
50+
break;
51+
}
52+
};
4653

4754
});
4855
const mainDesc = containerEl.createEl('p');

src/components/modals/columnSettings/handlers/rollups/RollupKeyHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class RollupKeyHandler extends AbstractHandlerClass<ColumnSettingsHandler
2626
});
2727
columnSettingsManager.modal.enableReset = true;
2828
};
29+
2930
recordFieldsFromRelation(
3031
relationColumn.config.related_note_path,
3132
configState.info.getLocalSettings(),

0 commit comments

Comments
 (0)