File tree Expand file tree Collapse file tree 2 files changed +22
-8
lines changed
src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/DatabaseBlock Expand file tree Collapse file tree 2 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
11
11
12
12
import { AddButtonComponent } from './AddColumnButton' ;
13
13
import { AddRowButton } from './AddRowButton' ;
14
+ import { createNewRow } from './utils' ;
14
15
15
16
export const DatabaseGrid = ( {
16
17
documentId,
@@ -73,14 +74,11 @@ export const DatabaseGrid = ({
73
74
rowData1 . push ( row ) ;
74
75
}
75
76
76
- const addNewRow : Record < string , string > = { } ;
77
- for ( const [ key ] of filteredEntries ) {
78
- addNewRow [ key ] = '+ new row' ;
79
- }
80
- rowData1 . push ( addNewRow ) ;
81
-
82
77
setRowData ( rowData1 ) ;
83
78
79
+ const addNewRow = createNewRow ( '+ new row' , colDefs ?? [ ] ) ;
80
+ rowData1 . push ( addNewRow ) ;
81
+
84
82
const columnNames = Object . keys ( Object . fromEntries ( filteredEntries ) ) ;
85
83
const columns : ColDef [ ] = columnNames . map ( ( key ) => ( {
86
84
field : key ,
@@ -94,9 +92,8 @@ export const DatabaseGrid = ({
94
92
params : { values : params . data } ,
95
93
} ;
96
94
97
- if ( Object . values ( params . data ) [ 0 ] . includes ( 'new' ) ) {
95
+ if ( Object . values ( params . data ) [ 0 ] ? .includes ( 'new' ) ) {
98
96
return addRowButton ;
99
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
100
97
}
101
98
return undefined ;
102
99
}
Original file line number Diff line number Diff line change
1
+ import { ColDef } from 'ag-grid-community' ;
2
+
3
+ export const createNewRow = (
4
+ value : string | undefined ,
5
+ columns : ColDef [ ] | undefined ,
6
+ ) => {
7
+ const defaultValue = value ?? '' ;
8
+ const columnNames = columns ?. map ( ( col ) => col . field ) ;
9
+ const addNewRow : Record < string , string > = { } ;
10
+ columnNames ?. forEach ( ( name ) => {
11
+ if ( name !== undefined ) {
12
+ addNewRow [ name ] = defaultValue ;
13
+ }
14
+ } ) ;
15
+
16
+ return addNewRow ;
17
+ } ;
You can’t perform that action at this time.
0 commit comments