@@ -301,6 +301,10 @@ func (table *ResultsTable) AppendNewRow(cells []models.CellValue, index int, UUI
301301 for i , cell := range cells {
302302 tableCell := tview .NewTableCell (cell .Value .(string ))
303303 tableCell .SetExpansion (1 )
304+ // Appended rows have a reference to the row UUID so we can identify them later
305+ // Also, rows that have columns marked to be UPDATED will have a reference to the type of the new value (NULL, EMPTY, DEFAULT)
306+ // So, the cell reference will be used to determine if the row/column is an inserted row or if it's an UPDATED row
307+ // there might be a better way to do this, but it works for now
304308 tableCell .SetReference (UUID )
305309 tableCell .SetTextColor (app .Styles .PrimaryTextColor )
306310 tableCell .SetBackgroundColor (tcell .ColorDarkGreen )
@@ -342,6 +346,7 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
342346 case commands .RecordsMenu :
343347 table .Menu .SetSelectedOption (1 )
344348 table .UpdateRows (table .GetRecords ())
349+ table .colorChangedCells ()
345350 table .AddInsertedRows ()
346351 case commands .ColumnsMenu :
347352 table .Menu .SetSelectedOption (2 )
@@ -415,17 +420,8 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
415420 }
416421 } else if command == commands .Delete {
417422 if table .Menu .GetSelectedOption () == 1 {
418- isAnInsertedRow := false
419- indexOfInsertedRow := - 1
420423
421- for i , insertedRow := range * table .state .listOfDBChanges {
422- cellReference := table .GetCell (selectedRowIndex , 0 ).GetReference ()
423-
424- if cellReference != nil && insertedRow .PrimaryKeyInfo [0 ].Value == cellReference {
425- isAnInsertedRow = true
426- indexOfInsertedRow = i
427- }
428- }
424+ isAnInsertedRow , indexOfInsertedRow := table .isAnInsertedRow (selectedRowIndex )
429425
430426 if isAnInsertedRow {
431427 * table .state .listOfDBChanges = append ((* table .state .listOfDBChanges )[:indexOfInsertedRow ], (* table .state .listOfDBChanges )[indexOfInsertedRow + 1 :]... )
@@ -438,7 +434,7 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
438434 }
439435 }
440436 } else {
441- table .AppendNewChange (models .DMLDeleteType , selectedRowIndex , - 1 , models.CellValue {})
437+ table .AppendNewChange (models .DMLDeleteType , selectedRowIndex , - 1 , models.CellValue {TableColumnIndex : - 1 , TableRowIndex : selectedRowIndex })
442438 }
443439
444440 }
@@ -749,6 +745,7 @@ func (table *ResultsTable) GetPrimaryKeyColumnNames() []string {
749745func (table * ResultsTable ) SetRecords (rows [][]string ) {
750746 table .state .records = rows
751747 table .UpdateRows (rows )
748+ table .colorChangedCells ()
752749}
753750
754751func (table * ResultsTable ) SetColumns (columns [][]string ) {
@@ -1048,11 +1045,11 @@ func (table *ResultsTable) AppendNewChange(changeType models.DMLType, rowIndex i
10481045 dmlChangeAlreadyExists := false
10491046
10501047 // If the column has a reference, it means it's an inserted rowIndex
1051- // These is maybe a better way to detect it is an inserted row
1048+ // There is maybe a better way to detect it is an inserted row
10521049 tableCell := table .GetCell (rowIndex , colIndex )
10531050 tableCellReference := tableCell .GetReference ()
10541051
1055- isAnInsertedRow := tableCellReference != nil && tableCellReference .( string ) != "NULL&" && tableCellReference .( string ) != "EMPTY&" && tableCellReference .( string ) != "DEFAULT&"
1052+ isAnInsertedRow , _ := table . isAnInsertedRow ( rowIndex )
10561053
10571054 if isAnInsertedRow {
10581055 table .MutateInsertedRowCell (tableCellReference .(string ), value )
@@ -1375,3 +1372,37 @@ func (table *ResultsTable) UpdateSidebar() {
13751372
13761373 }
13771374}
1375+
1376+ func (table * ResultsTable ) isAnInsertedRow (rowIndex int ) (isAnInsertedRow bool , DBChangeIndex int ) {
1377+ for i , dmlChange := range * table .state .listOfDBChanges {
1378+ for _ , value := range dmlChange .Values {
1379+ if value .TableRowIndex != rowIndex {
1380+ continue
1381+ }
1382+ cellReference := table .GetCell (rowIndex , 0 ).GetReference ()
1383+ if cellReference == nil {
1384+ break
1385+ }
1386+ switch cellReference .(string ) {
1387+ case "NULL&" , "EMPTY&" , "DEFAULT&" :
1388+ default :
1389+ return true , i
1390+ }
1391+ break
1392+ }
1393+ }
1394+ return false , - 1
1395+ }
1396+
1397+ func (table * ResultsTable ) colorChangedCells () {
1398+ for _ , dmlChange := range * table .state .listOfDBChanges {
1399+ switch dmlChange .Type {
1400+ case models .DMLDeleteType :
1401+ table .SetRowColor (dmlChange .Values [0 ].TableRowIndex , colorTableDelete )
1402+ case models .DMLUpdateType :
1403+ for _ , value := range dmlChange .Values {
1404+ table .SetCellColor (value .TableRowIndex , value .TableColumnIndex , colorTableChange )
1405+ }
1406+ }
1407+ }
1408+ }
0 commit comments