소스 검색

#291 lock management (#306)

Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
Fred Lefévère-Laoide 1 년 전
부모
커밋
e6716502d0
2개의 변경된 파일13개의 추가작업 그리고 4개의 파일을 삭제
  1. 12 4
      gui/src/DataNodeViewer.tsx
  2. 1 0
      src/taipy/gui_core/_context.py

+ 12 - 4
gui/src/DataNodeViewer.tsx

@@ -167,6 +167,8 @@ interface DataNodeViewerProps {
     onLock?: string;
     onLock?: string;
 }
 }
 
 
+const dataValueFocus = "data-value";
+
 const getDataValue = (value?: RowValue, dType?: string | null) => (dType == "date" ? new Date(value as string) : value);
 const getDataValue = (value?: RowValue, dType?: string | null) => (dType == "date" ? new Date(value as string) : value);
 
 
 const getValidDataNode = (datanode: DataNodeFull | DataNodeFull[]) =>
 const getValidDataNode = (datanode: DataNodeFull | DataNodeFull[]) =>
@@ -228,6 +230,7 @@ const DataNodeViewer = (props: DataNodeViewerProps) => {
             editLock.current = false;
             editLock.current = false;
             oldId.current = dn[DataNodeFullProps.id];
             oldId.current = dn[DataNodeFullProps.id];
         }
         }
+        editLock.current = dn ? dn[DataNodeFullProps.editInProgress]: false;
         return dn ? [...dn, true] : ["", "", "", "", "", "", "", "", -1, [], false, "", false];
         return dn ? [...dn, true] : ["", "", "", "", "", "", "", "", -1, [], false, "", false];
     }, [props.dataNode, props.defaultDataNode, oldId, id, dispatch, module, props.onLock]);
     }, [props.dataNode, props.defaultDataNode, oldId, id, dispatch, module, props.onLock]);
 
 
@@ -255,7 +258,11 @@ const DataNodeViewer = (props: DataNodeViewerProps) => {
     const onFocus = useCallback((e: MouseEvent<HTMLElement>) => {
     const onFocus = useCallback((e: MouseEvent<HTMLElement>) => {
         e.stopPropagation();
         e.stopPropagation();
         setFocusName(e.currentTarget.dataset.focus || "");
         setFocusName(e.currentTarget.dataset.focus || "");
-    }, []);
+        if (e.currentTarget.dataset.focus === dataValueFocus && !editLock.current) {
+            dispatch(createSendActionNameAction(id, module, props.onLock, { id: dnId, lock: true }));
+            editLock.current = true;
+        }
+    }, [dnId, props.onLock, id, dispatch, module]);
 
 
     // Label
     // Label
     const [label, setLabel] = useState<string>();
     const [label, setLabel] = useState<string>();
@@ -341,8 +348,9 @@ const DataNodeViewer = (props: DataNodeViewerProps) => {
             e.stopPropagation();
             e.stopPropagation();
             setDataValue(getDataValue(dtValue, dtType));
             setDataValue(getDataValue(dtValue, dtType));
             setFocusName("");
             setFocusName("");
+            dispatch(createSendActionNameAction(id, module, props.onLock, { id: dnId, lock: false }));
         },
         },
-        [dtValue, dtType, setDataValue, setFocusName]
+        [dtValue, dtType, dnId, id, dispatch, module, props.onLock, setDataValue, setFocusName]
     );
     );
     const onDataValueChange = useCallback((e: ChangeEvent<HTMLInputElement>) => setDataValue(e.target.value), []);
     const onDataValueChange = useCallback((e: ChangeEvent<HTMLInputElement>) => setDataValue(e.target.value), []);
     const onDataValueDateChange = useCallback((d: Date | null) => d && setDataValue(d), []);
     const onDataValueDateChange = useCallback((d: Date | null) => d && setDataValue(d), []);
@@ -672,14 +680,14 @@ const DataNodeViewer = (props: DataNodeViewerProps) => {
                                             container
                                             container
                                             xs={12}
                                             xs={12}
                                             justifyContent="space-between"
                                             justifyContent="space-between"
-                                            data-focus="data-value"
+                                            data-focus={dataValueFocus}
                                             onClick={onFocus}
                                             onClick={onFocus}
                                             sx={hoverSx}
                                             sx={hoverSx}
                                         >
                                         >
                                             {active &&
                                             {active &&
                                             dnEditInProgress &&
                                             dnEditInProgress &&
                                             dnEditorId === editorId &&
                                             dnEditorId === editorId &&
-                                            focusName === "data-value" ? (
+                                            focusName === dataValueFocus ? (
                                                 <>
                                                 <>
                                                     {typeof dtValue == "boolean" ? (
                                                     {typeof dtValue == "boolean" ? (
                                                         <>
                                                         <>

+ 1 - 0
src/taipy/gui_core/_context.py

@@ -656,6 +656,7 @@ class _GuiCoreContext(CoreEventConsumerBase):
                     else data.get("value"),
                     else data.get("value"),
                     comment=data.get(_GuiCoreContext.__PROP_ENTITY_COMMENT),
                     comment=data.get(_GuiCoreContext.__PROP_ENTITY_COMMENT),
                 )
                 )
+                entity.unlock_edit(self.gui._get_client_id())
                 state.assign(_GuiCoreContext._DATANODE_VIZ_ERROR_VAR, "")
                 state.assign(_GuiCoreContext._DATANODE_VIZ_ERROR_VAR, "")
             except Exception as e:
             except Exception as e:
                 state.assign(_GuiCoreContext._DATANODE_VIZ_ERROR_VAR, f"Error updating Datanode value. {e}")
                 state.assign(_GuiCoreContext._DATANODE_VIZ_ERROR_VAR, f"Error updating Datanode value. {e}")