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

Commit d0402fc

Browse files
committed
Merge branch '5-fr-drag-and-drop-columns-and-persist-order-on-disk'
2 parents 11b2b33 + 89ffb3e commit d0402fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1027
-42349
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,4 @@ main.js
1313

1414
# obsidian
1515
data.json
16-
.DS_Store
17-
18-
# dist exception
19-
!dist/*
16+
.DS_Store

dist/main.js

Lines changed: 0 additions & 41523 deletions
This file was deleted.

jest.config.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
module.exports = {
22
preset: "ts-jest",
33
testEnvironment: "jsdom",
4-
roots: ["src"],
5-
modulePaths: ["src"],
6-
moduleDirectories: ["node_modules"],
4+
rootDir: ".",
5+
roots: [
6+
"<rootDir>",
7+
"<rootDir>/src/",
8+
"<rootDir>/node_modules/"
9+
],
10+
modulePaths: [
11+
"<rootDir>",
12+
"<rootDir>/src",
13+
"<rootDir>/node_modules"
14+
],
15+
moduleNameMapper: {
16+
"src/(.*)": "<rootDir>/src/$1",
17+
"node_modules/(.*)": "<rootDir>/node_modules/$1",
18+
"obsidian-dataview": "<rootDir>/node_modules/obsidian-dataview/lib/index.js"
19+
},
20+
transform: {
21+
"^.+\\.svelte$": [
22+
"svelte-jester",
23+
{
24+
"preprocess": true
25+
}
26+
],
27+
"^.+\\.ts$": "ts-jest"
28+
},
29+
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
30+
moduleDirectories: ["node_modules", "src"],
731
};

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "dbfolder",
33
"name": "DB Folder",
4-
"version": "0.0.4",
4+
"version": "0.0.5",
55
"minAppVersion": "0.14.5",
66
"description": "Folder with the capability to store and retrieve data from a folder like database",
77
"author": "RafaelGB",

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-dbfolder",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
55
"main": "main.js",
66
"scripts": {
@@ -23,18 +23,24 @@
2323
"@rollup/plugin-node-resolve": "13.2.1",
2424
"@rollup/plugin-typescript": "8.3.2",
2525
"@types/jest": "27.4.1",
26+
"@testing-library/jest-dom": "5.16.4",
27+
"@testing-library/react": "12.1.2",
2628
"@types/node": "17.0.25",
2729
"@types/react": "17.0.43",
2830
"@types/react-dom": "17.0.14",
2931
"@types/react-table": "7.7.10",
3032
"@types/react-window": "1.8.5",
33+
"@types/react-beautiful-dnd": "13.1.2",
3134
"@typescript-eslint/eslint-plugin": "5.20.0",
3235
"@typescript-eslint/parser": "5.20.0",
3336
"eslint": "8.13.0",
3437
"jest": "27.5.1",
3538
"obsidian": "0.14.6",
36-
"obsidian-dataview": "0.5.13",
39+
"obsidian-dataview": "0.5.16",
3740
"rollup": "2.70.2",
41+
"svelte-check": "2.7.0",
42+
"svelte-jester": "2.3.2",
43+
"svelte-preprocess": "4.10.6",
3844
"ts-jest": "27.1.4",
3945
"tslib": "2.3.1",
4046
"typescript": "4.6.3"
@@ -48,11 +54,12 @@
4854
"monkey-around": "2.3.0",
4955
"pkg.json": "2.0.8",
5056
"react": "17.0.2",
57+
"react-beautiful-dnd": "13.1.0",
5158
"react-contenteditable": "3.3.6",
5259
"react-dom": "17.0.2",
5360
"react-popper": "2.2.5",
5461
"react-table": "7.7.0",
55-
"react-window": "1.8.6",
62+
"react-window": "1.8.7",
5663
"regenerator-runtime": "0.13.9"
5764
}
5865
}

src/DatabaseView.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TableDataType } from 'cdm/FolderModel';
22
import { obtainColumnsFromFolder, obtainMetadataColumns} from 'components/Columns';
33
import { createDatabase } from 'components/index/Database';
4-
import { DatabaseCore, DataTypes } from 'helpers/Constants';
4+
import { DatabaseCore, DataTypes, StyleClasses } from 'helpers/Constants';
55
import { adapterTFilesToRows } from 'helpers/VaultManagement';
66
import DBFolderPlugin from 'main';
77

@@ -26,6 +26,8 @@ export class DatabaseView extends TextFileView implements HoverParent {
2626
plugin: DBFolderPlugin;
2727
hoverPopover: HoverPopover | null;
2828
tableContainer: HTMLDivElement | null = null;
29+
diskConfig: DatabaseInfo;
30+
2931
constructor(leaf: WorkspaceLeaf, plugin: DBFolderPlugin) {
3032
super(leaf);
3133
this.plugin = plugin;
@@ -107,9 +109,9 @@ export class DatabaseView extends TextFileView implements HoverParent {
107109

108110
async initDatabase(): Promise<void> {
109111
LOGGER.info(`=>initDatabase ${this.file.path}`);
110-
const databaseInfo = new DatabaseInfo(this.file);
111-
await databaseInfo.initDatabaseconfigYaml();
112-
const columns = await obtainColumnsFromFolder(databaseInfo.yaml.columns);
112+
this.diskConfig = new DatabaseInfo(this.file);
113+
await this.diskConfig.initDatabaseconfigYaml(this.plugin.settings.local_settings);
114+
const columns = await obtainColumnsFromFolder(this.diskConfig.yaml.columns);
113115
const metatadaColumns = await obtainMetadataColumns();
114116
columns.push(...metatadaColumns);
115117
const rows = await adapterTFilesToRows(this.file.parent.path);
@@ -119,12 +121,11 @@ export class DatabaseView extends TextFileView implements HoverParent {
119121
data: rows,
120122
skipReset: false,
121123
view: this,
122-
stateManager: this.plugin.getStateManager(this.file),
123-
diskConfig: databaseInfo
124+
stateManager: this.plugin.getStateManager(this.file)
124125
}
125126

126-
let table = createDatabase(tableProps);
127-
this.tableContainer = this.contentEl.createDiv("dbfolder-table-container");
127+
const table = createDatabase(tableProps);
128+
this.tableContainer = this.contentEl.createDiv(StyleClasses.TABLE_CONTAINER);
128129
ReactDOM.render(table, this.tableContainer);
129130
LOGGER.info(`<=initDatabase ${this.file.path}`);
130131
}

src/Settings.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@ import { DatabaseView } from "DatabaseView";
55
import { LOGGER } from "services/Logger";
66
import { developer_settings_section } from "settings/DeveloperSection";
77

8+
interface GlobalSettings {
9+
enable_debug_mode: boolean;
10+
logger_level_info: string;
11+
}
812

13+
export interface LocalSettings {
14+
enable_show_state: boolean;
15+
}
916
export interface DatabaseSettings {
10-
enable_debug_mode: boolean;
11-
logger_level_info: string;
17+
global_settings: GlobalSettings;
18+
local_settings: LocalSettings;
1219
}
1320

1421
export const DEFAULT_SETTINGS: DatabaseSettings = {
22+
global_settings:{
1523
enable_debug_mode: false,
16-
logger_level_info: "error"
24+
logger_level_info: 'error'
25+
},
26+
local_settings:{
27+
enable_show_state: false
28+
}
1729
};
1830

1931
export type SettingRetriever = <K extends keyof DatabaseSettings>(
@@ -49,19 +61,27 @@ export interface SettingsManagerConfig {
4961
this.config = config;
5062
this.settings = settings;
5163
}
52-
constructUI(containerEl: HTMLElement, heading: string, local: boolean) {
64+
65+
/**
66+
* Render settings window
67+
* @param containerEl
68+
* @param heading
69+
* @param local
70+
* @param view optional. Used only for local settings
71+
*/
72+
constructUI(containerEl: HTMLElement, heading: string, local: boolean,view?: DatabaseView) {
5373
/** Common modal headings */
5474
containerEl.empty();
5575
containerEl.addClass('database-settings-modal');
5676
add_setting_header(containerEl,heading,'h2');
5777
const settingsBody:HTMLDivElement = containerEl.createDiv('database-settings-body');
58-
this.constructSettingBody(settingsBody, local);
78+
this.constructSettingBody(settingsBody, local, view);
5979
}
6080

61-
constructSettingBody(containerEl: HTMLElement, local: boolean) {
81+
constructSettingBody(containerEl: HTMLElement, local: boolean, view?: DatabaseView) {
6282
containerEl.empty();
6383
/** Developer section */
64-
developer_settings_section(this, containerEl, local);
84+
developer_settings_section(this, containerEl, local, view);
6585
}
6686
cleanUp() {
6787
this.cleanupFns.forEach((fn) => fn());
@@ -89,7 +109,7 @@ export class SettingsModal extends Modal {
89109

90110
modalEl.addClass('database-settings-modal');
91111

92-
this.settingsManager.constructUI(contentEl, this.view.file.basename, true);
112+
this.settingsManager.constructUI(contentEl, this.view.file.basename, true, this.view);
93113
}
94114

95115
onClose() {
@@ -117,6 +137,6 @@ export class DBFolderSettingTab extends PluginSettingTab {
117137

118138
export function loadServicesThatRequireSettings(settings: DatabaseSettings) {
119139
/** Init logger */
120-
LOGGER.setDebugMode(settings.enable_debug_mode);
121-
LOGGER.setLevelInfo(settings.logger_level_info);
140+
LOGGER.setDebugMode(settings.global_settings.enable_debug_mode);
141+
LOGGER.setLevelInfo(settings.global_settings.logger_level_info);
122142
}

src/__tests__/reactTable.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { render, screen } from "@testing-library/react";
2+
import obsidian from 'obsidian';
3+
import { Database } from 'components/index/Database';
4+
import {TableDataType} from 'cdm/FolderModel';
5+
import { makeData } from "mock/mockUtils";
6+
import React from "react";
7+
8+
// jest.mock("obsidian");
9+
10+
test("Render without crashing", () => {
11+
// const mockedTableData:TableDataType = makeData(10);
12+
// render(<Database {...mockedTableData} />);
13+
// const titleLabel = screen.getByText(" title");
14+
// expect(titleLabel).toBeInTheDocument();
15+
});
16+

src/cdm/DatabaseModel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { RowType } from "cdm/RowTypeModel"
2+
import { LocalSettings } from "Settings"
23

34
/** database column */
45
export type DatabaseColumn = {
56
input: string,
67
Header?: string,
78
key?: string,
9+
position?: number,
810
accessor: string,
911
label: string,
1012
isMetadata?: boolean,
@@ -19,4 +21,7 @@ export type DatabaseYaml = {
1921
description: string,
2022
/** database columns */
2123
columns: Record<string, DatabaseColumn>
24+
/** database local configuration
25+
* TODO typing*/
26+
config?: LocalSettings
2227
}

src/cdm/FolderModel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ export type Models = {
3030
}
3131

3232
export type TableColumn = {
33-
id: number,
33+
id: string,
3434
Header?: any,
3535
label?: string,
3636
key: string,
37+
position: number,
3738
accessor: any,
3839
minWidth?: number,
3940
width?:number
@@ -58,8 +59,7 @@ export type TableDataType={
5859
skipReset: boolean,
5960
view: DatabaseView,
6061
stateManager?: StateManager,
61-
dispatch?: Dispatch<any>,
62-
diskConfig: DatabaseInfo
62+
dispatch?: Dispatch<any>
6363
}
6464
export interface DatabaseHeaderProps{
6565
columns:any,

0 commit comments

Comments
 (0)