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

Commit 66fbf29

Browse files
committed
Merge branch '801-bug-using-dataview-query-with-use-all-fields-causes-an-error'
2 parents 717d38d + 34acebf commit 66fbf29

File tree

12 files changed

+967
-917
lines changed

12 files changed

+967
-917
lines changed

package-lock.json

Lines changed: 873 additions & 873 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@
3030
"@testing-library/react": "13.4.0",
3131
"@types/jest": "29.4.0",
3232
"@types/luxon": "3.2.0",
33-
"@types/node": "18.11.18",
34-
"@types/react": "18.0.27",
33+
"@types/node": "18.13.0",
34+
"@types/react": "18.0.28",
3535
"@types/react-datepicker": "4.8.0",
3636
"@types/react-dom": "18.0.10",
3737
"@types/react-window": "1.8.5",
3838
"@types/papaparse": "5.3.7",
39-
"@typescript-eslint/eslint-plugin": "5.50.0",
40-
"@typescript-eslint/parser": "5.50.0",
41-
"eslint": "8.33.0",
42-
"jest": "29.4.1",
39+
"@typescript-eslint/eslint-plugin": "5.52.0",
40+
"@typescript-eslint/parser": "5.52.0",
41+
"eslint": "8.34.0",
42+
"jest": "29.4.2",
4343
"jest-mock-extended": "3.0.1",
44-
"jest-environment-jsdom": "29.4.1",
44+
"jest-environment-jsdom": "29.4.2",
4545
"obsidian": "1.1.1",
46-
"rollup": "3.13.0",
46+
"rollup": "3.15.0",
4747
"rollup-plugin-typescript2": "0.34.1",
4848
"ts-jest": "29.0.5",
4949
"tslib": "2.5.0",
@@ -52,7 +52,7 @@
5252
"dependencies": {
5353
"@emotion/styled": "11.10.5",
5454
"@mui/icons-material": "5.11.0",
55-
"@mui/material": "5.11.7",
55+
"@mui/material": "5.11.8",
5656
"@popperjs/core": "2.11.6",
5757
"@tanstack/match-sorter-utils": "8.7.6",
5858
"@tanstack/react-table": "8.7.9",
@@ -68,6 +68,6 @@
6868
"react-dom": "18.2.0",
6969
"react-select": "5.7.0",
7070
"react-window": "1.8.8",
71-
"zustand": "4.3.2"
71+
"zustand": "4.3.3"
7272
}
7373
}

src/components/modals/columnSettings/handlers/selects/FormulaColumnOptionsHandler.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
77
import { FormulaService } from "services/FormulaService";
88

99
export class FormulaColumnOptionsHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
10-
settingTitle = t("column_settings_modal_option_source_dropdown_title");
10+
settingTitle = t("column_settings_modal_formula_option_source_title");
1111
handle(
1212
columnHandlerResponse: ColumnSettingsHandlerResponse
1313
): ColumnSettingsHandlerResponse {
@@ -24,23 +24,25 @@ export class FormulaColumnOptionsHandler extends AbstractHandlerClass<ColumnSett
2424
};
2525
new Setting(containerEl)
2626
.setName("Formula for column options")
27-
.setDesc("Write a formula to generate the options for this column.")
27+
.setDesc(t("column_settings_modal_formula_option_source_desc"))
2828
.setClass(c("setting-item"))
2929
.addTextArea((textArea) => {
3030
textArea.setValue(currentFormula);
3131
textArea.setPlaceholder("I.E.: [{value: 'a', label: 'A' color: 'red'}, {value: 'b', label: 'B' color: 'blue'}]");
3232
textArea.inputEl.addClass(c("textarea-setting"));
3333
textArea.onChange(formula_promise);
3434
}).addExtraButton((cb) => {
35-
cb.setIcon("pencil")
36-
.setTooltip("Update your column options with the formula above.")
35+
cb.setIcon("reset")
36+
.setTooltip("column_settings_modal_formula_option_source_placeholder")
3737
.onClick(async (): Promise<void> => {
38-
if (currentFormula === config.formula_option_source) {
39-
new Notice("No changes made", 1500);
38+
try {
39+
columnHandlerResponse.column.options = FormulaService.evalOptionsWith(column, automationState.info.getFormulas());
40+
} catch (e) {
41+
new Notice("Error in formula: " + e);
4042
return;
4143
}
42-
columnHandlerResponse.column.options = FormulaService.evalOptionsWith(column, automationState.info.getFormulas());
4344
columnHandlerResponse.column.config.formula_option_source = currentFormula;
45+
4446
// Persist changes
4547
await view.diskConfig.updateColumnConfig(column.id, {
4648
formula_option_source: columnHandlerResponse.column.config.formula_option_source
@@ -61,14 +63,29 @@ export class FormulaColumnOptionsHandler extends AbstractHandlerClass<ColumnSett
6163
href: "https://rafaelgb.github.io/obsidian-db-folder/features/Formulas/",
6264
})
6365
);
64-
// TODO Show column options read-only
66+
// Label-Value pairs table
67+
const tableEl = containerEl.createEl("table");
68+
const thead = tableEl.createEl("thead");
69+
const tr = thead.createEl("tr");
70+
tr.createEl("th", {
71+
text: "Label",
72+
});
73+
tr.createEl("th", {
74+
text: "Value",
75+
});
76+
const tbody = tableEl.createEl("tbody");
77+
// Show column options read-only
6578
columnHandlerResponse.column.options.forEach((option) => {
66-
const optionEl = containerEl.createDiv();
67-
optionEl.style.backgroundColor = option.color;
68-
optionEl.addClass(c("readable-options"));
69-
optionEl.createDiv({ text: option.label });
70-
optionEl.createDiv({ text: option.value });
71-
79+
const tr = tbody.createEl("tr");
80+
tr.addClass(c("center-cell"));
81+
tr.style.backgroundColor = option.color;
82+
// td centering text
83+
tr.createEl("td", {
84+
text: option.label,
85+
});
86+
tr.createEl("td", {
87+
text: option.value,
88+
});
7289
});
7390
}
7491
return this.goNext(columnHandlerResponse);

src/components/modals/columnSettings/handlers/selects/OptionSourceDropdownHandler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export class OptionSourceDropdownHandler extends AbstractHandlerClass<ColumnSett
2323
});
2424

2525
const optionSourcePromise = async (optionSource: string): Promise<void> => {
26-
console.log("optionSourcePromise", optionSource);
2726
if (optionSource === column.config.option_source) {
2827
new Notice("No changes made", 1500);
2928
return;
@@ -34,6 +33,11 @@ export class OptionSourceDropdownHandler extends AbstractHandlerClass<ColumnSett
3433
option_source: optionSource,
3534
});
3635

36+
// Reset options
37+
await view.diskConfig.updateColumnProperties(column.id, {
38+
options: [],
39+
});
40+
3741
columnHandlerResponse.column.config.option_source = optionSource;
3842
// Reset column settings
3943
columnSettingsManager.reset(columnHandlerResponse);

src/lang/locale/en.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ export default {
194194

195195
"column_settings_modal_option_source_dropdown_title": "Select option source",
196196
"column_settings_modal_option_source_dropdown_desc": "Select the source of the options",
197+
"column_settings_modal_formula_option_source_title": "Formula option source",
198+
"column_settings_modal_formula_option_source_desc": "Write your formula to generate the options",
199+
"column_settings_modal_formula_option_source_placeholder": "Write your formula here...",
197200

198201
"column_settings_modal_hide_completed_tasks_toggle_title": "Hide completed tasks",
199202
"column_settings_modal_hide_completed_tasks_toggle_desc": "Enable/disable to hide completed tasks",

src/main.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,6 @@ export default class DBFolderPlugin extends Plugin {
407407
*/
408408
this.registerEvent(
409409
app.metadataCache.on("dataview:index-ready", async () => {
410-
for (const [, { viewMap }] of Array.from(this.windowRegistry.entries())) {
411-
// Refresh all database views
412-
for (const view of viewMap.values()) {
413-
await view.reloadDatabase();
414-
}
415-
}
416-
await sleep(2000);
417410
/**
418411
* Once the index is ready, we can start listening for metadata changes.
419412
*/
@@ -497,7 +490,7 @@ export default class DBFolderPlugin extends Plugin {
497490

498491
// Active View Open Settings
499492
this.addCommand({
500-
id: 'activ-database-folder-open-settings',
493+
id: 'active-database-folder-open-settings',
501494
name: t('active_open_settings'),
502495
checkCallback: (checking) => {
503496
const activeView = app.workspace.getActiveViewOfType(DatabaseView);

src/settings/HelpersSection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SettingHandlerResponse } from 'settings/handlers/AbstractSettingHandler
33
import { AbstractChain } from 'patterns/chain/AbstractFactoryChain';
44
import { AbstractHandler } from 'patterns/chain/AbstractHandler';
55
import { ShowSearchBarByDefaultToggleHandler } from 'settings/handlers/helpersCommands/ShowSearchBarByDefaultToggleHandler';
6-
import { EnableAutoUpdateToggleHandler } from 'settings/handlers/helpersCommands/EnableAutoUpdateTOggleHandler';
6+
import { EnableAutoUpdateToggleHandler } from 'settings/handlers/helpersCommands/EnableAutoUpdateToggleHandler';
77
import { t } from 'lang/helpers';
88

99
class HelpersSection extends AbstractChain<SettingHandlerResponse> {

src/stateManagement/columns/handlers/AlterOptionToColumnAction.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ export default class AlterOptionToColumnHandlerAction extends AbstractTableActio
1111
column: TableColumn,
1212
option: ColumnOption
1313
) => {
14-
if (OptionSource.FORMULA === column.config.formula_option_source) {
14+
if (OptionSource.FORMULA === column.config.option_source) {
1515
// End the execution if the option is from a formula
1616
return;
1717
}
18-
1918
const { value } = option;
2019
// Wrap in a promise of a queue to avoid concurrency issues
2120
const columnIndex = get().columns.findIndex(

src/views/AbstractView.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ export abstract class CustomView extends TextFileView implements HoverParent {
5252
*/
5353
abstract getFormulas(): Promise<Record<string, unknown>>;
5454

55+
/**
56+
* Pre actions to be executed before the database is loaded
57+
*/
58+
abstract preActions(): Promise<void>;
59+
60+
/**
61+
* Post actions to be executed after the database is loaded
62+
*/
63+
abstract postActions(): Promise<void>;
64+
5565
/**
5666
* Abstract
5767
* @param leaf
@@ -93,6 +103,7 @@ export abstract class CustomView extends TextFileView implements HoverParent {
93103
private async initDatabase(): Promise<void> {
94104
try {
95105
LOGGER.info(`=>initDatabase ${this.file.path}`);
106+
await this.preActions();
96107
// Load the database file
97108
this.diskConfig = await new DatabaseInfo(this.file, this.plugin.settings.local_settings).build();
98109
this.setDataApi(this.diskConfig.yaml.config.implementation);
@@ -103,6 +114,8 @@ export abstract class CustomView extends TextFileView implements HoverParent {
103114

104115
// Define table properties
105116
this.shadowColumns = this.columns.filter((col) => col.skipPersist);
117+
118+
await this.postActions();
106119
const tableProps: TableDataType = {
107120
skipReset: false,
108121
view: this,
@@ -111,7 +124,7 @@ export abstract class CustomView extends TextFileView implements HoverParent {
111124
// Render database
112125
const table = createDatabase(tableProps);
113126
this.rootContainer.render(table);
114-
this.diskConfig.saveOnDisk();
127+
await this.diskConfig.saveOnDisk();
115128
LOGGER.info(`<=initDatabase ${this.file.path}`);
116129
} catch (e: unknown) {
117130
LOGGER.error(`initDatabase ${this.file.path}`, e);

src/views/DatabaseView.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import {
33
obtainColumnsFromFolder,
44
obtainMetadataColumns,
55
} from "components/Columns";
6+
import { OptionSource } from "helpers/Constants";
67
import obtainInitialType from "helpers/InitialType";
78
import { adapterTFilesToRows } from "helpers/VaultManagement";
89
import { Db } from "services/CoreService";
10+
import { FormulaService } from "services/FormulaService";
11+
import { LOGGER } from "services/Logger";
912
import { CustomView } from "./AbstractView";
1013

1114
export class DatabaseView extends CustomView {
@@ -35,4 +38,26 @@ export class DatabaseView extends CustomView {
3538
async getFormulas() {
3639
return await Db.buildFns(this.diskConfig.yaml.config);
3740
}
41+
42+
async preActions() {
43+
// Nothing to do
44+
}
45+
46+
async postActions() {
47+
// Automatically update formula options
48+
this.columns.forEach(async (column) => {
49+
const { config } = column;
50+
if (config.option_source === OptionSource.FORMULA) {
51+
LOGGER.info(`Updating options for column ${column.id}`);
52+
const updatedOptions = FormulaService.evalOptionsWith(
53+
column,
54+
this.formulas
55+
);
56+
57+
await this.diskConfig.updateColumnProperties(column.id, {
58+
options: updatedOptions,
59+
});
60+
}
61+
});
62+
}
3863
}

0 commit comments

Comments
 (0)