@@ -3,6 +3,7 @@ import update from "immutability-helper";
33import {
44 ActionTypes ,
55 DataTypes ,
6+ DEFAULT_COLUMN_CONFIG ,
67 MetadataColumns ,
78 TableColumnsTemplate ,
89 UpdateRowOptions ,
@@ -27,9 +28,7 @@ import { Literal } from "obsidian-dataview/lib/data-model/value";
2728import { DateTime } from "luxon" ;
2829
2930export function databaseReducer ( state : TableDataType , action : ActionType ) {
30- LOGGER . debug (
31- `<=>databaseReducer action: ${ action . type } value: ${ action . value } `
32- ) ;
31+ LOGGER . debug ( `<=>databaseReducer action: ${ action . type } ` , action ) ;
3332 /** database configuration */
3433 const dbconfig = state . view . diskConfig . yaml . config ;
3534 // Check if action exists
@@ -114,28 +113,25 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
114113 ( column : any ) => column . id === action . columnId
115114 ) ;
116115 // Update configuration & row files on disk
117- state . view . diskConfig
118- . updateColumnKey ( action . columnId , action . newKey , action . label )
119- . then ( async ( ) => {
120- // Once the column is updated, update the rows in case the key is changed
121-
122- await Promise . all (
123- state . data . map ( async ( row : RowDataType ) => {
124- await updateRowFileProxy (
125- row . note . getFile ( ) ,
126- action . columnId ,
127- action . newKey ,
128- state ,
129- UpdateRowOptions . COLUMN_KEY
130- ) ;
131- } )
132- ) ;
133- } ) ;
134- // Update view yaml info
135- state . view . diskConfig . yaml . columns [ action . newKey ] =
136- state . view . diskConfig . yaml . columns [ action . columnId ] ;
137- delete state . view . diskConfig . yaml . columns [ action . columnId ] ;
138-
116+ state . view . diskConfig . updateColumnKey (
117+ action . columnId ,
118+ action . newKey ,
119+ action . label
120+ ) ;
121+ async ( ) => {
122+ // Update the rows in case the key is changed
123+ await Promise . all (
124+ state . data . map ( async ( row : RowDataType ) => {
125+ await updateRowFileProxy (
126+ row . note . getFile ( ) ,
127+ action . columnId ,
128+ action . newKey ,
129+ state ,
130+ UpdateRowOptions . COLUMN_KEY
131+ ) ;
132+ } )
133+ ) ;
134+ } ;
139135 return update ( state , {
140136 skipReset : { $set : true } ,
141137 // Modify column visually with the new label
@@ -167,9 +163,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
167163 view : {
168164 diskConfig : {
169165 yaml : {
170- columns : {
171- $set : state . view . diskConfig . yaml . columns ,
172- } ,
166+ $set : state . view . diskConfig . yaml ,
173167 } ,
174168 } ,
175169 } ,
@@ -271,12 +265,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
271265 key : action . columnInfo . name ,
272266 label : action . columnInfo . label ,
273267 position : action . columnInfo . position ,
274- config : {
275- isInline : false ,
276- media_height : 100 ,
277- media_width : 100 ,
278- enable_media_view : false ,
279- } ,
268+ config : DEFAULT_COLUMN_CONFIG ,
280269 } ;
281270 // Update configuration on disk
282271 state . view . diskConfig . addColumn ( action . columnInfo . name , newLeftColumn ) ;
@@ -324,12 +313,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
324313 key : action . columnInfo . name ,
325314 label : action . columnInfo . label ,
326315 position : action . columnInfo . position ,
327- config : {
328- isInline : false ,
329- media_height : 100 ,
330- media_width : 100 ,
331- enable_media_view : false ,
332- } ,
316+ config : DEFAULT_COLUMN_CONFIG ,
333317 } ;
334318 // Update configuration on disk
335319 state . view . diskConfig . addColumn ( action . columnInfo . name , newRIghtColumn ) ;
0 commit comments