Skip to content

Commit

Permalink
Merge branch 'clean_legacy'
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGB committed Feb 26, 2023
2 parents 7cf3d16 + 8937e21 commit 9d35b8a
Show file tree
Hide file tree
Showing 24 changed files with 320 additions and 254 deletions.
222 changes: 111 additions & 111 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@
"@rollup/plugin-typescript": "11.0.0",
"@rollup/plugin-terser": "0.4.0",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "14.00",
"@testing-library/react": "14.0.0",
"@types/jest": "29.4.0",
"@types/luxon": "3.2.0",
"@types/node": "18.14.0",
"@types/node": "18.14.1",
"@types/react": "18.0.28",
"@types/react-datepicker": "4.8.0",
"@types/react-dom": "18.0.11",
"@types/react-window": "1.8.5",
"@types/papaparse": "5.3.7",
"@typescript-eslint/eslint-plugin": "5.52.0",
"@typescript-eslint/parser": "5.52.0",
"@typescript-eslint/eslint-plugin": "5.53.0",
"@typescript-eslint/parser": "5.53.0",
"eslint": "8.34.0",
"jest": "29.4.3",
"jest-mock-extended": "3.0.1",
"jest-mock-extended": "3.0.2",
"jest-environment-jsdom": "29.4.3",
"obsidian": "1.1.1",
"rollup": "3.16.0",
"rollup": "3.17.2",
"rollup-plugin-typescript2": "0.34.1",
"ts-jest": "29.0.5",
"tslib": "2.5.0",
Expand All @@ -52,7 +52,7 @@
"dependencies": {
"@emotion/styled": "11.10.6",
"@mui/icons-material": "5.11.9",
"@mui/material": "5.11.9",
"@mui/material": "5.11.10",
"@popperjs/core": "2.11.6",
"@tanstack/match-sorter-utils": "8.7.6",
"@tanstack/react-table": "8.7.9",
Expand Down
1 change: 1 addition & 0 deletions src/IO/md/RowDatabaseFieldsToFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Literal } from "obsidian-dataview";
import { DateTime } from "luxon";
import { DataviewService } from "services/DataviewService";
import { ParseService } from "services/ParseService";

export const parseFrontmatterFieldsToString = (databaseFields: RowDatabaseFields, localSettings: LocalSettings, deletedColumn?: string): string => {
const frontmatterFields = databaseFields.frontmatter;
let array: string[] = [];
Expand Down
4 changes: 2 additions & 2 deletions src/api/data-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { RowDataType, TableColumn } from "cdm/FolderModel";
import { LocalSettings } from "cdm/SettingsModel";
import { UpdateRowInfo } from "cdm/TableStateInterface";
import { ValueOf } from "typings/base";
import { CustomView } from "views/AbstractView";
import { UpdateRowOptions } from "helpers/Constants";
import { TFile } from "obsidian";

export type UpdateApiInfo = Omit<UpdateRowInfo, "saveOnDisk"> & { action: ValueOf<typeof UpdateRowOptions> };
/**
* Abstract class that defines the CRUD API for a given entity.
* Each entity will have a free format data structure, but it will be marshalled to a database standard format.
*/
export abstract class DataApi {
constructor(protected view: CustomView) { }
constructor(protected databaseFile: TFile) { }
/**
* Create a new entity
* @param entity
Expand Down
2 changes: 1 addition & 1 deletion src/api/obsidian-projects-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CustomView } from "views/AbstractView";

const projectsMetadataColumns = ["File", "name", "path"];
class ProjectAPI extends ProjectView {
private ignoreDataAutoReload: boolean = false;
private ignoreDataAutoReload = false;
private plugin: DBFolderPlugin;
private view: CustomView;

Expand Down
14 changes: 12 additions & 2 deletions src/cdm/DatabaseModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { RowType } from "cdm/RowTypeModel"
import { FilterSettings, LocalSettings } from "cdm/SettingsModel";
import { Literal } from "obsidian-dataview/lib/data-model/value";
import { TableOptions } from "@tanstack/react-table";
import { BaseColumn, RowDataType } from "cdm/FolderModel";
import { BaseColumn, RowDataType, TableColumn } from "cdm/FolderModel";
import { SMarkdownPage } from "obsidian-dataview";
import en from "lang/locale/en";
import { TFile } from "obsidian";
import DatabaseInfo from "services/DatabaseInfo";

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

export type LocaleDict = keyof typeof en;
export type LocaleDict = keyof typeof en;

export type RelationInfo = {
recordRows: Record<string, string>;
ddbbFile: TFile,
ddbbInfo: DatabaseInfo,
relatedColumns: TableColumn[],
relatedRows: RowDataType[]
}
20 changes: 13 additions & 7 deletions src/components/ErrorComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface Props {

interface State {
hasError: boolean;
error?: Error;
}

export function boundaryPreRendererComponent(errors: Record<string, string[]>) {
Expand Down Expand Up @@ -39,23 +40,28 @@ export function boundaryPreRendererComponent(errors: Record<string, string[]>) {
class DbErrorBoundary extends Component<Props, State> {
public state: State = {
hasError: false,
error: null,
};

public static getDerivedStateFromError(_: Error): State {
public static getDerivedStateFromError(error: Error): State {
// Update state so the next render will show the fallback UI.
return { hasError: true };
return { hasError: true, error: error };
}

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

public render() {
if (this.state.hasError) {
return <h1>Sorry.. there was an error</h1>;
}

return this.props.children;
return this.state.hasError ? (
<>
<h1>Something went wrong.</h1>
<h2>{this.state.error.message}</h2>
<p>{this.state.error.stack}</p>
</>
) : (
this.props.children
);
}
}

Expand Down
33 changes: 23 additions & 10 deletions src/components/cellTypes/Editor/RelationEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { RelationEditorComponentProps, SelectValue } from "cdm/ComponentsModel";
import React, { useEffect } from "react";
import { useState } from "react";
import Select from "react-select";
import CustomTagsStyles from "components/styles/TagsStyles";
import { c } from "helpers/StylesHelper";
import { obtainInfoFromRelation } from "helpers/RelationHelper";
import { TableColumn } from "cdm/FolderModel";
import { Link } from "obsidian-dataview";
import { OnChangeValue } from "react-select";
import { StyleVariables } from "helpers/Constants";
import { ActionMeta, OnChangeValue } from "react-select";
import ClickAwayListener from "@mui/material/ClickAwayListener";
import CreatableSelect from "react-select/creatable";
import { RelationalService } from "services/RelationalService";

const RelationEditor = (props: RelationEditorComponentProps) => {
const { defaultCell, persistChange, relationCell } = props;
Expand All @@ -21,18 +20,32 @@ const RelationEditor = (props: RelationEditorComponentProps) => {
? relationCell.map((link: Link) => ({
label: link.fileName(),
value: link.path,
color: StyleVariables.TEXT_NORMAL,
color: tableColumn.config.relation_color,
}))
: []
);
const [relationOptions, setRelationOptions] = useState([]);

// onChange handler
const handleOnChange = async (newValue: OnChangeValue<SelectValue, true>) => {
const handleOnChange = async (
newValue: OnChangeValue<SelectValue, true>,
actionMeta: ActionMeta<SelectValue>
) => {
switch (actionMeta.action) {
case "create-option":
await RelationalService.createNoteIntoRelation(
tableColumn.config.related_note_path,
actionMeta.option.value
);
break;
default:
// Do nothing
}

const arrayTags = newValue.map((tag) => ({
label: tag.label,
value: tag.value,
color: StyleVariables.TEXT_NORMAL,
color: tableColumn.config.relation_color,
}));
setRelationValue(arrayTags);
};
Expand All @@ -46,14 +59,14 @@ const RelationEditor = (props: RelationEditorComponentProps) => {

useEffect(() => {
setTimeout(async () => {
const { recordRows } = await obtainInfoFromRelation(
const { recordRows } = await RelationalService.obtainInfoFromRelation(
tableColumn.config.related_note_path
);

const multiOptions = Object.entries(recordRows).map(([key, value]) => ({
label: value,
value: key,
color: StyleVariables.TEXT_NORMAL,
color: tableColumn.config.relation_color,
}));

setRelationOptions(multiOptions);
Expand All @@ -63,7 +76,7 @@ const RelationEditor = (props: RelationEditorComponentProps) => {
return (
<ClickAwayListener onClickAway={handleClickAway}>
<div className={c("relation")}>
<Select
<CreatableSelect
defaultValue={relationValue}
components={{
DropdownIndicator: () => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
import { Setting } from "obsidian";
import { StringSuggest } from "settings/suggesters/StringSuggester";
import { recordAllDatabases } from "helpers/RelationHelper";
import { t } from "lang/helpers";
import { RelationalService } from "services/RelationalService";

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

new Setting(containerEl)
.setName(this.settingTitle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { ColumnSettingsHandlerResponse } from "cdm/ModalsModel";
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
import { Setting } from "obsidian";
import { StringSuggest } from "settings/suggesters/StringSuggester";
import { recordFieldsFromRelation } from "helpers/RelationHelper";
import { ROLLUP_EMBED_ACTIONS } from "helpers/Constants";
import { t } from "lang/helpers";
import { RelationalService } from "services/RelationalService";
export class RollupKeyHandler extends AbstractHandlerClass<ColumnSettingsHandlerResponse> {
settingTitle: string = t("column_settings_modal_rollup_key_title");
handle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
Expand All @@ -27,7 +27,7 @@ export class RollupKeyHandler extends AbstractHandlerClass<ColumnSettingsHandler
columnSettingsManager.modal.enableReset = true;
};

recordFieldsFromRelation(
RelationalService.recordFieldsFromRelation(
relationColumn.config.related_note_path,
configState.info.getLocalSettings(),
allColumns
Expand Down
6 changes: 4 additions & 2 deletions src/components/styles/TagsStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ const CustomTagsStyles: StylesConfig<any, true, GroupBase<unknown>> = {
}),
singleValue: (styles, { data }) => ({
...styles,
backgroundColor: data.color
backgroundColor: data.color,
color: Db.coreFns.colors.getContrast(data.color),
}),
multiValue: (styles, { data }) => {
return {
...styles,
backgroundColor: data.color
backgroundColor: data.color,
color: Db.coreFns.colors.getContrast(data.color)
};
},
multiValueLabel: (styles, { data }) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export const WRAPPERER_KEY = `_\\*~\``;
export const INLINE_REGEX = Object.freeze({
INLINE_WITHOUT_FRONTMATTER: /(^[\s\S]*$)/g,
INLINE_WITH_FRONTMATTER: /(^---[\s\S]+?---)+([\s\S]*$)/g,
INLINE_LAST_FIELD: /([\s\S]*)(^[^_*~`a-zA-Z1-9\[\(]*)([\[\(]{0,1})([_*~`]{0,2})([A-Za-z0-9]+)([_*~`]{0,2})([:]{2})([^\]\)\n]+)([\]\)]{0,1})(.*$)(\n{0,1})([\s\S]*)/gm
INLINE_LAST_FIELD: /([\s\S]*)(^[^_*~`a-zA-Z1-9[(]*)([[(]{0,1})([_*~`]{0,2})([A-Za-z0-9]+)([_*~`]{0,2})([:]{2})([^\])\n]+)([\])]{0,1})(.*$)(\n{0,1})([\s\S]*)/gm
});

/******************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/FileManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export function get_tfiles_from_folder(
return files;
}

export function destination_folder(view: CustomView, ddbbConfig: LocalSettings): string {
let destination_folder = view.file.parent.path;
export function destination_folder(databaseFile: TFile, ddbbConfig: LocalSettings): string {
let destination_folder = databaseFile.parent.path;
switch (ddbbConfig.source_data) {
case SourceDataTypes.TAG:
case SourceDataTypes.OUTGOING_LINK:
Expand Down
63 changes: 0 additions & 63 deletions src/helpers/RelationHelper.ts

This file was deleted.

Loading

0 comments on commit 9d35b8a

Please sign in to comment.