mirror of
https://github.com/supabase/supabase.git
synced 2026-06-08 18:47:20 +08:00
fix: revert changes when the value is the same as old (#44196)
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Revert changes when the value is the same as the old value --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import { isEqual } from 'lodash'
|
||||
|
||||
import { isPendingAddRow } from '../types'
|
||||
import { generateTableChangeKey, rowMatchesIdentifiers } from './queueOperationUtils'
|
||||
import { tryParseJson } from '@/lib/helpers'
|
||||
import {
|
||||
type NewDeleteRowOperation,
|
||||
type NewEditCellContentOperation,
|
||||
isDeleteRowOperation,
|
||||
isEditCellContentOperation,
|
||||
NewQueuedOperation,
|
||||
QueuedOperation,
|
||||
QueuedOperationType,
|
||||
isDeleteRowOperation,
|
||||
isEditCellContentOperation,
|
||||
type NewDeleteRowOperation,
|
||||
type NewEditCellContentOperation,
|
||||
} from '@/state/table-editor-operation-queue.types'
|
||||
|
||||
export type DeleteConflictResult =
|
||||
@@ -165,6 +168,17 @@ export function upsertOperation(
|
||||
existingOp.type === QueuedOperationType.EDIT_CELL_CONTENT
|
||||
) {
|
||||
queuedOperation.payload.oldValue = existingOp.payload.oldValue
|
||||
|
||||
const { oldValue, newValue } = queuedOperation.payload
|
||||
// [Joshen] These comparisons by data type are because of how the table editor renders the values
|
||||
if (
|
||||
(typeof oldValue === 'number' && Number(oldValue) === Number(newValue)) ||
|
||||
(typeof newValue === 'object' && isEqual(tryParseJson(oldValue), newValue)) ||
|
||||
oldValue === newValue
|
||||
) {
|
||||
updatedOperations.splice(existingOpIndex, 1)
|
||||
return { operations: updatedOperations }
|
||||
}
|
||||
}
|
||||
|
||||
updatedOperations[existingOpIndex] = queuedOperation
|
||||
|
||||
Reference in New Issue
Block a user