diff --git a/airflow/ui/src/components/Clear/ClearAccordion.tsx b/airflow/ui/src/components/Clear/ClearAccordion.tsx index 74be262da7561..8c5bc7e918474 100644 --- a/airflow/ui/src/components/Clear/ClearAccordion.tsx +++ b/airflow/ui/src/components/Clear/ClearAccordion.tsx @@ -35,7 +35,7 @@ type Props = { // Table is in memory, pagination and sorting are disabled. // TODO: Make a front-end only unconnected table component with client side ordering and pagination const ClearAccordion = ({ affectedTasks, note, setNote }: Props) => ( - + Affected Tasks: {affectedTasks?.total_entries ?? 0} diff --git a/airflow/ui/src/components/Clear/Run/ClearRunButton.tsx b/airflow/ui/src/components/Clear/Run/ClearRunButton.tsx index 151e2f3bd9e92..30a3f2aa3dfef 100644 --- a/airflow/ui/src/components/Clear/Run/ClearRunButton.tsx +++ b/airflow/ui/src/components/Clear/Run/ClearRunButton.tsx @@ -17,12 +17,10 @@ * under the License. */ import { Box, useDisclosure } from "@chakra-ui/react"; -import { useState } from "react"; import { FiRefreshCw } from "react-icons/fi"; -import type { DAGRunResponse, TaskInstanceCollectionResponse } from "openapi/requests/types.gen"; +import type { DAGRunResponse } from "openapi/requests/types.gen"; import ActionButton from "src/components/ui/ActionButton"; -import { useClearDagRun } from "src/queries/useClearRun"; import ClearRunDialog from "./ClearRunDialog"; @@ -34,21 +32,6 @@ type Props = { const ClearRunButton = ({ dagRun, withText = true }: Props) => { const { onClose, onOpen, open } = useDisclosure(); - const [affectedTasks, setAffectedTasks] = useState({ - task_instances: [], - total_entries: 0, - }); - - const dagId = dagRun.dag_id; - const dagRunId = dagRun.dag_run_id; - - const { isPending, mutate } = useClearDagRun({ - dagId, - dagRunId, - onSuccessConfirm: onClose, - onSuccessDryRun: setAffectedTasks, - }); - return ( { withText={withText} /> - + ); }; diff --git a/airflow/ui/src/components/Clear/Run/ClearRunDialog.tsx b/airflow/ui/src/components/Clear/Run/ClearRunDialog.tsx index 4cb48669b5537..47e9b95b47daf 100644 --- a/airflow/ui/src/components/Clear/Run/ClearRunDialog.tsx +++ b/airflow/ui/src/components/Clear/Run/ClearRunDialog.tsx @@ -17,58 +17,59 @@ * under the License. */ import { Flex, Heading, VStack } from "@chakra-ui/react"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { FiRefreshCw } from "react-icons/fi"; -import type { - DAGRunClearBody, - DAGRunResponse, - TaskInstanceCollectionResponse, -} from "openapi/requests/types.gen"; +import type { DAGRunResponse } from "openapi/requests/types.gen"; import { Button, Dialog } from "src/components/ui"; import SegmentedControl from "src/components/ui/SegmentedControl"; +import { useClearDagRunDryRun } from "src/queries/useClearDagRunDryRun"; +import { useClearDagRun } from "src/queries/useClearRun"; import { usePatchDagRun } from "src/queries/usePatchDagRun"; import ClearAccordion from "../ClearAccordion"; type Props = { - readonly affectedTasks: TaskInstanceCollectionResponse; readonly dagRun: DAGRunResponse; - readonly isPending: boolean; - readonly mutate: ({ - dagId, - dagRunId, - requestBody, - }: { - dagId: string; - dagRunId: string; - requestBody: DAGRunClearBody; - }) => void; readonly onClose: () => void; readonly open: boolean; }; -const ClearRunDialog = ({ affectedTasks, dagRun, isPending, mutate, onClose, open }: Props) => { +const ClearRunDialog = ({ dagRun, onClose, open }: Props) => { const [selectedOptions, setSelectedOptions] = useState>([]); - const onlyFailed = selectedOptions.includes("onlyFailed"); - const dagId = dagRun.dag_id; const dagRunId = dagRun.dag_run_id; + const { isPending, mutate } = useClearDagRun({ + dagId, + dagRunId, + onSuccessConfirm: onClose, + }); + + const onlyFailed = selectedOptions.includes("onlyFailed"); + const [note, setNote] = useState(dagRun.note); const { isPending: isPendingPatchDagRun, mutate: mutatePatchDagRun } = usePatchDagRun({ dagId, dagRunId }); - useEffect(() => { - mutate({ - dagId, - dagRunId, - requestBody: { dry_run: true, only_failed: onlyFailed }, - }); - }, [dagId, dagRunId, mutate, onlyFailed]); + const { data } = useClearDagRunDryRun({ + dagId, + dagRunId, + options: { + enabled: open, + }, + requestBody: { + only_failed: onlyFailed, + }, + }); + + const affectedTasks = data ?? { + task_instances: [], + total_entries: 0, + }; return ( - + @@ -100,6 +101,7 @@ const ClearRunDialog = ({ affectedTasks, dagRun, isPending, mutate, onClose, ope