@@ -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,23 +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- } ) ;
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+ } ;
134135 return update ( state , {
135136 skipReset : { $set : true } ,
136137 // Modify column visually with the new label
@@ -158,6 +159,14 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
158159 return row ;
159160 } ) ,
160161 } ,
162+ // Update view yaml state
163+ view : {
164+ diskConfig : {
165+ yaml : {
166+ $set : state . view . diskConfig . yaml ,
167+ } ,
168+ } ,
169+ } ,
161170 } ) ;
162171
163172 /**
@@ -256,12 +265,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
256265 key : action . columnInfo . name ,
257266 label : action . columnInfo . label ,
258267 position : action . columnInfo . position ,
259- config : {
260- isInline : false ,
261- media_height : 100 ,
262- media_width : 100 ,
263- enable_media_view : false ,
264- } ,
268+ config : DEFAULT_COLUMN_CONFIG ,
265269 } ;
266270 // Update configuration on disk
267271 state . view . diskConfig . addColumn ( action . columnInfo . name , newLeftColumn ) ;
@@ -285,6 +289,14 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
285289 ...state . columns . slice ( leftIndex , state . columns . length ) ,
286290 ] ,
287291 } ,
292+ // Update view yaml
293+ view : {
294+ diskConfig : {
295+ yaml : {
296+ $set : state . view . diskConfig . yaml ,
297+ } ,
298+ } ,
299+ } ,
288300 } ) ;
289301 /**
290302 * Add new column to the table to the right of the column with the given id
@@ -301,12 +313,7 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
301313 key : action . columnInfo . name ,
302314 label : action . columnInfo . label ,
303315 position : action . columnInfo . position ,
304- config : {
305- isInline : false ,
306- media_height : 100 ,
307- media_width : 100 ,
308- enable_media_view : false ,
309- } ,
316+ config : DEFAULT_COLUMN_CONFIG ,
310317 } ;
311318 // Update configuration on disk
312319 state . view . diskConfig . addColumn ( action . columnInfo . name , newRIghtColumn ) ;
@@ -331,6 +338,14 @@ export function databaseReducer(state: TableDataType, action: ActionType) {
331338 ...state . columns . slice ( rightIndex + 1 , state . columns . length ) ,
332339 ] ,
333340 } ,
341+ // Update view yaml
342+ view : {
343+ diskConfig : {
344+ yaml : {
345+ $set : state . view . diskConfig . yaml ,
346+ } ,
347+ } ,
348+ } ,
334349 } ) ;
335350 case ActionTypes . DELETE_COLUMN :
336351 const deleteIndex = state . columns . findIndex (
0 commit comments