11import { ActionTypes , DataTypes } from "helpers/Constants" ;
2- import React , { useLayoutEffect , useRef , useState } from "react" ;
2+ import React , { useEffect , useLayoutEffect , useRef , useState } from "react" ;
33import ContentEditable , { ContentEditableEvent } from "react-contenteditable" ;
44import { LOGGER } from "services/Logger" ;
55import { Cell } from "react-table" ;
@@ -28,6 +28,7 @@ function getFilePath(cellValue: string): string {
2828}
2929
3030export default function DefaultCell ( cellProperties : Cell ) {
31+ console . log ( "render cell" ) ;
3132 const dataDispatch = ( cellProperties as any ) . dataDispatch ;
3233 /** Initial state of cell */
3334 const initialValue = cellProperties . value ;
@@ -44,10 +45,20 @@ export default function DefaultCell(cellProperties: Cell) {
4445 } ) ;
4546 /** state for keeping the timeout to trigger the editior */
4647 const [ editNoteTimeout , setEditNoteTimeout ] = useState ( null ) ;
48+ const [ dirtyCell , setDirtyCell ] = useState ( false ) ;
4749 /** states for selector option */
4850 LOGGER . debug (
4951 `<=> Cell.rendering dataType: ${ dataType } . value: ${ contextValue . value } `
5052 ) ;
53+ // set contextValue when cell is loaded
54+ useEffect ( ( ) => {
55+ if ( ! dirtyCell && initialValue !== contextValue . value ) {
56+ setContextValue ( {
57+ value : initialValue ,
58+ update : false ,
59+ } ) ;
60+ }
61+ } , [ ] ) ;
5162
5263 const handleKeyDown = ( event : any ) => {
5364 if ( event . key === "Enter" ) {
@@ -62,6 +73,7 @@ export default function DefaultCell(cellProperties: Cell) {
6273 }
6374 // first update the input text as user type
6475 setContextValue ( { value : event . target . value , update : false } ) ;
76+ setDirtyCell ( true ) ;
6577 // initialize a setimeout by wrapping in our editNoteTimeout so that we can clear it out using clearTimeout
6678 setEditNoteTimeout (
6779 setTimeout ( ( ) => {
@@ -81,6 +93,7 @@ export default function DefaultCell(cellProperties: Cell) {
8193 row : cellProperties . row ,
8294 columnId : ( cellProperties . column as any ) . id ,
8395 } ) ;
96+ setDirtyCell ( false ) ;
8497 }
8598
8699 function getCellElement ( ) {
0 commit comments