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

Commit d2b7ff1

Browse files
committed
Merge branch '227-migrate-actual-dispatcher-to-zustand'
2 parents 2d3bb8b + 4c6ed4b commit d2b7ff1

Some content is hidden

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

56 files changed

+1489
-1259
lines changed

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
"@rollup/plugin-commonjs": "22.0.1",
2222
"@rollup/plugin-json": "4.1.0",
2323
"@rollup/plugin-node-resolve": "13.3.0",
24-
"@rollup/plugin-typescript": "8.3.3",
24+
"@rollup/plugin-typescript": "8.3.4",
2525
"@types/jest": "28.1.6",
2626
"@testing-library/jest-dom": "5.16.4",
2727
"@testing-library/react": "13.3.0",
28-
"@types/node": "18.6.1",
28+
"@types/node": "18.6.3",
2929
"@types/react": "18.0.15",
3030
"@types/react-dom": "18.0.6",
3131
"@types/react-color": "3.0.6",
@@ -36,7 +36,7 @@
3636
"@types/luxon": "3.0.0",
3737
"@typescript-eslint/eslint-plugin": "5.30.7",
3838
"@typescript-eslint/parser": "5.30.7",
39-
"eslint": "8.20.0",
39+
"eslint": "8.21.0",
4040
"jest": "28.1.3",
4141
"jest-mock-extended": "2.0.7",
4242
"obsidian": "0.15.4",
@@ -49,8 +49,8 @@
4949
"@faker-js/faker": "7.3.0"
5050
},
5151
"dependencies": {
52-
"@emotion/styled": "11.9.3",
53-
"@mui/material": "5.9.2",
52+
"@emotion/styled": "11.10.0",
53+
"@mui/material": "5.9.3",
5454
"@mui/icons-material": "5.8.4",
5555
"@popperjs/core": "2.11.5",
5656
"immutability-helper": "3.1.1",
@@ -63,13 +63,14 @@
6363
"react-dom": "18.2.0",
6464
"react-csv": "2.2.2",
6565
"react-popper": "2.3.0",
66-
"@tanstack/react-table": "8.5.1",
66+
"@tanstack/react-table": "8.5.5",
6767
"@tanstack/match-sorter-utils": "8.1.1",
6868
"react-select": "5.4.0",
6969
"react-color": "2.19.3",
7070
"react-window": "1.8.7",
7171
"react-datepicker": "4.8.0",
7272
"regenerator-runtime": "0.13.9",
73-
"luxon": "3.0.1"
73+
"luxon": "3.0.1",
74+
"zustand": "4.0.0"
7475
}
7576
}

src/DatabaseView.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import { DatabaseColumn } from "cdm/DatabaseModel";
2-
import { InitialState, RowDataType, TableDataType } from "cdm/FolderModel";
2+
import {
3+
InitialType,
4+
RowDataType,
5+
TableColumn,
6+
TableDataType,
7+
} from "cdm/FolderModel";
8+
import { TableStateInterface } from "cdm/TableStateInterface";
39
import {
410
obtainColumnsFromFolder,
511
obtainMetadataColumns,
612
} from "components/Columns";
713
import { createDatabase } from "components/index/Database";
814
import { DbFolderException } from "errors/AbstractException";
915
import { DatabaseCore, InputType, StyleClasses } from "helpers/Constants";
10-
import obtainInitialState from "helpers/InitialState";
16+
import obtainInitialType from "helpers/InitialType";
1117
import { adapterTFilesToRows, isDatabaseNote } from "helpers/VaultManagement";
1218
import DBFolderPlugin from "main";
1319

@@ -23,6 +29,12 @@ import { createRoot, Root } from "react-dom/client";
2329
import DatabaseInfo from "services/DatabaseInfo";
2430
import { LOGGER } from "services/Logger";
2531
import { SettingsModal } from "Settings";
32+
import useColumnsStore from "stateManagement/useColumnsStore";
33+
import useConfigStore from "stateManagement/useConfigStore";
34+
import useDataStore from "stateManagement/useDataStore";
35+
import useInitialTypeStore from "stateManagement/useInitialTypeStore";
36+
import useRowTemplateStore from "stateManagement/useRowTemplateStore";
37+
import useSortingStore from "stateManagement/useSortingStore";
2638
import StateManager from "StateManager";
2739
export const databaseIcon = "blocks";
2840

@@ -33,6 +45,10 @@ export class DatabaseView extends TextFileView implements HoverParent {
3345
rootContainer: Root | null = null;
3446
diskConfig: DatabaseInfo;
3547
rows: Array<RowDataType>;
48+
columns: Array<TableColumn>;
49+
shadowColumns: Array<TableColumn>;
50+
initial: InitialType;
51+
3652
constructor(leaf: WorkspaceLeaf, plugin: DBFolderPlugin) {
3753
super(leaf);
3854
this.plugin = plugin;
@@ -127,29 +143,27 @@ export class DatabaseView extends TextFileView implements HoverParent {
127143
);
128144
let yamlColumns: Record<string, DatabaseColumn> =
129145
this.diskConfig.yaml.columns;
146+
this.diskConfig.yaml.config;
130147
// Complete the columns with the metadata columns
131148
yamlColumns = await obtainMetadataColumns(
132149
yamlColumns,
133150
this.diskConfig.yaml.config
134151
);
135152
// Obtain base information about columns
136-
const columns = await obtainColumnsFromFolder(yamlColumns);
153+
this.columns = await obtainColumnsFromFolder(yamlColumns);
137154
this.rows = await adapterTFilesToRows(
138155
this.file.parent.path,
139-
columns,
156+
this.columns,
140157
this.diskConfig.yaml
141158
);
142-
const initialState: InitialState = obtainInitialState(columns, this.rows);
159+
this.initial = obtainInitialType(this.columns, this.rows);
143160
// Define table properties
161+
this.shadowColumns = this.columns.filter((col) => col.skipPersist);
144162
const tableProps: TableDataType = {
145-
columns: columns,
146-
shadowColumns: columns.filter((col) => col.skipPersist),
147163
skipReset: false,
148164
view: this,
149165
stateManager: this.plugin.getStateManager(this.file),
150-
initialState: initialState,
151166
};
152-
153167
// Render database
154168
const table = createDatabase(tableProps);
155169
this.rootContainer.render(table);

src/StateManager.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import { DatabaseSettings } from "cdm/SettingsModel";
22
import { DatabaseView } from "DatabaseView";
3-
import { App, TFile } from 'obsidian';
3+
import { TFile } from 'obsidian';
44
export default class StateManager {
55
private onEmpty: () => void;
66
private getGlobalSettings: () => DatabaseSettings;
77
private viewSet: Set<DatabaseView> = new Set();
8-
9-
public app: App;
108
public file: TFile;
119
constructor(
12-
app: App,
1310
initialView: DatabaseView,
1411
initialData: string,
1512
onEmpty: () => void,
1613
getGlobalSettings: () => DatabaseSettings
1714
) {
18-
this.app = app;
1915
this.file = initialView.file;
2016
this.onEmpty = onEmpty;
2117
this.getGlobalSettings = getGlobalSettings;

src/cdm/CellModel.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
import { Cell, Column, Table } from "@tanstack/react-table";
2-
import { RowDataType } from "cdm/FolderModel";
3-
4-
export type CellProps = {
5-
cell: Cell<RowDataType, any>,
6-
column: Column<RowDataType, unknown>;
7-
row: any;
8-
table: Table<RowDataType>;
9-
[key: string]: any;
10-
}
11-
121
export type TableCellProps = {
132
row: any,
143
rowIndex: any

src/cdm/CheckboxModel.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { TableColumn, TableDataType } from "cdm/FolderModel";
2-
import { CellProps } from "cdm/CellModel";
31

2+
import { CellContext } from "@tanstack/react-table";
3+
import { Literal } from "obsidian-dataview";
4+
import { RowDataType } from "cdm/FolderModel";
45
export type CheckboxProps = {
5-
intialState: TableDataType;
6-
column: TableColumn;
7-
cellProperties: CellProps;
8-
};
6+
defaultCell: CellContext<RowDataType, Literal>;
7+
}

src/cdm/ComponentsModel.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
import NoteInfo from "services/NoteInfo";
2-
import { BaseComponentProps } from "cdm/DatabaseModel";
3-
import { CellProps } from "cdm/CellModel";
2+
import { CellContext } from "@tanstack/react-table";
3+
import { RowDataType } from "cdm/FolderModel";
4+
import { Literal } from "obsidian-dataview/lib/data-model/value";
45

56
export type RowSelectOption = {
67
backgroundColor: string,
78
label: string,
89
}
9-
export type PopperProps = {
10-
dispatch: (action: any) => void;
11-
row: any;
12-
columns: any;
13-
note: NoteInfo;
14-
} & BaseComponentProps;
1510

11+
export type PopperProps = {
12+
defaultCell: CellContext<RowDataType, Literal>;
13+
}
1614

1715
export type TagsProps = {
18-
dispatch: (action: any) => void;
19-
cellProperties: CellProps;
20-
columns: any;
21-
} & BaseComponentProps;
16+
defaultCell: CellContext<RowDataType, Literal>;
17+
}
2218

2319
export type CalendarProps = {
24-
cellProperties: CellProps;
25-
} & BaseComponentProps;
20+
defaultCell: CellContext<RowDataType, Literal>;
21+
}

src/cdm/DatabaseModel.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RowType } from "cdm/RowTypeModel"
22
import { LocalSettings } from "cdm/SettingsModel";
33
import { Literal } from "obsidian-dataview/lib/data-model/value";
4-
import { Column, TableOptions } from "@tanstack/react-table";
4+
import { Column, TableMeta, TableOptions } from "@tanstack/react-table";
55
import { BaseColumn, RowDataType, TableColumn, TableDataType } from "cdm/FolderModel";
66
import { RowSelectOption } from "cdm/ComponentsModel";
77

@@ -39,10 +39,6 @@ export type OptionSelect = {
3939
label: string;
4040
backgroundColor: string;
4141
}
42-
export type BaseComponentProps = {
43-
intialState: TableDataType;
44-
column: Column<RowDataType, unknown>;
45-
}
4642

4743
export type SortedType = {
4844
id: string;

src/cdm/FolderModel.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import NoteInfo from "services/NoteInfo";
66
import { TFile } from "obsidian";
77
import { Column, ColumnSort, Header, Table } from "@tanstack/react-table";
88
import { Literal } from "obsidian-dataview/lib/data-model/value";
9+
import { TableStateInterface } from "./TableStateInterface";
910

1011
export type Group = Parameter | Parameters | FolderModel | Models;
1112
type Parameter = {
@@ -71,18 +72,15 @@ export type RowDataType = {
7172
[key: string]: Literal | NoteInfo
7273
}
7374

74-
export type InitialState = {
75+
export type InitialType = {
7576
sortBy?: ColumnSort[],
7677
}
7778

7879
export type TableDataType = {
79-
columns: TableColumn[],
80-
shadowColumns: TableColumn[],
8180
skipReset: boolean,
8281
view: DatabaseView,
8382
stateManager: StateManager,
84-
dispatch?: Dispatch<any>,
85-
initialState?: InitialState,
83+
tableStore?: TableStateInterface
8684
}
8785

8886
export interface DatabaseHeaderProps {

src/cdm/HeaderActionModel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export type HeaderActionResponse = {
1111
}
1212
}
1313

14+
export type HeaderActionModel = {
15+
label: string;
16+
icon: React.ReactNode;
17+
onClick: (e: any) => void;
18+
};
1419
export interface HeaderAction {
1520
setNext(handler: HeaderAction): HeaderAction;
1621
handle(settingHandlerResponse: HeaderActionResponse): HeaderActionResponse;

src/cdm/HeaderModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ColumnOrderState, ColumnResizeMode, Header, Table } from "@tanstack/react-table";
1+
import { ColumnOrderState, Header, Table } from "@tanstack/react-table";
22
import { DatabaseHeaderProps, RowDataType, TableColumn } from "cdm/FolderModel";
33

44
export type HeaderMenuProps = {

0 commit comments

Comments
 (0)