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

Commit 5d7b9b2

Browse files
committed
hotfix of addrow and import
1 parent cd42399 commit 5d7b9b2

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

src/cdm/TableStateInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface ConfigState {
3636
export interface DataState {
3737
rows: RowDataType[];
3838
actions: {
39-
addRow: (filename: string, columns: TableColumn[], ddbbConfig: LocalSettings) => void;
39+
addRow: (filename: string, columns: TableColumn[], ddbbConfig: LocalSettings) => Promise<void>;
4040
updateCell: (rowIndex: number, column: TableColumn, value: Literal, columns: TableColumn[], ddbbConfig: LocalSettings, isMovingFile?: boolean) => Promise<void>;
4141
parseDataOfColumn: (column: TableColumn, input: string, ddbbConfig: LocalSettings) => void;
4242
updateDataAfterLabelChange: (column: TableColumn, label: string, columns: TableColumn[], ddbbConfig: LocalSettings) => Promise<void>;

src/stateManagement/data/handlers/AddRowHandlerAction.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { LocalSettings } from "cdm/SettingsModel";
44
import { DataState, TableActionResponse } from "cdm/TableStateInterface";
55
import { DatabaseView } from "DatabaseView";
66
import { SourceDataTypes } from "helpers/Constants";
7-
import { resolve_tfolder } from "helpers/FileManagement";
7+
import { resolve_tfile, resolve_tfolder } from "helpers/FileManagement";
88
import { DateTime } from "luxon";
99
import { Link } from "obsidian-dataview";
1010
import { VaultManagerDB } from "services/FileManagerService";
@@ -13,21 +13,22 @@ import { AbstractTableAction } from "stateManagement/AbstractTableAction";
1313

1414
export default class AddRowlHandlerAction extends AbstractTableAction<DataState> {
1515
handle(tableActionResponse: TableActionResponse<DataState>): TableActionResponse<DataState> {
16-
const { view, set, implementation } = tableActionResponse;
17-
implementation.actions.addRow = (filename: string, columns: TableColumn[], ddbbConfig: LocalSettings) => set((state) => {
16+
const { view, set, get, implementation } = tableActionResponse;
17+
implementation.actions.addRow = async (filename: string, columns: TableColumn[], ddbbConfig: LocalSettings) => {
1818
const destination_folder = this.destination_folder(view, ddbbConfig);
1919
let trimedFilename = filename.replace(/\.[^/.]+$/, "").trim();
2020
let filepath = `${destination_folder}/${trimedFilename}.md`;
2121
// Validate possible duplicates
2222
let sufixOfDuplicate = 0;
23-
while (state.rows.find((row) => row.__note__.filepath === filepath)) {
23+
while (get().rows.find((row) => row.__note__.filepath === filepath)) {
2424
sufixOfDuplicate++;
2525
filepath = `${destination_folder}/${trimedFilename}-${sufixOfDuplicate}.md`;
2626
}
2727
if (sufixOfDuplicate > 0) {
2828
trimedFilename = `${trimedFilename}-${sufixOfDuplicate}`;
2929
filename = `${trimedFilename} copy(${sufixOfDuplicate})`;
3030
}
31+
3132
const rowRecord: RowDatabaseFields = { inline: {}, frontmatter: {} };
3233
columns
3334
.filter((column: TableColumn) => !column.isMetadata)
@@ -39,29 +40,48 @@ export default class AddRowlHandlerAction extends AbstractTableAction<DataState>
3940
}
4041
});
4142
// Add note to persist row
42-
VaultManagerDB.create_markdown_file(
43+
await VaultManagerDB.create_markdown_file(
4344
resolve_tfolder(destination_folder),
4445
trimedFilename,
4546
rowRecord,
4647
ddbbConfig
4748
);
49+
4850
const newNote = new NoteInfo({
4951
...rowRecord.frontmatter,
5052
...rowRecord.inline,
5153
file: {
5254
path: filepath,
5355
ctime: DateTime.now(),
5456
mtime: DateTime.now(),
55-
link: Link.file(filepath),
57+
link: {
58+
path: filepath,
59+
fileName: () => filename,
60+
type: "file",
61+
embed: false,
62+
equals: (link: Link) => link.path === filepath,
63+
toObject: () => ({ path: filepath }),
64+
withPath: null,
65+
withDisplay: null,
66+
withHeader: null,
67+
toEmbed: null,
68+
toFile: null,
69+
markdown: () => `[[${filepath}|${filename}]]`,
70+
fromEmbed: null,
71+
obsidianLink: () => `[[${filepath}|${filename}]]`,
72+
},
5673
tasks: [],
5774
inlinks: [],
5875
outlinks: [],
5976
},
6077
});
6178

6279
const row: RowDataType = newNote.getRowDataType(columns, ddbbConfig);
63-
return { rows: [...state.rows, row] }
64-
});
80+
set((state) => {
81+
82+
return { rows: [...state.rows, row] }
83+
})
84+
};
6585
tableActionResponse.implementation = implementation;
6686
return this.goNext(tableActionResponse);
6787
}

src/stateManagement/data/handlers/SaveDataFromFileHandlerAction.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,22 @@ export default class SaveDataFromFileHandlerAction extends AbstractTableAction<D
8686
path: filepath,
8787
ctime: DateTime.now(),
8888
mtime: DateTime.now(),
89-
link: Link.file(filepath),
89+
link: {
90+
path: filepath,
91+
fileName: () => filename,
92+
type: "file",
93+
embed: false,
94+
equals: (link: Link) => link.path === filepath,
95+
toObject: () => ({ path: filepath }),
96+
withPath: null,
97+
withDisplay: null,
98+
withHeader: null,
99+
toEmbed: null,
100+
toFile: null,
101+
markdown: () => `[[${filepath}|${filename}]]`,
102+
fromEmbed: null,
103+
obsidianLink: () => `[[${filepath}|${filename}]]`,
104+
},
90105
tasks: [],
91106
inlinks: [],
92107
outlinks: [],

0 commit comments

Comments
 (0)