@@ -4,7 +4,7 @@ import { LocalSettings } from "cdm/SettingsModel";
44import { DataState } from "cdm/TableStateInterface" ;
55import { DatabaseView } from "DatabaseView" ;
66import { MetadataColumns , UpdateRowOptions } from "helpers/Constants" ;
7- import { updateRowFileProxy } from "helpers/VaultManagement" ;
7+ import { moveFile , updateRowFileProxy } from "helpers/VaultManagement" ;
88import { DateTime } from "luxon" ;
99import { Literal } from "obsidian-dataview" ;
1010import { DataviewService } from "services/DataviewService" ;
@@ -52,8 +52,43 @@ const useDataStore = (view: DatabaseView) => {
5252 } ;
5353 return { rows : [ ...state . rows , row ] }
5454 } ) ,
55- updateCell : ( rowIndex : number , column : TableColumn , value : Literal , columns : TableColumn [ ] , ddbbConfig : LocalSettings ) => set ( ( state ) => {
56- const rowTFile = state . rows [ rowIndex ] . __note__ . getFile ( ) ;
55+ updateCell : ( rowIndex : number , column : TableColumn , value : Literal , columns : TableColumn [ ] , ddbbConfig : LocalSettings , isMovingFile ?: boolean ) => set ( ( state ) => {
56+ const row = { ...state . rows [ rowIndex ] } ;
57+ row [ column . key ] = value ;
58+ console . log ( ddbbConfig . show_metadata_modified ) ;
59+ if ( ddbbConfig . show_metadata_modified ) {
60+ row [ MetadataColumns . MODIFIED ] = DateTime . now ( ) ;
61+ }
62+ let rowTFile = state . rows [ rowIndex ] . __note__ . getFile ( ) ;
63+ if ( isMovingFile && ddbbConfig . group_folder_column === column . id ) {
64+ const moveInfo = {
65+ file : rowTFile ,
66+ id : column . id ,
67+ value : value ,
68+ columns : columns ,
69+ ddbbConfig : ddbbConfig ,
70+ }
71+ moveFile ( `${ view . file . parent . path } /${ value } ` , moveInfo ) ;
72+ // Update row file
73+ row [
74+ MetadataColumns . FILE
75+ ] = `[[${ view . file . parent . path } /${ value } /${ rowTFile . name } |${ rowTFile . basename } ]]` ;
76+ // Check if action.value is a valid folder name
77+ const auxPath =
78+ value !== ""
79+ ? `${ view . file . parent . path } /${ value } /${ rowTFile . name } `
80+ : `${ view . file . parent . path } /${ rowTFile . name } ` ;
81+
82+ row . __note__ = new NoteInfo ( {
83+ ...row ,
84+ file : {
85+ path : auxPath ,
86+ } ,
87+ } ) ;
88+ // Update rows
89+ return { rows : [ ...state . rows . slice ( 0 , rowIndex ) , row , ...state . rows . slice ( rowIndex + 1 ) ] } ;
90+ }
91+
5792 // Save on disk
5893 updateRowFileProxy (
5994 rowTFile ,
@@ -64,10 +99,6 @@ const useDataStore = (view: DatabaseView) => {
6499 UpdateRowOptions . COLUMN_VALUE
65100 ) ;
66101
67- // Update row in memory
68- const row = { ...state . rows [ rowIndex ] } ;
69- row [ column . key ] = value ;
70- row [ MetadataColumns . MODIFIED ] = DateTime . now ( ) ;
71102 return { rows : [ ...state . rows . slice ( 0 , rowIndex ) , row , ...state . rows . slice ( rowIndex + 1 ) ] } ;
72103 }
73104 ) ,
@@ -97,4 +128,60 @@ const useDataStore = (view: DatabaseView) => {
97128 } ) ,
98129 ) ;
99130}
100- export default useDataStore ;
131+ export default useDataStore ;
132+
133+ /**
134+ *
135+ * dispatch({
136+ type: ActionTypes.UPDATE_OPTION_CELL,
137+ file: note.getFile(),
138+ key: tableColumn.key,
139+ value: option.label,
140+ row: row,
141+ columnId: column.id,
142+ state: table.options.meta,
143+ });
144+
145+
146+
147+ * case ActionTypes.UPDATE_OPTION_CELL:
148+ // check if this column is configured as a group folder
149+ if (dbconfig.group_folder_column === action.key) {
150+ moveFile(`${state.view.file.parent.path}/${action.value}`, action);
151+ action.row[
152+ MetadataColumns.FILE
153+ ] = `[[${state.view.file.parent.path}/${action.value}/${action.file.name}|${action.file.basename}]]`;
154+ // Check if action.value is a valid folder name
155+ const auxPath =
156+ action.value !== ""
157+ ? `${state.view.file.parent.path}/${action.value}/${action.file.name}`
158+ : `${state.view.file.parent.path}/${action.file.name}`;
159+
160+ action.row.original.__note__ = new NoteInfo({
161+ ...action.row,
162+ file: {
163+ path: auxPath,
164+ },
165+ });
166+ // Update original cell value
167+ const update_option_cell_index = state.view.columns.findIndex(
168+ (column) => column.id === action.columnId
169+ );
170+ const update_option_cell_column_key =
171+ state.view.columns[update_option_cell_index].key;
172+ return update(state, {
173+ view: {
174+ rows: {
175+ [action.row.index]: {
176+ $merge: {
177+ [MetadataColumns.FILE]: action.row[MetadataColumns.FILE],
178+ note: action.row.original.__note__,
179+ [update_option_cell_column_key]: action.value,
180+ },
181+ },
182+ },
183+ },
184+ });
185+ }
186+ break;
187+ */
0 commit comments