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

Commit fe66af7

Browse files
committed
Merge branch 'master' into imed-docu-branch
2 parents eb8bc3d + 2a70616 commit fe66af7

40 files changed

+1012
-69
lines changed

docs/docs/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
## 2.8.0
3+
### Shiny new things
4+
- Added video examples to the docs for each section [imeed166](https://github.com/imeed166)
25
## 2.7.4
36
### Shiny new things
47
- names of tags are now editable (updating all the related rows) [ISSUE#443](https://github.com/RafaelGB/obsidian-db-folder/issues/443)

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@
1919
"license": "MIT",
2020
"devDependencies": {
2121
"@faker-js/faker": "7.6.0",
22-
"@rollup/plugin-commonjs": "23.0.0",
23-
"@rollup/plugin-json": "5.0.0",
24-
"@rollup/plugin-node-resolve": "15.0.0",
25-
"@rollup/plugin-replace": "5.0.0",
26-
"@rollup/plugin-typescript": "9.0.1",
22+
"@rollup/plugin-commonjs": "23.0.2",
23+
"@rollup/plugin-json": "5.0.1",
24+
"@rollup/plugin-node-resolve": "15.0.1",
25+
"@rollup/plugin-replace": "5.0.1",
26+
"@rollup/plugin-typescript": "9.0.2",
2727
"@testing-library/jest-dom": "5.16.5",
2828
"@testing-library/react": "13.4.0",
29-
"@types/jest": "29.1.2",
30-
"@types/luxon": "3.0.1",
31-
"@types/node": "18.11.0",
29+
"@types/jest": "29.2.0",
30+
"@types/luxon": "3.0.2",
31+
"@types/node": "18.11.4",
3232
"@types/react": "18.0.21",
3333
"@types/react-csv": "1.1.3",
3434
"@types/react-datepicker": "4.4.2",
3535
"@types/react-dom": "18.0.6",
3636
"@types/react-window": "1.8.5",
37-
"@typescript-eslint/eslint-plugin": "5.40.0",
38-
"@typescript-eslint/parser": "5.40.0",
37+
"@typescript-eslint/eslint-plugin": "5.40.1",
38+
"@typescript-eslint/parser": "5.40.1",
3939
"eslint": "8.25.0",
40-
"jest": "29.2.0",
40+
"jest": "29.2.1",
4141
"jest-mock-extended": "3.0.1",
4242
"obsidian": "0.16.3",
4343
"rollup": "2.79.1",
@@ -50,7 +50,7 @@
5050
"dependencies": {
5151
"@emotion/styled": "11.10.4",
5252
"@mui/icons-material": "5.10.9",
53-
"@mui/material": "5.10.9",
53+
"@mui/material": "5.10.10",
5454
"@popperjs/core": "2.11.6",
5555
"@tanstack/match-sorter-utils": "8.5.14",
5656
"@tanstack/react-table": "8.5.15",
@@ -64,8 +64,8 @@
6464
"react-datepicker": "4.8.0",
6565
"react-dom": "18.2.0",
6666
"react-popper": "2.3.0",
67-
"react-select": "5.5.0",
67+
"react-select": "5.5.4",
6868
"react-window": "1.8.7",
69-
"zustand": "4.1.2"
69+
"zustand": "4.1.3"
7070
}
7171
}

src/automations/AutomationsHelper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { LocalSettings } from "cdm/SettingsModel";
22
import { FormulaGenerator } from "automations/FormulaGenerator";
3-
import { AutomationError, showDBError } from "errors/ErrorTypes";
43

54
export async function obtainFormulasFromFolder(config: LocalSettings) {
65
const generator = new FormulaGenerator(config);
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { FormulaFunctions } from "automations/formula_functions/FormulaFunctions";
22
import { IGenerateObject } from "automations/IGenerateObject";
33
import { LocalSettings } from "cdm/SettingsModel";
4+
import { Link } from "obsidian-dataview";
5+
import { DataviewService } from "services/DataviewService";
6+
import Rollup from "automations/Rollup";
47
export class FormulaGenerator implements IGenerateObject {
58
public js_functions: FormulaFunctions;
69

@@ -9,15 +12,17 @@ export class FormulaGenerator implements IGenerateObject {
912
}
1013

1114
private async generate_js_functions(): Promise<Record<string, unknown>> {
12-
1315
return await this.js_functions.generate_object(this.config);
1416
}
1517

1618
async generate_object(): Promise<Record<string, unknown>> {
1719
const final_object: Record<string, any> = {};
1820
Object.assign(final_object, {
1921
js: await this.generate_js_functions(),
20-
});
22+
dataview: DataviewService.getDataviewAPI(),
23+
rollup: (relation: Link[], action?: string, key?: string) => new Rollup(relation, action, key)
24+
}
25+
);
2126
return final_object;
2227
}
2328
}

src/automations/Rollup.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { DEFAULT_SETTINGS, InputType, ROLLUP_ACTIONS } from "helpers/Constants";
2+
import { Link, Literal } from "obsidian-dataview";
3+
import { DataviewService } from "services/DataviewService";
4+
import { LOGGER } from "services/Logger";
5+
import { ParseService } from "services/ParseService";
6+
7+
class Rollup {
8+
private pages: Record<string, Literal>[];
9+
private action: string;
10+
private key: string;
11+
12+
static generatePages(relation: Link[]): Record<string, Literal>[] {
13+
return relation.map((link) =>
14+
DataviewService.getDataviewAPI().page(link.path)
15+
);
16+
}
17+
18+
constructor(relation: Link[], action?: string, key?: string) {
19+
const consultedLinks = Rollup.generatePages(relation);
20+
this.pages = consultedLinks;
21+
this.action = action;
22+
this.key = key;
23+
}
24+
25+
public dispatch(): string {
26+
let result = "";
27+
switch (this.action) {
28+
case ROLLUP_ACTIONS.SUM:
29+
result = this.sum();
30+
break;
31+
case ROLLUP_ACTIONS.COUNT_ALL:
32+
result = this.countAll();
33+
break;
34+
case ROLLUP_ACTIONS.ORIGINAL_VALUE:
35+
result = this.originalValue();
36+
break;
37+
default:
38+
// No valid action found
39+
LOGGER.warn(`No valid action found for rollup: ${this.action}`);
40+
}
41+
return result;
42+
}
43+
44+
public getPages(): Record<string, Literal>[] {
45+
return this.pages;
46+
}
47+
48+
/**
49+
* Iters over the pages and sums the values of the key
50+
* @returns
51+
*/
52+
private sum(): string {
53+
// Check if key is not truthy, return empty string
54+
if (!this.key) {
55+
return "";
56+
}
57+
let sum = 0;
58+
this.pages.forEach((page) => {
59+
if (page[this.key]) {
60+
sum += Number(page[this.key]);
61+
}
62+
});
63+
return sum.toString();
64+
}
65+
66+
/**
67+
* Obtains the number of pages of the relation with the key informed
68+
* @returns
69+
*/
70+
private countAll(): string {
71+
return this.pages.filter((page) => page[this.key]).length.toString();
72+
}
73+
74+
/**
75+
* Returns the original value map of the pages with the key informed
76+
* @returns
77+
*/
78+
private originalValue(): string {
79+
// TODO use local settings of the table instead of default settings
80+
return this.pages
81+
.filter((page) => page[this.key])
82+
.map((page) => ParseService.parseLiteral(page[this.key], InputType.MARKDOWN, DEFAULT_SETTINGS.local_settings)).join(", ");
83+
}
84+
85+
}
86+
87+
export default Rollup;

src/cdm/ComponentsModel.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CellContext, Table } from "@tanstack/react-table";
22
import { RowDataType } from "cdm/FolderModel";
3-
import { Literal } from "obsidian-dataview/lib/data-model/value";
3+
import { Link, Literal } from "obsidian-dataview/lib/data-model/value";
44
import { AtomicFilter } from "cdm/SettingsModel";
55

66
export type RowSelectOption = {
@@ -22,6 +22,11 @@ export type EditorCellComponentProps = {
2222
textCell: string;
2323
} & CellComponentProps;
2424

25+
export type RelationEditorComponentProps = {
26+
persistChange: (newPath: string[]) => void;
27+
relationCell: Link[];
28+
} & CellComponentProps;
29+
2530
export type DataviewFiltersProps = {
2631
table: Table<RowDataType>;
2732
};

src/cdm/DatabaseModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FilterSettings, LocalSettings } from "cdm/SettingsModel";
33
import { Literal } from "obsidian-dataview/lib/data-model/value";
44
import { TableOptions } from "@tanstack/react-table";
55
import { BaseColumn, RowDataType } from "cdm/FolderModel";
6-
import { DateTime, SMarkdownPage, STask } from "obsidian-dataview";
6+
import { SMarkdownPage } from "obsidian-dataview";
77

88
/** database column */
99
export interface DatabaseColumn extends BaseColumn {

src/cdm/FolderModel.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ export interface ConfigColumn {
4949
// Formulas
5050
formula_query?: string;
5151
persist_formula?: boolean;
52+
// Relations
53+
related_note_path?: string;
54+
// Rollups
55+
asociated_relation_id?: string;
56+
rollup_action?: string;
57+
rollup_key?: string;
58+
persist_rollup?: boolean;
5259
/** Extras from yaml */
5360
[key: string]: Literal;
5461
}
@@ -62,7 +69,6 @@ export type BaseColumn = {
6269
config: ConfigColumn;
6370
/** Circunstancial */
6471
nestedKey?: string;
65-
options?: RowSelectOption[];
6672
csvCandidate?: boolean;
6773
width?: number;
6874
position?: number;
@@ -73,7 +79,10 @@ export type BaseColumn = {
7379
isHidden?: boolean;
7480
skipPersist?: boolean;
7581
isDragDisabled?: boolean;
82+
// Selects & Tags
83+
options?: RowSelectOption[];
7684
}
85+
7786
export type TableColumn = ColumnDef<RowDataType, Literal> & BaseColumn;
7887

7988
export type RowDataType = {

src/cdm/TableStateInterface.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ColumnOrderState, SortingState } from "@tanstack/react-table";
2-
import { RowDataType, TableColumn } from "cdm/FolderModel";
2+
import { ConfigColumn, RowDataType, TableColumn } from "cdm/FolderModel";
33
import { FilterSettings, GlobalSettings, LocalSettings } from "cdm/SettingsModel";
44
import { DatabaseView } from "DatabaseView";
5-
import { Literal } from "obsidian-dataview";
5+
import { Link, Literal } from "obsidian-dataview";
66
import { StoreApi, UseBoundStore } from "zustand";
77

88
export type TableActionResponse<T> = {
@@ -60,7 +60,7 @@ export interface ColumnsState {
6060
addToRight: (column: TableColumn, customName?: string) => void;
6161
remove: (column: TableColumn) => void;
6262
alterSorting: (column: TableColumn) => void;
63-
addOptionToColumn: (column: TableColumn, option: string, backgroundColor: string) => Promise<void>;
63+
addOptionToColumn: (column: TableColumn, option: string, backgroundColor: string) => void;
6464
alterColumnType: (column: TableColumn, input: string, parsedRows?: RowDataType[]) => Promise<void>;
6565
alterColumnId: (column: TableColumn, root: string, nestedIds: string[]) => Promise<void>;
6666
alterColumnLabel: (column: TableColumn, label: string) => Promise<void>;
@@ -92,6 +92,7 @@ export interface AutomationState {
9292
info: {
9393
getFormula: (name: string) => unknown;
9494
runFormula: (input: string, row: RowDataType, dbbConfig: LocalSettings) => Literal;
95+
dispatchRollup: (configColumn: ConfigColumn, relation: Link[], dbbConfig: LocalSettings) => Literal;
9596
},
9697
actions: {
9798
loadFormulas: (ddbbConfig: LocalSettings) => Promise<void>;

src/components/DefaultCell.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import TextCell from "components/cellTypes/TextCell";
1414
import MetadataTimeCell from "components/cellTypes/MetadataTimeCell";
1515
import InOutLinksCell from "components/cellTypes/InOutLinksCell";
1616
import FormulaCell from "components/cellTypes/FormulaCell";
17+
import RelationCell from "components/cellTypes/RelationCell";
18+
import RollupCell from "components/cellTypes/RollupCell";
1719
import { CellContext } from "@tanstack/react-table";
1820
import { Literal } from "obsidian-dataview";
1921

@@ -78,6 +80,14 @@ export default function DefaultCell(
7880
case InputType.FORMULA:
7981
return <FormulaCell defaultCell={defaultCell} />;
8082

83+
/** Relation with another ddbb */
84+
case InputType.RELATION:
85+
return <RelationCell defaultCell={defaultCell} />;
86+
87+
/** Rollup info of a relation */
88+
case InputType.ROLLUP:
89+
return <RollupCell defaultCell={defaultCell} />;
90+
8191
/** New column option */
8292
case InputType.NEW_COLUMN:
8393
// Do nothing

0 commit comments

Comments
 (0)