@@ -10,73 +10,79 @@ import { AbstractTableAction } from "stateManagement/AbstractTableAction";
1010
1111export default class UpdateCellHandlerAction extends AbstractTableAction < DataState > {
1212 handle ( tableActionResponse : TableActionResponse < DataState > ) : TableActionResponse < DataState > {
13- const { view, set, implementation } = tableActionResponse ;
14- implementation . actions . updateCell = (
13+ const { view, set, get , implementation } = tableActionResponse ;
14+ implementation . actions . updateCell = async (
1515 rowIndex : number ,
1616 column : TableColumn ,
1717 value : Literal ,
1818 columns : TableColumn [ ] ,
1919 ddbbConfig : LocalSettings ,
20- isMovingFile ?: boolean ) => set ( ( state ) => {
21- const modifiedRow = state . rows [ rowIndex ] ;
22- let rowTFile = modifiedRow . __note__ . getFile ( ) ;
20+ isMovingFile ?: boolean ) => {
21+ const modifiedRow = get ( ) . rows [ rowIndex ] ;
22+ let rowTFile = modifiedRow . __note__ . getFile ( ) ;
2323
24- // Update the row on memory
25- modifiedRow [ column . key ] = value ;
24+ // Update the row on memory
25+ modifiedRow [ column . key ] = value ;
2626
27- // Row Rules
28- if ( ddbbConfig . show_metadata_modified ) {
29- modifiedRow [ MetadataColumns . MODIFIED ] = DateTime . now ( ) ;
30- }
31-
32- // Update the row on disk
33- if ( isMovingFile && ddbbConfig . group_folder_column === column . id ) {
27+ // Row Rules
28+ if ( ddbbConfig . show_metadata_modified ) {
29+ modifiedRow [ MetadataColumns . MODIFIED ] = DateTime . now ( ) ;
30+ }
31+ // Update the row on disk
32+ if ( isMovingFile && ddbbConfig . group_folder_column === column . id ) {
3433
35- const moveInfo = {
36- file : rowTFile ,
37- id : column . id ,
38- value : value ,
39- columns : columns ,
40- ddbbConfig : ddbbConfig ,
41- }
42- moveFile ( `${ view . file . parent . path } /${ value } ` , moveInfo ) ;
43- // Update row file
44- modifiedRow [
45- MetadataColumns . FILE
46- ] = `[[${ view . file . parent . path } /${ value } /${ rowTFile . name } |${ rowTFile . basename } ]]` ;
47- // Check if action.value is a valid folder name
48- const auxPath =
49- value !== ""
50- ? `${ view . file . parent . path } /${ value } /${ rowTFile . name } `
51- : `${ view . file . parent . path } /${ rowTFile . name } ` ;
34+ const moveInfo = {
35+ file : rowTFile ,
36+ id : column . id ,
37+ value : value ,
38+ columns : columns ,
39+ ddbbConfig : ddbbConfig ,
40+ }
41+ await moveFile ( `${ view . file . parent . path } /${ value } ` , moveInfo ) ;
42+ // Update row file
43+ modifiedRow [
44+ MetadataColumns . FILE
45+ ] = `[[${ view . file . parent . path } /${ value } /${ rowTFile . name } |${ rowTFile . basename } ]]` ;
46+ // Check if action.value is a valid folder name
47+ const auxPath =
48+ value !== ""
49+ ? `${ view . file . parent . path } /${ value } /${ rowTFile . name } `
50+ : `${ view . file . parent . path } /${ rowTFile . name } ` ;
5251
53- const recordRow : Record < string , Literal > = { } ;
54- Object . entries ( modifiedRow ) . forEach ( ( [ key , value ] ) => {
55- recordRow [ key ] = value as Literal ;
56- } ) ;
52+ const recordRow : Record < string , Literal > = { } ;
53+ Object . entries ( modifiedRow ) . forEach ( ( [ key , value ] ) => {
54+ recordRow [ key ] = value as Literal ;
55+ } ) ;
5756
58- modifiedRow . __note__ = new NoteInfo ( {
59- ...recordRow ,
60- file : {
61- path : auxPath ,
62- } ,
63- } ) ;
57+ modifiedRow . __note__ = new NoteInfo ( {
58+ ...recordRow ,
59+ file : {
60+ path : auxPath ,
61+ } ,
62+ } ) ;
6463
65- } else {
66- // Save on disk
67- updateRowFileProxy (
68- rowTFile ,
69- column . id ,
70- value ,
71- columns ,
72- ddbbConfig ,
73- UpdateRowOptions . COLUMN_VALUE
74- ) ;
75- }
76- // Update rows without re render
77- state . rows [ rowIndex ] = modifiedRow ;
78- return { rows : state . rows } ;
79- } ) ;
64+ } else {
65+ // Save on disk
66+ await updateRowFileProxy (
67+ rowTFile ,
68+ column . id ,
69+ value ,
70+ columns ,
71+ ddbbConfig ,
72+ UpdateRowOptions . COLUMN_VALUE
73+ ) ;
74+ }
75+ set ( ( state ) => {
76+ // Save on memory
77+ return {
78+ rows : [
79+ ...state . rows . slice ( 0 , rowIndex ) ,
80+ modifiedRow ,
81+ ...state . rows . slice ( rowIndex + 1 ) ,
82+ ]
83+ } ;
84+ } )
85+ } ;
8086 tableActionResponse . implementation = implementation ;
8187 return this . goNext ( tableActionResponse ) ;
8288 }
0 commit comments