pierrejeambrun commented on code in PR #35393:
URL: https://github.com/apache/airflow/pull/35393#discussion_r1405477319


##########
airflow/www/static/js/dag/details/dagRun/MarkRunAs.tsx:
##########
@@ -58,42 +65,115 @@ const MarkRunAs = ({ runId, state, ...otherProps }: Props) 
=> {
     markSuccess({ confirmed: true });
   };
 
+  useEffect(() => {
+    const storedSuccessValue = localStorage.getItem("doNotShowAgainSuccess");
+    const storedFailedValue = localStorage.getItem("doNotShowAgainFailed");
+
+    if (storedSuccessValue) {
+      setDoNotShowAgainSuccess(JSON.parse(storedSuccessValue));
+    }
+    if (storedFailedValue) {
+      setDoNotShowAgainFailed(JSON.parse(storedFailedValue));
+    }
+  }, []);
+
+  const confirmAction = () => {
+    localStorage.setItem(
+      "doNotShowAgainSuccess",
+      JSON.stringify(doNotShowAgainSuccess)
+    );
+    localStorage.setItem(
+      "doNotShowAgainFailed",
+      JSON.stringify(doNotShowAgainFailed)
+    );
+
+    if (confirmingAction === "failed") {
+      markAsFailed();
+    } else if (confirmingAction === "success") {
+      markAsSuccess();
+    }
+    setShowConfirmationModal(false);
+  };
+
   useKeysPress(keyboardShortcutIdentifier.dagMarkSuccess, () => {
-    if (state !== "success") markAsSuccess();
+    if (state !== "success") {
+      if (!doNotShowAgainSuccess) {
+        setConfirmingAction("success");
+        setShowConfirmationModal(true);
+      } else markAsSuccess();
+    }
   });
   useKeysPress(keyboardShortcutIdentifier.dagMarkFailed, () => {
-    if (state !== "failed") markAsFailed();
+    if (state !== "failed") {
+      if (!doNotShowAgainFailed) {
+        setConfirmingAction("failed");
+        setShowConfirmationModal(true);
+      } else markAsFailed();
+    }
   });
 
   const markLabel = "Manually set dag run state";
   return (
-    <Menu>
-      <MenuButton
-        as={Button}
-        colorScheme="blue"
-        transition="all 0.2s"
-        title={markLabel}
-        aria-label={markLabel}
-        disabled={!canEdit || isMarkFailedLoading || isMarkSuccessLoading}
-        {...otherProps}
-        mt={2}
+    <>
+      <Menu>
+        <MenuButton
+          as={Button}
+          colorScheme="blue"
+          transition="all 0.2s"
+          title={markLabel}
+          aria-label={markLabel}
+          disabled={!canEdit || isMarkFailedLoading || isMarkSuccessLoading}
+          {...otherProps}
+          mt={2}
+        >
+          <Flex>
+            Mark state as...
+            <MdArrowDropDown size="16px" />
+          </Flex>
+        </MenuButton>
+        <MenuList>
+          <MenuItem onClick={markAsFailed} isDisabled={state === "failed"}>

Review Comment:
   For consistency, I would prefer that marking as... via the button would also 
trigger the confirmation dialog.
   
   Right now, the dialog only shows up if the action is taken via keyboard 
shortcuts.



##########
airflow/www/static/js/dag/details/dagRun/MarkRunAs.tsx:
##########
@@ -58,42 +65,115 @@ const MarkRunAs = ({ runId, state, ...otherProps }: Props) 
=> {
     markSuccess({ confirmed: true });
   };
 
+  useEffect(() => {
+    const storedSuccessValue = localStorage.getItem("doNotShowAgainSuccess");
+    const storedFailedValue = localStorage.getItem("doNotShowAgainFailed");
+
+    if (storedSuccessValue) {
+      setDoNotShowAgainSuccess(JSON.parse(storedSuccessValue));
+    }
+    if (storedFailedValue) {
+      setDoNotShowAgainFailed(JSON.parse(storedFailedValue));
+    }
+  }, []);
+
+  const confirmAction = () => {
+    localStorage.setItem(
+      "doNotShowAgainSuccess",
+      JSON.stringify(doNotShowAgainSuccess)
+    );
+    localStorage.setItem(
+      "doNotShowAgainFailed",
+      JSON.stringify(doNotShowAgainFailed)
+    );
+
+    if (confirmingAction === "failed") {
+      markAsFailed();
+    } else if (confirmingAction === "success") {
+      markAsSuccess();
+    }
+    setShowConfirmationModal(false);
+  };
+
   useKeysPress(keyboardShortcutIdentifier.dagMarkSuccess, () => {
-    if (state !== "success") markAsSuccess();
+    if (state !== "success") {
+      if (!doNotShowAgainSuccess) {
+        setConfirmingAction("success");
+        setShowConfirmationModal(true);

Review Comment:
   When you have states that are bound to each other by some logic, I recommend 
using a useReducer. This way coupled logic between states get hidden behind a 
common action, and this would go into the reducer. 
   
   https://react.dev/reference/react/useReducer
   
   Action could for instance be `CONFIRM_SUCCESS`, `CONFIRM_FAILURE` etc. Then 
it would take care of switching all the appropriate states, and when you need 
it you can just dispatch the appropriate action.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to