bbovenzi commented on code in PR #44850:
URL: https://github.com/apache/airflow/pull/44850#discussion_r1882863114


##########
airflow/ui/src/components/TriggerDag/TriggerDAGTextButton.tsx:
##########
@@ -38,13 +38,15 @@ const TriggerDAGIconButton: React.FC<Props> = ({ dag }) => {
         Trigger
       </Button>
 
-      <TriggerDAGModal
-        dagDisplayName={dag.dag_display_name}
-        dagId={dag.dag_id}
-        isPaused={dag.is_paused}
-        onClose={onClose}
-        open={open}
-      />
+      {open ? (

Review Comment:
   Why are we wrapping the modal here?



##########
airflow/ui/src/components/TriggerDag/TriggerDAGModal.tsx:
##########
@@ -41,33 +57,102 @@ const TriggerDAGModal: React.FC<TriggerDAGModalProps> = ({
   onClose,
   open,
 }) => {
-  const initialDagParams = useMemo(
-    () => ({
-      configJson: "{}",
-      dagId,
-      dataIntervalEnd: "",
-      dataIntervalStart: "",
-      notes: "",
-      runId: "",
-    }),
-    [dagId],
-  );
+  const { data, error } = useDagServiceGetDagDetails({ dagId });
 
-  const [dagParams, setDagParams] = useState<DagParams>(initialDagParams);
+  const transformedParams = data?.params
+    ? Object.fromEntries(
+        Object.entries(data.params).map(([key, param]) => [
+          key,
+          (param as { value: unknown }).value,
+        ]),
+      )
+    : {};
+
+  const initialConf = JSON.stringify(transformedParams, undefined, 2);
+
+  const [dagParams, setDagParams] = useState<DagParams>({
+    configJson: initialConf,
+    dagId,
+    dataIntervalEnd: "",
+    dataIntervalStart: "",
+    notes: "",
+    runId: "",
+  });
+
+  useEffect(() => {
+    const newConfigJson = Boolean(error) ? "{}" : initialConf; // Fallback to 
"{}" if there's an error
 
-  const handleTrigger = useCallback(
+    setDagParams((prevParams) => ({
+      ...prevParams,
+      configJson: newConfigJson,
+    }));
+  }, [initialConf, error]);
+
+  const queryClient = useQueryClient();
+  const onSuccess = async () => {
+    await queryClient.invalidateQueries({
+      queryKey: [useDagServiceGetDagsKey],
+    });
+
+    await queryClient.invalidateQueries({
+      queryKey: [useDagsServiceRecentDagRunsKey],
+    });
+
+    await queryClient.invalidateQueries({
+      queryKey: [useDagRunServiceGetDagRunsKey],
+    });
+  };
+  const { mutate } = useDagRunServiceTriggerDagRun({
+    onSuccess,
+  });
+
+  const onTrigger = useCallback(

Review Comment:
   I think we should probably move a lot of the mutation logic into a custom 
mutation under `/queries/useTrigger.ts` and then the component only worries 
about editing the form and not its side effects



##########
airflow/ui/src/components/TriggerDag/TriggerDAGModal.tsx:
##########
@@ -94,12 +180,14 @@ const TriggerDAGModal: React.FC<TriggerDAGModalProps> = ({
         <Dialog.CloseTrigger />
 
         <Dialog.Body>
-          <TriggerDAGForm
-            dagParams={dagParams}
-            onClose={onClose}
-            onTrigger={handleTrigger}
-            setDagParams={setDagParams}
-          />
+          {Boolean(error) ? undefined : (

Review Comment:
   Why would we want to hide the form if there is an error?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to