@@ -31,16 +31,16 @@ export default function DataTableNode({ data} : {data:Data} ) { //this 'data' i
31
31
32
32
//split up the table into different parts based on how the data is structured. fetch
33
33
const tableName = tableData [ 0 ] ;
34
- let firstRow : string [ ] = [ ]
35
- let restRowsData : RowsOfData [ ] | [ ] = [ ]
36
- let secondaryFirstRow : string [ ] = [ ]
34
+ let firstRow : string [ ] = [ ] ;
35
+ let restRowsData : RowsOfData [ ] | [ ] = [ ] ;
36
+ let secondaryFirstRow : string [ ] = [ ] ;
37
37
let RowData :( RowsOfData [ ] ) = Object . values ( tableData [ 1 ] ) ;
38
38
39
39
40
40
//Used to grab the primary key and foreign keys column in the Table
41
41
let schemaName = schemaStore [ `public.${ tableName } ` ] ;
42
- let PK :( string | number | null ) = null
43
- let FK :( string | number | null ) = null
42
+ let PK :( string | number | null ) = null ;
43
+ let FK :( string | number | null ) = null ;
44
44
let pkVals = new Set ( ) ;
45
45
for ( let key in schemaName ) {
46
46
if ( schemaName [ key ] [ 'IsForeignKey' ] ) FK = schemaName [ key ] . field_name ;
@@ -104,13 +104,13 @@ export default function DataTableNode({ data} : {data:Data} ) { //this 'data' i
104
104
restRowsData = [ ...RowData ] ;
105
105
}
106
106
} else {
107
- firstRow = secondaryFirstRow
107
+ firstRow = secondaryFirstRow ;
108
108
}
109
109
110
110
111
111
//UseEffect set Table when the dataStore is changed after on Delete.
112
112
useEffect ( ( ) => {
113
- setTableData ( [ tableName , dataStore [ tableName ] ] )
113
+ setTableData ( [ tableName , dataStore [ tableName ] ] ) ;
114
114
} , [ dataStore ] ) ;
115
115
116
116
@@ -131,11 +131,11 @@ export default function DataTableNode({ data} : {data:Data} ) { //this 'data' i
131
131
// }
132
132
/////////////////////////////////////////////////////////////////////////
133
133
134
- const newDatastore = structuredClone ( dataStore )
134
+ const newDatastore = structuredClone ( dataStore ) ;
135
135
136
- restRowsData = restRowsData . slice ( 0 , index ) . concat ( restRowsData . slice ( index + 1 , restRowsData . length ) )
136
+ restRowsData = restRowsData . slice ( 0 , index ) . concat ( restRowsData . slice ( index + 1 , restRowsData . length ) ) ;
137
137
138
- newDatastore [ tableName ] = restRowsData
138
+ newDatastore [ tableName ] = restRowsData ;
139
139
setDataStore ( { ...newDatastore , [ id ] :restRowsData } ) ;
140
140
await fetch ( `/api/sql/${ dbCredentials . db_type } /deleteRow` , {
141
141
method : 'DELETE' ,
@@ -146,10 +146,32 @@ const newDatastore = structuredClone(dataStore)
146
146
} )
147
147
. then ( ( res ) => {
148
148
//console.log("deleting row info sent")
149
- return res
149
+ return res ;
150
150
} )
151
151
. catch ( ( err : ErrorEvent ) => { console . error ( 'deleting row error' , err ) } )
152
- } ;
152
+ } else {
153
+ const sendDeleteRequest = fetch ( `/api/sql/${ dbCredentials . db_type } /deleteRow` , {
154
+ method : 'DELETE' ,
155
+ headers : {
156
+ 'Content-Type' : 'application/json'
157
+ } ,
158
+ body : JSON . stringify ( { tableName : tableName , deletedRow : value } )
159
+ } )
160
+ . then ( ( res ) => {
161
+ //console.log("deleting row info sent")
162
+ return res ;
163
+ } )
164
+ . catch ( ( err : ErrorEvent ) => { console . error ( 'deleting row error' , err ) } )
165
+ }
166
+ ////////////////// Fetch path: /api/delete ///////////////////
167
+ // {
168
+ // tableName: name of table,
169
+ // primaryKey: primary key,
170
+ // value: corresponding value of the primary key
171
+ // }
172
+ ////////////////////////////////////////////
173
+ }
174
+
153
175
154
176
155
177
//cannot make handles for data table dynamic since size of each column can vary
0 commit comments