@@ -4,7 +4,7 @@ import { LocalSettings } from "cdm/SettingsModel";
44import { DataState , TableActionResponse } from "cdm/TableStateInterface" ;
55import { DatabaseView } from "DatabaseView" ;
66import { SourceDataTypes } from "helpers/Constants" ;
7- import { resolve_tfolder } from "helpers/FileManagement" ;
7+ import { resolve_tfile , resolve_tfolder } from "helpers/FileManagement" ;
88import { DateTime } from "luxon" ;
99import { Link } from "obsidian-dataview" ;
1010import { VaultManagerDB } from "services/FileManagerService" ;
@@ -13,21 +13,22 @@ import { AbstractTableAction } from "stateManagement/AbstractTableAction";
1313
1414export 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 }
0 commit comments