@@ -277,19 +277,45 @@ const CellRenderer: React.FC<CellRendererProps> = ({
277277 return editable ;
278278 } , [ context . path , column , node . data . hadronDocument , parentType ] ) ;
279279
280+ // Determine cell state
281+ let cellState :
282+ | typeof UNEDITABLE
283+ | typeof EMPTY
284+ | typeof INVALID
285+ | typeof DELETED
286+ | typeof ADDED
287+ | typeof EDITED
288+ | typeof VALID ;
289+
290+ if ( ! isEditable ) {
291+ cellState = UNEDITABLE ;
292+ } else if ( isEmpty || isDeleted ) {
293+ cellState = EMPTY ;
294+ } else if ( ! element . isCurrentTypeValid ( ) ) {
295+ cellState = INVALID ;
296+ } else if ( element . isRemoved ( ) ) {
297+ cellState = DELETED ;
298+ } else if ( element . isAdded ( ) ) {
299+ cellState = ADDED ;
300+ } else if ( element . isModified ( ) ) {
301+ cellState = EDITED ;
302+ } else {
303+ cellState = VALID ;
304+ }
305+
280306 const handleUndo = useCallback (
281307 ( event : React . MouseEvent ) => {
282308 event . stopPropagation ( ) ;
283309 if ( ! element ) {
284310 return ;
285311 }
286312 const oid : string = node . data . hadronDocument . getStringId ( ) ;
287- if ( element . isAdded ( ) ) {
313+ if ( cellState === ADDED ) {
288314 setIsDeleted ( true ) ;
289315 const isArray =
290316 ! element . parent ?. isRoot ( ) && element . parent ?. currentType === 'Array' ;
291317 elementRemoved ( String ( element . currentKey ) , oid , isArray ) ;
292- } else if ( element . isRemoved ( ) ) {
318+ } else if ( cellState === DELETED ) {
293319 elementAdded ( String ( element . currentKey ) , element . currentType , oid ) ;
294320 } else {
295321 elementTypeChanged ( String ( element . currentKey ) , element . type , oid ) ;
@@ -325,32 +351,6 @@ const CellRenderer: React.FC<CellRendererProps> = ({
325351 }
326352 } , [ node , api , column ] ) ;
327353
328- // Determine cell state
329- let cellState :
330- | typeof UNEDITABLE
331- | typeof EMPTY
332- | typeof INVALID
333- | typeof DELETED
334- | typeof ADDED
335- | typeof EDITED
336- | typeof VALID ;
337-
338- if ( ! isEditable ) {
339- cellState = UNEDITABLE ;
340- } else if ( isEmpty || isDeleted ) {
341- cellState = EMPTY ;
342- } else if ( ! element . isCurrentTypeValid ( ) ) {
343- cellState = INVALID ;
344- } else if ( element . isRemoved ( ) ) {
345- cellState = DELETED ;
346- } else if ( element . isAdded ( ) ) {
347- cellState = ADDED ;
348- } else if ( element . isModified ( ) ) {
349- cellState = EDITED ;
350- } else {
351- cellState = VALID ;
352- }
353-
354354 return (
355355 // `ag-grid` renders this component outside of the context chain
356356 // so we re-supply the dark mode theme here.
0 commit comments