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

Commit 9d35b8a

Browse files
committed
Merge branch 'clean_legacy'
2 parents 7cf3d16 + 8937e21 commit 9d35b8a

24 files changed

+320
-254
lines changed

package-lock.json

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

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@
2727
"@rollup/plugin-typescript": "11.0.0",
2828
"@rollup/plugin-terser": "0.4.0",
2929
"@testing-library/jest-dom": "5.16.5",
30-
"@testing-library/react": "14.00",
30+
"@testing-library/react": "14.0.0",
3131
"@types/jest": "29.4.0",
3232
"@types/luxon": "3.2.0",
33-
"@types/node": "18.14.0",
33+
"@types/node": "18.14.1",
3434
"@types/react": "18.0.28",
3535
"@types/react-datepicker": "4.8.0",
3636
"@types/react-dom": "18.0.11",
3737
"@types/react-window": "1.8.5",
3838
"@types/papaparse": "5.3.7",
39-
"@typescript-eslint/eslint-plugin": "5.52.0",
40-
"@typescript-eslint/parser": "5.52.0",
39+
"@typescript-eslint/eslint-plugin": "5.53.0",
40+
"@typescript-eslint/parser": "5.53.0",
4141
"eslint": "8.34.0",
4242
"jest": "29.4.3",
43-
"jest-mock-extended": "3.0.1",
43+
"jest-mock-extended": "3.0.2",
4444
"jest-environment-jsdom": "29.4.3",
4545
"obsidian": "1.1.1",
46-
"rollup": "3.16.0",
46+
"rollup": "3.17.2",
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.6",
5454
"@mui/icons-material": "5.11.9",
55-
"@mui/material": "5.11.9",
55+
"@mui/material": "5.11.10",
5656
"@popperjs/core": "2.11.6",
5757
"@tanstack/match-sorter-utils": "8.7.6",
5858
"@tanstack/react-table": "8.7.9",

src/IO/md/RowDatabaseFieldsToFile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Literal } from "obsidian-dataview";
55
import { DateTime } from "luxon";
66
import { DataviewService } from "services/DataviewService";
77
import { ParseService } from "services/ParseService";
8+
89
export const parseFrontmatterFieldsToString = (databaseFields: RowDatabaseFields, localSettings: LocalSettings, deletedColumn?: string): string => {
910
const frontmatterFields = databaseFields.frontmatter;
1011
let array: string[] = [];

src/api/data-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { RowDataType, TableColumn } from "cdm/FolderModel";
22
import { LocalSettings } from "cdm/SettingsModel";
33
import { UpdateRowInfo } from "cdm/TableStateInterface";
44
import { ValueOf } from "typings/base";
5-
import { CustomView } from "views/AbstractView";
65
import { UpdateRowOptions } from "helpers/Constants";
6+
import { TFile } from "obsidian";
77

88
export type UpdateApiInfo = Omit<UpdateRowInfo, "saveOnDisk"> & { action: ValueOf<typeof UpdateRowOptions> };
99
/**
1010
* Abstract class that defines the CRUD API for a given entity.
1111
* Each entity will have a free format data structure, but it will be marshalled to a database standard format.
1212
*/
1313
export abstract class DataApi {
14-
constructor(protected view: CustomView) { }
14+
constructor(protected databaseFile: TFile) { }
1515
/**
1616
* Create a new entity
1717
* @param entity

src/api/obsidian-projects-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { CustomView } from "views/AbstractView";
1515

1616
const projectsMetadataColumns = ["File", "name", "path"];
1717
class ProjectAPI extends ProjectView {
18-
private ignoreDataAutoReload: boolean = false;
18+
private ignoreDataAutoReload = false;
1919
private plugin: DBFolderPlugin;
2020
private view: CustomView;
2121

src/cdm/DatabaseModel.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { RowType } from "cdm/RowTypeModel"
22
import { FilterSettings, LocalSettings } from "cdm/SettingsModel";
33
import { Literal } from "obsidian-dataview/lib/data-model/value";
44
import { TableOptions } from "@tanstack/react-table";
5-
import { BaseColumn, RowDataType } from "cdm/FolderModel";
5+
import { BaseColumn, RowDataType, TableColumn } from "cdm/FolderModel";
66
import { SMarkdownPage } from "obsidian-dataview";
77
import en from "lang/locale/en";
8+
import { TFile } from "obsidian";
9+
import DatabaseInfo from "services/DatabaseInfo";
810

911
/** database column */
1012
export interface DatabaseColumn extends BaseColumn {
@@ -47,4 +49,12 @@ export type NoteInfoPage = Omit<SMarkdownPage, "file"> & {
4749
file: Pick<SMarkdownPage["file"], "link" | "path" | "ctime" | "mtime" | "tasks" | "outlinks" | "inlinks" | "folder">
4850
};
4951

50-
export type LocaleDict = keyof typeof en;
52+
export type LocaleDict = keyof typeof en;
53+
54+
export type RelationInfo = {
55+
recordRows: Record<string, string>;
56+
ddbbFile: TFile,
57+
ddbbInfo: DatabaseInfo,
58+
relatedColumns: TableColumn[],
59+
relatedRows: RowDataType[]
60+
}

src/components/ErrorComponents.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface Props {
66

77
interface State {
88
hasError: boolean;
9+
error?: Error;
910
}
1011

1112
export function boundaryPreRendererComponent(errors: Record<string, string[]>) {
@@ -39,23 +40,28 @@ export function boundaryPreRendererComponent(errors: Record<string, string[]>) {
3940
class DbErrorBoundary extends Component<Props, State> {
4041
public state: State = {
4142
hasError: false,
43+
error: null,
4244
};
4345

44-
public static getDerivedStateFromError(_: Error): State {
46+
public static getDerivedStateFromError(error: Error): State {
4547
// Update state so the next render will show the fallback UI.
46-
return { hasError: true };
48+
return { hasError: true, error: error };
4749
}
4850

4951
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
5052
LOGGER.error("Uncaught error:", error, errorInfo);
5153
}
5254

5355
public render() {
54-
if (this.state.hasError) {
55-
return <h1>Sorry.. there was an error</h1>;
56-
}
57-
58-
return this.props.children;
56+
return this.state.hasError ? (
57+
<>
58+
<h1>Something went wrong.</h1>
59+
<h2>{this.state.error.message}</h2>
60+
<p>{this.state.error.stack}</p>
61+
</>
62+
) : (
63+
this.props.children
64+
);
5965
}
6066
}
6167

src/components/cellTypes/Editor/RelationEditor.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { RelationEditorComponentProps, SelectValue } from "cdm/ComponentsModel";
22
import React, { useEffect } from "react";
33
import { useState } from "react";
4-
import Select from "react-select";
54
import CustomTagsStyles from "components/styles/TagsStyles";
65
import { c } from "helpers/StylesHelper";
7-
import { obtainInfoFromRelation } from "helpers/RelationHelper";
86
import { TableColumn } from "cdm/FolderModel";
97
import { Link } from "obsidian-dataview";
10-
import { OnChangeValue } from "react-select";
11-
import { StyleVariables } from "helpers/Constants";
8+
import { ActionMeta, OnChangeValue } from "react-select";
129
import ClickAwayListener from "@mui/material/ClickAwayListener";
10+
import CreatableSelect from "react-select/creatable";
11+
import { RelationalService } from "services/RelationalService";
1312

1413
const RelationEditor = (props: RelationEditorComponentProps) => {
1514
const { defaultCell, persistChange, relationCell } = props;
@@ -21,18 +20,32 @@ const RelationEditor = (props: RelationEditorComponentProps) => {
2120
? relationCell.map((link: Link) => ({
2221
label: link.fileName(),
2322
value: link.path,
24-
color: StyleVariables.TEXT_NORMAL,
23+
color: tableColumn.config.relation_color,
2524
}))
2625
: []
2726
);
2827
const [relationOptions, setRelationOptions] = useState([]);
2928

3029
// onChange handler
31-
const handleOnChange = async (newValue: OnChangeValue<SelectValue, true>) => {
30+
const handleOnChange = async (
31+
newValue: OnChangeValue<SelectValue, true>,
32+
actionMeta: ActionMeta<SelectValue>
33+
) => {
34+
switch (actionMeta.action) {
35+
case "create-option":
36+
await RelationalService.createNoteIntoRelation(
37+
tableColumn.config.related_note_path,
38+
actionMeta.option.value
39+
);
40+
break;
41+
default:
42+
// Do nothing
43+
}
44+
3245
const arrayTags = newValue.map((tag) => ({
3346
label: tag.label,
3447
value: tag.value,
35-
color: StyleVariables.TEXT_NORMAL,
48+
color: tableColumn.config.relation_color,
3649
}));
3750
setRelationValue(arrayTags);
3851
};
@@ -46,14 +59,14 @@ const RelationEditor = (props: RelationEditorComponentProps) => {
4659

4760
useEffect(() => {
4861
setTimeout(async () => {
49-
const { recordRows } = await obtainInfoFromRelation(
62+
const { recordRows } = await RelationalService.obtainInfoFromRelation(
5063
tableColumn.config.related_note_path
5164
);
5265

5366
const multiOptions = Object.entries(recordRows).map(([key, value]) => ({
5467
label: value,
5568
value: key,
56-
color: StyleVariables.TEXT_NORMAL,
69+
color: tableColumn.config.relation_color,
5770
}));
5871

5972
setRelationOptions(multiOptions);
@@ -63,7 +76,7 @@ const RelationEditor = (props: RelationEditorComponentProps) => {
6376
return (
6477
<ClickAwayListener onClickAway={handleClickAway}>
6578
<div className={c("relation")}>
66-
<Select
79+
<CreatableSelect
6780
defaultValue={relationValue}
6881
components={{
6982
DropdownIndicator: () => null,

src/components/modals/columnSettings/handlers/dropdowns/DatabaseSelectorHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
22
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
33
import { Setting } from "obsidian";
44
import { StringSuggest } from "settings/suggesters/StringSuggester";
5-
import { recordAllDatabases } from "helpers/RelationHelper";
65
import { t } from "lang/helpers";
6+
import { RelationalService } from "services/RelationalService";
77

88
export class DatabaseSelectorHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
99
settingTitle: string = t("column_settings_modal_database_selector_title");
@@ -20,7 +20,7 @@ export class DatabaseSelectorHandler extends AbstractHandlerClass<ColumnSettings
2020
columnSettingsManager.modal.enableReset = true;
2121
columnHandlerResponse.columnSettingsManager.reset(columnHandlerResponse);
2222
}
23-
const avaliableDDBB = recordAllDatabases();
23+
const avaliableDDBB = RelationalService.recordAllDatabases();
2424

2525
new Setting(containerEl)
2626
.setName(this.settingTitle)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
22
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
33
import { Setting } from "obsidian";
44
import { StringSuggest } from "settings/suggesters/StringSuggester";
5-
import { recordFieldsFromRelation } from "helpers/RelationHelper";
65
import { ROLLUP_EMBED_ACTIONS } from "helpers/Constants";
76
import { t } from "lang/helpers";
7+
import { RelationalService } from "services/RelationalService";
88
export class RollupKeyHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
99
settingTitle: string = t("column_settings_modal_rollup_key_title");
1010
handle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
@@ -27,7 +27,7 @@ export class RollupKeyHandler extends AbstractHandlerClass<ColumnSettingsHandler
2727
columnSettingsManager.modal.enableReset = true;
2828
};
2929

30-
recordFieldsFromRelation(
30+
RelationalService.recordFieldsFromRelation(
3131
relationColumn.config.related_note_path,
3232
configState.info.getLocalSettings(),
3333
allColumns

0 commit comments

Comments
 (0)