1
- import { ColDef , ColSpanParams , themeQuartz } from 'ag-grid-community' ;
1
+ import { ColDef , ColSpanParams , ICellRendererParams } from 'ag-grid-community' ;
2
2
import { AgGridReact } from 'ag-grid-react' ;
3
- import { useEffect , useMemo , useRef , useState } from 'react' ;
3
+ import { useEffect , useRef , useState } from 'react' ;
4
4
5
5
import { Box } from '@/components' ;
6
6
import {
@@ -10,6 +10,7 @@ import {
10
10
} from '@/features/grist' ;
11
11
12
12
import { AddButtonComponent } from './AddColumnButton' ;
13
+ import { AddRowButton } from './AddRowButton' ;
13
14
14
15
export const DatabaseGrid = ( {
15
16
documentId,
@@ -84,6 +85,23 @@ export const DatabaseGrid = ({
84
85
const columns : ColDef [ ] = columnNames . map ( ( key ) => ( {
85
86
field : key ,
86
87
colSpan : newRowColSpan ,
88
+ cellRendererSelector : (
89
+ params : ICellRendererParams < Record < string , string > > ,
90
+ ) => {
91
+ if ( params . data ) {
92
+ const addRowButton = {
93
+ component : AddRowButton ,
94
+ params : { values : params . data } ,
95
+ } ;
96
+
97
+ if ( Object . values ( params . data ) [ 0 ] . includes ( 'new' ) ) {
98
+ return addRowButton ;
99
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
100
+ }
101
+ return undefined ;
102
+ }
103
+ return undefined ;
104
+ } ,
87
105
} ) ) ;
88
106
89
107
setColDefs ( columns . concat ( addColumnColDef ) ) ;
@@ -98,24 +116,16 @@ export const DatabaseGrid = ({
98
116
spanRows : true ,
99
117
} ;
100
118
101
- const theme = useMemo ( ( ) => {
102
- return themeQuartz . withParams ( {
103
- pinnedRowBorder : {
104
- width : 2 ,
105
- } ,
106
- } ) ;
107
- } , [ ] ) ;
108
-
109
119
const addColumn = ( columnName : string ) => {
110
120
const newColDef : ColDef = {
111
121
field : columnName ,
112
122
} ;
113
123
114
124
setColDefs ( ( prev ) => {
115
- const addColumn = prev . pop ( ) ;
125
+ const addColumn = prev ? .pop ( ) ;
116
126
117
127
return [
118
- ...prev ,
128
+ ...( prev ?? [ ] ) ,
119
129
newColDef ,
120
130
...( addColumn !== undefined ? [ addColumn ] : [ ] ) ,
121
131
] ;
@@ -141,7 +151,6 @@ export const DatabaseGrid = ({
141
151
defaultColDef = { defaultColDef }
142
152
domLayout = "autoHeight"
143
153
enableCellSpan = { true }
144
- theme = { theme }
145
154
/>
146
155
</ Box >
147
156
) ;
0 commit comments