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

Commit 719f497

Browse files
committed
persisted formulas if you wish
1 parent 335f016 commit 719f497

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

src/cdm/FolderModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface ConfigColumn {
4141
isInline: boolean;
4242
task_hide_completed?: boolean;
4343
formula_query?: string;
44+
persist_formula?: boolean;
4445
[key: string]: Literal;
4546
}
4647

src/components/cellTypes/FormulaCell.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const FormulaCell = (mdProps: CellComponentProps) => {
1111
const tableColumn = column.columnDef as TableColumn;
1212
const formulaRef = useRef<HTMLDivElement>();
1313
const formulaRow = tableState.data((state) => state.rows[row.index]);
14+
const dataActions = tableState.data((state) => state.actions);
1415
const configInfo = tableState.configState((state) => state.info);
16+
const columnsInfo = tableState.columns((state) => state.info);
1517
const formulaInfo = tableState.automations((state) => state.info);
1618

1719
useEffect(() => {
@@ -25,6 +27,20 @@ const FormulaCell = (mdProps: CellComponentProps) => {
2527
)
2628
.toString();
2729
renderMarkdown(defaultCell, formulaResponse, formulaRef.current, 5);
30+
31+
// Save formula response on disk
32+
if (
33+
tableColumn.config.persist_formula &&
34+
formulaRow[column.id] !== formulaResponse
35+
) {
36+
dataActions.updateCell(
37+
row.index,
38+
tableColumn,
39+
formulaResponse,
40+
columnsInfo.getAllColumns(),
41+
configInfo.getLocalSettings()
42+
);
43+
}
2844
}
2945
}, [row]);
3046
return (

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
22
import { AbstractHandlerClass } from "patterns/AbstractHandler";
33
import { Setting } from "obsidian";
4+
import { add_toggle } from "settings/SettingsComponents";
45
export class FormulaInputHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
5-
settingTitle: string = 'Enable link alias';
6+
settingTitle: string = 'Formula properties';
67
handle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
78
const { column, containerEl, columnSettingsManager } = columnHandlerResponse;
89
const { view } = columnSettingsManager.modal;
@@ -16,6 +17,22 @@ export class FormulaInputHandler extends AbstractHandlerClass<ColumnSettingsHand
1617
columnSettingsManager.modal.enableReset = true;
1718
}
1819

20+
const persist_Formula_toggle_promise = async (value: boolean): Promise<void> => {
21+
column.config.link_alias_enabled = value;
22+
// Persist value
23+
await view.diskConfig.updateColumnConfig(column.key, {
24+
persist_formula: value
25+
});
26+
columnSettingsManager.modal.enableReset = true;
27+
}
28+
add_toggle(
29+
containerEl,
30+
"Persist formula output",
31+
"Enable/disable to persist formula output on your notes (Only persisted formulas could be searchable and sortable)",
32+
column.config.persist_formula,
33+
persist_Formula_toggle_promise
34+
);
35+
1936
new Setting(containerEl)
2037
.setName('Formula input')
2138
.setDesc('Enter your formula here using your js function names')

src/stateManagement/automations/handlers/RunFormulaHandlerAction.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { RowDataType } from "cdm/FolderModel";
22
import { LocalSettings } from "cdm/SettingsModel";
33
import { AutomationState, TableActionResponse } from "cdm/TableStateInterface";
44
import { Literal } from "obsidian-dataview";
5+
import { LOGGER } from "services/Logger";
56
import { AbstractTableAction } from "stateManagement/AbstractTableAction";
67

78
export default class RunFormulaHandlerAction extends AbstractTableAction<AutomationState> {
@@ -31,7 +32,8 @@ export default class RunFormulaHandlerAction extends AbstractTableAction<Automat
3132
try {
3233
return this.evalInput(input, row, config, db);
3334
} catch (e) {
34-
return `Error: ${e}`;
35+
LOGGER.error(`Error evaluating formula from row ${row.__note__.filepath}: `, e);
36+
return "";
3537
}
3638
}
3739

0 commit comments

Comments
 (0)