This is an automated email from the ASF dual-hosted git repository.
pierrejeambrun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 1adbca5643f AIP-38 Mark TI as success/failed (#46138)
1adbca5643f is described below
commit 1adbca5643f30662e5d90d7207d8e76f975af7ca
Author: Pierre Jeambrun <[email protected]>
AuthorDate: Tue Jan 28 17:44:21 2025 +0100
AIP-38 Mark TI as success/failed (#46138)
* AIP-38 Add mark TI as success/failed
* Refactor Accordion
* Update following code review
* Update menue style
---
.../components/ActionAccordion/ActionAccordion.tsx | 103 +++++++++++++++++++++
.../ui/src/components/ActionAccordion/columns.tsx | 65 +++++++++++++
.../{MarkAs => ActionAccordion}/index.tsx | 2 +-
airflow/ui/src/components/Clear/ClearAccordion.tsx | 101 --------------------
.../ui/src/components/Clear/Run/ClearRunDialog.tsx | 5 +-
.../Clear/TaskInstance/ClearTaskInstanceDialog.tsx | 5 +-
.../ui/src/components/MarkAs/MarkAsAccordion.tsx | 72 --------------
.../src/components/MarkAs/Run/MarkRunAsButton.tsx | 9 +-
.../src/components/MarkAs/Run/MarkRunAsDialog.tsx | 7 +-
.../MarkTaskInstanceAsButton.tsx} | 28 +++---
.../TaskInstance/MarkTaskInstanceAsDialog.tsx} | 69 ++++++--------
.../components/MarkAs/{ => TaskInstance}/index.tsx | 2 +-
airflow/ui/src/components/MarkAs/index.tsx | 1 +
.../src/components/MarkAs/{index.tsx => utils.ts} | 3 +-
airflow/ui/src/pages/Run/TaskInstances.tsx | 2 +
airflow/ui/src/pages/TaskInstance/Header.tsx | 2 +
airflow/ui/src/queries/usePatchTaskInstance.ts | 10 +-
.../ui/src/queries/usePatchTaskInstanceDryRun.ts | 63 +++++++++++++
18 files changed, 301 insertions(+), 248 deletions(-)
diff --git a/airflow/ui/src/components/ActionAccordion/ActionAccordion.tsx
b/airflow/ui/src/components/ActionAccordion/ActionAccordion.tsx
new file mode 100644
index 00000000000..3995b789308
--- /dev/null
+++ b/airflow/ui/src/components/ActionAccordion/ActionAccordion.tsx
@@ -0,0 +1,103 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { Box, Editable, Text, VStack } from "@chakra-ui/react";
+import type { ChangeEvent } from "react";
+
+import type { DAGRunResponse, TaskInstanceCollectionResponse } from
"openapi/requests/types.gen";
+import ReactMarkdown from "src/components/ReactMarkdown";
+import { Accordion } from "src/components/ui";
+
+import { DataTable } from "../DataTable";
+import { columns } from "./columns";
+
+type Props = {
+ readonly affectedTasks?: TaskInstanceCollectionResponse;
+ readonly note: DAGRunResponse["note"];
+ readonly setNote: (value: string) => void;
+};
+
+// 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 ActionAccordion = ({ affectedTasks, note, setNote }: Props) => {
+ const showTaskSection = affectedTasks !== undefined;
+
+ return (
+ <Accordion.Root
+ collapsible
+ defaultValue={showTaskSection ? ["tasks"] : ["note"]}
+ multiple={false}
+ variant="enclosed"
+ >
+ {showTaskSection ? (
+ <Accordion.Item key="tasks" value="tasks">
+ <Accordion.ItemTrigger>
+ <Text fontWeight="bold">Affected Tasks:
{affectedTasks.total_entries}</Text>
+ </Accordion.ItemTrigger>
+ <Accordion.ItemContent>
+ <Box maxH="400px" overflowY="scroll">
+ <DataTable
+ columns={columns}
+ data={affectedTasks.task_instances}
+ displayMode="table"
+ modelName="Task Instance"
+ total={affectedTasks.total_entries}
+ />
+ </Box>
+ </Accordion.ItemContent>
+ </Accordion.Item>
+ ) : undefined}
+ <Accordion.Item key="note" value="note">
+ <Accordion.ItemTrigger>
+ <Text fontWeight="bold">Note</Text>
+ </Accordion.ItemTrigger>
+ <Accordion.ItemContent>
+ <Editable.Root
+ onChange={(event: ChangeEvent<HTMLInputElement>) =>
setNote(event.target.value)}
+ value={note ?? ""}
+ >
+ <Editable.Preview
+ _hover={{ backgroundColor: "transparent" }}
+ alignItems="flex-start"
+ as={VStack}
+ gap="0"
+ height="200px"
+ overflowY="auto"
+ width="100%"
+ >
+ {Boolean(note) ? (
+ <ReactMarkdown>{note}</ReactMarkdown>
+ ) : (
+ <Text color="fg.subtle">Add a note...</Text>
+ )}
+ </Editable.Preview>
+ <Editable.Textarea
+ data-testid="notes-input"
+ height="200px"
+ overflowY="auto"
+ placeholder="Add a note..."
+ resize="none"
+ />
+ </Editable.Root>
+ </Accordion.ItemContent>
+ </Accordion.Item>
+ </Accordion.Root>
+ );
+};
+
+export default ActionAccordion;
diff --git a/airflow/ui/src/components/ActionAccordion/columns.tsx
b/airflow/ui/src/components/ActionAccordion/columns.tsx
new file mode 100644
index 00000000000..95aeb66d4f7
--- /dev/null
+++ b/airflow/ui/src/components/ActionAccordion/columns.tsx
@@ -0,0 +1,65 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { Link } from "@chakra-ui/react";
+import type { ColumnDef } from "@tanstack/react-table";
+import { Link as RouterLink } from "react-router-dom";
+
+import type { TaskInstanceResponse } from "openapi/requests/types.gen";
+import { StateBadge } from "src/components/StateBadge";
+import { Tooltip } from "src/components/ui";
+import { getTaskInstanceLink } from "src/utils/links";
+import { trimText } from "src/utils/trimTextFn";
+
+export const columns: Array<ColumnDef<TaskInstanceResponse>> = [
+ {
+ accessorKey: "task_display_name",
+ cell: ({ row: { original } }) => (
+ <Tooltip content={original.task_display_name}>
+ <Link asChild color="fg.info" fontWeight="bold" maxWidth="200px"
overflow="hidden">
+ <RouterLink to={getTaskInstanceLink(original)}>
+ {trimText(original.task_display_name, 25).trimmedText}
+ </RouterLink>
+ </Link>
+ </Tooltip>
+ ),
+ enableSorting: false,
+ header: "Task ID",
+ },
+ {
+ accessorKey: "state",
+ cell: ({
+ row: {
+ original: { state },
+ },
+ }) => <StateBadge state={state}>{state}</StateBadge>,
+ enableSorting: false,
+ header: () => "State",
+ },
+ {
+ accessorFn: (row) => row.rendered_map_index ?? row.map_index,
+ enableSorting: false,
+ header: "Map Index",
+ },
+
+ {
+ accessorKey: "dag_run_id",
+ enableSorting: false,
+ header: "Run Id",
+ },
+];
diff --git a/airflow/ui/src/components/MarkAs/index.tsx
b/airflow/ui/src/components/ActionAccordion/index.tsx
similarity index 92%
copy from airflow/ui/src/components/MarkAs/index.tsx
copy to airflow/ui/src/components/ActionAccordion/index.tsx
index 7aab3b38b57..fa6ffe6251b 100644
--- a/airflow/ui/src/components/MarkAs/index.tsx
+++ b/airflow/ui/src/components/ActionAccordion/index.tsx
@@ -17,4 +17,4 @@
* under the License.
*/
-export { default as MarkRunAsButton } from "./Run";
+export { default as ActionAccordion } from "./ActionAccordion";
diff --git a/airflow/ui/src/components/Clear/ClearAccordion.tsx
b/airflow/ui/src/components/Clear/ClearAccordion.tsx
deleted file mode 100644
index 8c5bc7e9184..00000000000
--- a/airflow/ui/src/components/Clear/ClearAccordion.tsx
+++ /dev/null
@@ -1,101 +0,0 @@
-/*!
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-import { Box, Editable, Text, VStack } from "@chakra-ui/react";
-import type { ChangeEvent } from "react";
-
-import type { DAGRunResponse, TaskInstanceCollectionResponse } from
"openapi/requests/types.gen";
-import { DataTable } from "src/components/DataTable";
-import ReactMarkdown from "src/components/ReactMarkdown";
-import { Accordion } from "src/components/ui";
-
-import { columns } from "./columns";
-
-type Props = {
- readonly affectedTasks?: TaskInstanceCollectionResponse;
- readonly note: DAGRunResponse["note"];
- readonly setNote: (value: string) => void;
-};
-
-// 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) => (
- <Accordion.Root collapsible defaultValue={["tasks"]} multiple={false}
variant="enclosed">
- <Accordion.Item key="tasks" value="tasks">
- <Accordion.ItemTrigger>
- <Text fontWeight="bold">Affected Tasks: {affectedTasks?.total_entries
?? 0}</Text>
- </Accordion.ItemTrigger>
- <Accordion.ItemContent>
- <Box maxH="400px" overflowY="scroll">
- <DataTable
- columns={columns}
- data={affectedTasks?.task_instances ?? []}
- displayMode="table"
- initialState={{
- pagination: {
- pageIndex: 0,
- pageSize: affectedTasks?.total_entries ?? 0,
- },
- sorting: [],
- }}
- modelName="Task Instance"
- total={affectedTasks?.total_entries}
- />
- </Box>
- </Accordion.ItemContent>
- </Accordion.Item>
- <Accordion.Item key="note" value="note">
- <Accordion.ItemTrigger>
- <Text fontWeight="bold">Note</Text>
- </Accordion.ItemTrigger>
- <Accordion.ItemContent>
- <Editable.Root
- onChange={(event: ChangeEvent<HTMLInputElement>) =>
setNote(event.target.value)}
- value={note ?? ""}
- >
- <Editable.Preview
- _hover={{ backgroundColor: "transparent" }}
- alignItems="flex-start"
- as={VStack}
- gap="0"
- height="200px"
- overflowY="auto"
- width="100%"
- >
- {Boolean(note) ? (
- <ReactMarkdown>{note}</ReactMarkdown>
- ) : (
- <Text color="gray" opacity={0.6}>
- Add a note...
- </Text>
- )}
- </Editable.Preview>
- <Editable.Textarea
- data-testid="notes-input"
- height="200px"
- overflowY="auto"
- placeholder="Add a note..."
- resize="none"
- />
- </Editable.Root>
- </Accordion.ItemContent>
- </Accordion.Item>
- </Accordion.Root>
-);
-
-export default ClearAccordion;
diff --git a/airflow/ui/src/components/Clear/Run/ClearRunDialog.tsx
b/airflow/ui/src/components/Clear/Run/ClearRunDialog.tsx
index 47e9b95b47d..9e99491aa28 100644
--- a/airflow/ui/src/components/Clear/Run/ClearRunDialog.tsx
+++ b/airflow/ui/src/components/Clear/Run/ClearRunDialog.tsx
@@ -21,14 +21,13 @@ import { useState } from "react";
import { FiRefreshCw } from "react-icons/fi";
import type { DAGRunResponse } from "openapi/requests/types.gen";
+import { ActionAccordion } from "src/components/ActionAccordion";
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 dagRun: DAGRunResponse;
readonly onClose: () => void;
@@ -97,7 +96,7 @@ const ClearRunDialog = ({ dagRun, onClose, open }: Props) => {
]}
/>
</Flex>
- <ClearAccordion affectedTasks={affectedTasks} note={note}
setNote={setNote} />
+ <ActionAccordion affectedTasks={affectedTasks} note={note}
setNote={setNote} />
<Flex justifyContent="end" mt={3}>
<Button
colorPalette="blue"
diff --git
a/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceDialog.tsx
b/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceDialog.tsx
index b2344bf90d2..25972500d8e 100644
--- a/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceDialog.tsx
+++ b/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceDialog.tsx
@@ -21,6 +21,7 @@ import { useState } from "react";
import { FiRefreshCw } from "react-icons/fi";
import type { TaskInstanceResponse } from "openapi/requests/types.gen";
+import { ActionAccordion } from "src/components/ActionAccordion";
import Time from "src/components/Time";
import { Button, Dialog } from "src/components/ui";
import SegmentedControl from "src/components/ui/SegmentedControl";
@@ -28,8 +29,6 @@ import { useClearTaskInstances } from
"src/queries/useClearTaskInstances";
import { useClearTaskInstancesDryRun } from
"src/queries/useClearTaskInstancesDryRun";
import { usePatchTaskInstance } from "src/queries/usePatchTaskInstance";
-import ClearAccordion from "../ClearAccordion";
-
type Props = {
readonly onClose: () => void;
readonly open: boolean;
@@ -114,7 +113,7 @@ const ClearTaskInstanceDialog = ({ onClose, open,
taskInstance }: Props) => {
]}
/>
</Flex>
- <ClearAccordion affectedTasks={affectedTasks} note={note}
setNote={setNote} />
+ <ActionAccordion affectedTasks={affectedTasks} note={note}
setNote={setNote} />
<Flex justifyContent="end" mt={3}>
<Button
colorPalette="blue"
diff --git a/airflow/ui/src/components/MarkAs/MarkAsAccordion.tsx
b/airflow/ui/src/components/MarkAs/MarkAsAccordion.tsx
deleted file mode 100644
index a275c20d6ed..00000000000
--- a/airflow/ui/src/components/MarkAs/MarkAsAccordion.tsx
+++ /dev/null
@@ -1,72 +0,0 @@
-/*!
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-import { Editable, Text, VStack } from "@chakra-ui/react";
-import type { ChangeEvent } from "react";
-
-import type { DAGRunResponse } from "openapi/requests/types.gen";
-import ReactMarkdown from "src/components/ReactMarkdown";
-import { Accordion } from "src/components/ui";
-
-type Props = {
- readonly note: DAGRunResponse["note"];
- readonly setNote: (value: string) => void;
-};
-
-const MarkAsAccordion = ({ note, setNote }: Props) => (
- <Accordion.Root collapsible defaultValue={["note"]} multiple={false}
variant="enclosed">
- <Accordion.Item key="note" value="note">
- <Accordion.ItemTrigger>
- <Text fontWeight="bold">Note</Text>
- </Accordion.ItemTrigger>
- <Accordion.ItemContent>
- <Editable.Root
- onChange={(event: ChangeEvent<HTMLInputElement>) =>
setNote(event.target.value)}
- value={note ?? ""}
- >
- <Editable.Preview
- _hover={{ backgroundColor: "transparent" }}
- alignItems="flex-start"
- as={VStack}
- gap="0"
- height="200px"
- overflowY="auto"
- width="100%"
- >
- {Boolean(note) ? (
- <ReactMarkdown>{note}</ReactMarkdown>
- ) : (
- <Text color="gray" opacity={0.6}>
- Add a note...
- </Text>
- )}
- </Editable.Preview>
- <Editable.Textarea
- data-testid="notes-input"
- height="200px"
- overflowY="auto"
- placeholder="Add a note..."
- resize="none"
- />
- </Editable.Root>
- </Accordion.ItemContent>
- </Accordion.Item>
- </Accordion.Root>
-);
-
-export default MarkAsAccordion;
diff --git a/airflow/ui/src/components/MarkAs/Run/MarkRunAsButton.tsx
b/airflow/ui/src/components/MarkAs/Run/MarkRunAsButton.tsx
index 0a7b66b569f..207d2671833 100644
--- a/airflow/ui/src/components/MarkAs/Run/MarkRunAsButton.tsx
+++ b/airflow/ui/src/components/MarkAs/Run/MarkRunAsButton.tsx
@@ -25,6 +25,7 @@ import { StateBadge } from "src/components/StateBadge";
import { Menu } from "src/components/ui";
import ActionButton from "src/components/ui/ActionButton";
+import { allowedStates } from "../utils";
import MarkRunAsDialog from "./MarkRunAsDialog";
type Props = {
@@ -32,8 +33,6 @@ type Props = {
readonly withText?: boolean;
};
-const allowedStates: Array<DAGRunPatchStates> = ["success", "failed"];
-
const MarkRunAsButton = ({ dagRun, withText = true }: Props) => {
const { onClose, onOpen, open } = useDisclosure();
const [state, setState] = useState<DAGRunPatchStates>("success");
@@ -51,7 +50,7 @@ const MarkRunAsButton = ({ dagRun, withText = true }: Props)
=> {
/>
</Menu.Trigger>
<Menu.Content>
- {allowedStates.map((menuState: DAGRunPatchStates) => (
+ {allowedStates.map((menuState) => (
<Menu.Item
asChild
disabled={dagRun.state === menuState}
@@ -64,7 +63,9 @@ const MarkRunAsButton = ({ dagRun, withText = true }: Props)
=> {
}}
value={menuState}
>
- <StateBadge state={menuState}>{menuState}</StateBadge>
+ <StateBadge my={1} state={menuState}>
+ {menuState}
+ </StateBadge>
</Menu.Item>
))}
</Menu.Content>
diff --git a/airflow/ui/src/components/MarkAs/Run/MarkRunAsDialog.tsx
b/airflow/ui/src/components/MarkAs/Run/MarkRunAsDialog.tsx
index a55693aecad..60926bb5a1c 100644
--- a/airflow/ui/src/components/MarkAs/Run/MarkRunAsDialog.tsx
+++ b/airflow/ui/src/components/MarkAs/Run/MarkRunAsDialog.tsx
@@ -21,12 +21,11 @@ import { useState } from "react";
import { FiRefreshCw } from "react-icons/fi";
import type { DAGRunPatchStates, DAGRunResponse } from
"openapi/requests/types.gen";
+import { ActionAccordion } from "src/components/ActionAccordion";
import { StateBadge } from "src/components/StateBadge";
import { Button, Dialog } from "src/components/ui";
import { usePatchDagRun } from "src/queries/usePatchDagRun";
-import MarkAsAccordion from "../MarkAsAccordion";
-
type Props = {
readonly dagRun: DAGRunResponse;
readonly onClose: () => void;
@@ -42,7 +41,7 @@ const MarkRunAsDialog = ({ dagRun, onClose, open, state }:
Props) => {
const { isPending, mutate } = usePatchDagRun({ dagId, dagRunId, onSuccess:
onClose });
return (
- <Dialog.Root onOpenChange={onClose} open={open} size="xl">
+ <Dialog.Root lazyMount onOpenChange={onClose} open={open} size="xl">
<Dialog.Content backdrop>
<Dialog.Header>
<VStack align="start" gap={4}>
@@ -55,7 +54,7 @@ const MarkRunAsDialog = ({ dagRun, onClose, open, state }:
Props) => {
<Dialog.CloseTrigger />
<Dialog.Body width="full">
- <MarkAsAccordion note={note} setNote={setNote} />
+ <ActionAccordion note={note} setNote={setNote} />
<Flex justifyContent="end" mt={3}>
<Button
colorPalette="blue"
diff --git a/airflow/ui/src/components/MarkAs/Run/MarkRunAsButton.tsx
b/airflow/ui/src/components/MarkAs/TaskInstance/MarkTaskInstanceAsButton.tsx
similarity index 71%
copy from airflow/ui/src/components/MarkAs/Run/MarkRunAsButton.tsx
copy to
airflow/ui/src/components/MarkAs/TaskInstance/MarkTaskInstanceAsButton.tsx
index 0a7b66b569f..fb888e424fc 100644
--- a/airflow/ui/src/components/MarkAs/Run/MarkRunAsButton.tsx
+++ b/airflow/ui/src/components/MarkAs/TaskInstance/MarkTaskInstanceAsButton.tsx
@@ -20,44 +20,44 @@ import { Box, useDisclosure } from "@chakra-ui/react";
import { useState } from "react";
import { MdArrowDropDown } from "react-icons/md";
-import type { DAGRunPatchStates, DAGRunResponse } from
"openapi/requests/types.gen";
+import type { TaskInstanceResponse, TaskInstanceState } from
"openapi/requests/types.gen";
import { StateBadge } from "src/components/StateBadge";
import { Menu } from "src/components/ui";
import ActionButton from "src/components/ui/ActionButton";
-import MarkRunAsDialog from "./MarkRunAsDialog";
+import { allowedStates } from "../utils";
+import MarkTaskInstanceAsDialog from "./MarkTaskInstanceAsDialog";
type Props = {
- readonly dagRun: DAGRunResponse;
+ readonly taskInstance: TaskInstanceResponse;
readonly withText?: boolean;
};
-const allowedStates: Array<DAGRunPatchStates> = ["success", "failed"];
-
-const MarkRunAsButton = ({ dagRun, withText = true }: Props) => {
+const MarkTaskInstanceAsButton = ({ taskInstance, withText = true }: Props) =>
{
const { onClose, onOpen, open } = useDisclosure();
- const [state, setState] = useState<DAGRunPatchStates>("success");
+
+ const [state, setState] = useState<TaskInstanceState>("success");
return (
<Box>
<Menu.Root positioning={{ gutter: 0, placement: "bottom" }}>
<Menu.Trigger asChild>
<ActionButton
- actionName="Mark Dag Run as..."
+ actionName="Mark Task Instance as..."
flexDirection="row-reverse"
icon={<MdArrowDropDown />}
- text="Mark Run as..."
+ text="Mark Task Instance as..."
withText={withText}
/>
</Menu.Trigger>
<Menu.Content>
- {allowedStates.map((menuState: DAGRunPatchStates) => (
+ {allowedStates.map((menuState) => (
<Menu.Item
asChild
- disabled={dagRun.state === menuState}
+ disabled={taskInstance.state === menuState}
key={menuState}
onClick={() => {
- if (dagRun.state !== menuState) {
+ if (taskInstance.state !== menuState) {
setState(menuState);
onOpen();
}
@@ -70,9 +70,9 @@ const MarkRunAsButton = ({ dagRun, withText = true }: Props)
=> {
</Menu.Content>
</Menu.Root>
- <MarkRunAsDialog dagRun={dagRun} onClose={onClose} open={open}
state={state} />
+ <MarkTaskInstanceAsDialog onClose={onClose} open={open} state={state}
taskInstance={taskInstance} />
</Box>
);
};
-export default MarkRunAsButton;
+export default MarkTaskInstanceAsButton;
diff --git
a/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceDialog.tsx
b/airflow/ui/src/components/MarkAs/TaskInstance/MarkTaskInstanceAsDialog.tsx
similarity index 68%
copy from
airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceDialog.tsx
copy to
airflow/ui/src/components/MarkAs/TaskInstance/MarkTaskInstanceAsDialog.tsx
index b2344bf90d2..f3f9a3ce16a 100644
--- a/airflow/ui/src/components/Clear/TaskInstance/ClearTaskInstanceDialog.tsx
+++ b/airflow/ui/src/components/MarkAs/TaskInstance/MarkTaskInstanceAsDialog.tsx
@@ -20,65 +20,60 @@ import { Flex, Heading, VStack } from "@chakra-ui/react";
import { useState } from "react";
import { FiRefreshCw } from "react-icons/fi";
-import type { TaskInstanceResponse } from "openapi/requests/types.gen";
+import type { TaskInstanceResponse, TaskInstanceState } from
"openapi/requests/types.gen";
+import { ActionAccordion } from "src/components/ActionAccordion";
+import { StateBadge } from "src/components/StateBadge";
import Time from "src/components/Time";
import { Button, Dialog } from "src/components/ui";
import SegmentedControl from "src/components/ui/SegmentedControl";
-import { useClearTaskInstances } from "src/queries/useClearTaskInstances";
-import { useClearTaskInstancesDryRun } from
"src/queries/useClearTaskInstancesDryRun";
import { usePatchTaskInstance } from "src/queries/usePatchTaskInstance";
-
-import ClearAccordion from "../ClearAccordion";
+import { usePatchTaskInstanceDryRun } from
"src/queries/usePatchTaskInstanceDryRun";
type Props = {
readonly onClose: () => void;
readonly open: boolean;
+ readonly state: TaskInstanceState;
readonly taskInstance: TaskInstanceResponse;
};
-const ClearTaskInstanceDialog = ({ onClose, open, taskInstance }: Props) => {
- const taskId = taskInstance.task_id;
- const mapIndex = taskInstance.map_index;
-
+const MarkTaskInstanceAsDialog = ({ onClose, open, state, taskInstance }:
Props) => {
const dagId = taskInstance.dag_id;
const dagRunId = taskInstance.dag_run_id;
-
- const { isPending, mutate } = useClearTaskInstances({
- dagId,
- dagRunId,
- onSuccessConfirm: onClose,
- });
+ const taskId = taskInstance.task_id;
+ const mapIndex = taskInstance.map_index;
const [selectedOptions, setSelectedOptions] = useState<Array<string>>([]);
- const onlyFailed = selectedOptions.includes("onlyFailed");
const past = selectedOptions.includes("past");
const future = selectedOptions.includes("future");
const upstream = selectedOptions.includes("upstream");
const downstream = selectedOptions.includes("downstream");
const [note, setNote] = useState<string | null>(taskInstance.note);
- const { isPending: isPendingPatchDagRun, mutate: mutatePatchTaskInstance } =
usePatchTaskInstance({
+
+ const { isPending, mutate } = usePatchTaskInstance({
dagId,
dagRunId,
mapIndex,
+ onSuccess: onClose,
taskId,
});
-
- const { data } = useClearTaskInstancesDryRun({
+ const { data, isPending: isPendingDryRun } = usePatchTaskInstanceDryRun({
dagId,
+ dagRunId,
+ mapIndex,
options: {
enabled: open,
},
requestBody: {
- dag_run_id: dagRunId,
include_downstream: downstream,
include_future: future,
include_past: past,
include_upstream: upstream,
- only_failed: onlyFailed,
- task_ids: [taskId],
+ new_state: state,
+ note,
},
+ taskId,
});
const affectedTasks = data ?? {
@@ -92,8 +87,8 @@ const ClearTaskInstanceDialog = ({ onClose, open,
taskInstance }: Props) => {
<Dialog.Header>
<VStack align="start" gap={4}>
<Heading size="xl">
- <strong>Clear Task Instance:</strong>
{taskInstance.task_display_name}{" "}
- <Time datetime={taskInstance.start_date} />
+ <strong>Mark Task Instance as {state}:</strong>
{taskInstance.task_display_name}{" "}
+ <Time datetime={taskInstance.start_date} /> <StateBadge
state={state} />
</Heading>
</VStack>
</Dialog.Header>
@@ -110,39 +105,29 @@ const ClearTaskInstanceDialog = ({ onClose, open,
taskInstance }: Props) => {
{ label: "Future", value: "future" },
{ label: "Upstream", value: "upstream" },
{ label: "Downstream", value: "downstream" },
- { label: "Only Failed", value: "onlyFailed" },
]}
/>
</Flex>
- <ClearAccordion affectedTasks={affectedTasks} note={note}
setNote={setNote} />
+ <ActionAccordion affectedTasks={affectedTasks} note={note}
setNote={setNote} />
<Flex justifyContent="end" mt={3}>
<Button
colorPalette="blue"
- disabled={affectedTasks.total_entries === 0}
- loading={isPending || isPendingPatchDagRun}
+ loading={isPending || isPendingDryRun}
onClick={() => {
mutate({
dagId,
+ dagRunId,
+ mapIndex,
requestBody: {
- dag_run_id: dagRunId,
- dry_run: false,
include_downstream: downstream,
include_future: future,
include_past: past,
include_upstream: upstream,
- only_failed: onlyFailed,
- task_ids: [taskId],
+ new_state: state,
+ note,
},
+ taskId,
});
- if (note !== taskInstance.note) {
- mutatePatchTaskInstance({
- dagId,
- dagRunId,
- mapIndex,
- requestBody: { note },
- taskId,
- });
- }
}}
>
<FiRefreshCw /> Confirm
@@ -154,4 +139,4 @@ const ClearTaskInstanceDialog = ({ onClose, open,
taskInstance }: Props) => {
);
};
-export default ClearTaskInstanceDialog;
+export default MarkTaskInstanceAsDialog;
diff --git a/airflow/ui/src/components/MarkAs/index.tsx
b/airflow/ui/src/components/MarkAs/TaskInstance/index.tsx
similarity index 93%
copy from airflow/ui/src/components/MarkAs/index.tsx
copy to airflow/ui/src/components/MarkAs/TaskInstance/index.tsx
index 7aab3b38b57..b478ccfe772 100644
--- a/airflow/ui/src/components/MarkAs/index.tsx
+++ b/airflow/ui/src/components/MarkAs/TaskInstance/index.tsx
@@ -17,4 +17,4 @@
* under the License.
*/
-export { default as MarkRunAsButton } from "./Run";
+export { default } from "./MarkTaskInstanceAsButton";
diff --git a/airflow/ui/src/components/MarkAs/index.tsx
b/airflow/ui/src/components/MarkAs/index.tsx
index 7aab3b38b57..f71a827bae2 100644
--- a/airflow/ui/src/components/MarkAs/index.tsx
+++ b/airflow/ui/src/components/MarkAs/index.tsx
@@ -18,3 +18,4 @@
*/
export { default as MarkRunAsButton } from "./Run";
+export { default as MarkTaskInstanceAsButton } from "./TaskInstance";
diff --git a/airflow/ui/src/components/MarkAs/index.tsx
b/airflow/ui/src/components/MarkAs/utils.ts
similarity index 84%
copy from airflow/ui/src/components/MarkAs/index.tsx
copy to airflow/ui/src/components/MarkAs/utils.ts
index 7aab3b38b57..14245602bfb 100644
--- a/airflow/ui/src/components/MarkAs/index.tsx
+++ b/airflow/ui/src/components/MarkAs/utils.ts
@@ -16,5 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
+import type { DAGRunPatchStates } from "openapi/requests/types.gen";
-export { default as MarkRunAsButton } from "./Run";
+export const allowedStates: Array<DAGRunPatchStates> = ["success", "failed"];
diff --git a/airflow/ui/src/pages/Run/TaskInstances.tsx
b/airflow/ui/src/pages/Run/TaskInstances.tsx
index 130da51182c..4f9667091df 100644
--- a/airflow/ui/src/pages/Run/TaskInstances.tsx
+++ b/airflow/ui/src/pages/Run/TaskInstances.tsx
@@ -34,6 +34,7 @@ import { ClearTaskInstanceButton } from
"src/components/Clear";
import { DataTable } from "src/components/DataTable";
import { useTableURLState } from "src/components/DataTable/useTableUrlState";
import { ErrorAlert } from "src/components/ErrorAlert";
+import { MarkTaskInstanceAsButton } from "src/components/MarkAs";
import { SearchBar } from "src/components/SearchBar";
import { StateBadge } from "src/components/StateBadge";
import Time from "src/components/Time";
@@ -97,6 +98,7 @@ const columns: Array<ColumnDef<TaskInstanceResponse>> = [
cell: ({ row }) => (
<Flex justifyContent="end">
<ClearTaskInstanceButton taskInstance={row.original} withText={false}
/>
+ <MarkTaskInstanceAsButton taskInstance={row.original} withText={false}
/>
</Flex>
),
enableSorting: false,
diff --git a/airflow/ui/src/pages/TaskInstance/Header.tsx
b/airflow/ui/src/pages/TaskInstance/Header.tsx
index 6761871a8db..f8bdbe86042 100644
--- a/airflow/ui/src/pages/TaskInstance/Header.tsx
+++ b/airflow/ui/src/pages/TaskInstance/Header.tsx
@@ -23,6 +23,7 @@ import { MdOutlineTask } from "react-icons/md";
import type { TaskInstanceResponse } from "openapi/requests/types.gen";
import { ClearTaskInstanceButton } from "src/components/Clear";
import DisplayMarkdownButton from "src/components/DisplayMarkdownButton";
+import { MarkTaskInstanceAsButton } from "src/components/MarkAs";
import { Stat } from "src/components/Stat";
import { StateBadge } from "src/components/StateBadge";
import Time from "src/components/Time";
@@ -52,6 +53,7 @@ export const Header = ({ taskInstance }: { readonly
taskInstance: TaskInstanceRe
/>
)}
<ClearTaskInstanceButton taskInstance={taskInstance} />
+ <MarkTaskInstanceAsButton taskInstance={taskInstance} />
</HStack>
</Flex>
<SimpleGrid columns={6} gap={4} my={2}>
diff --git a/airflow/ui/src/queries/usePatchTaskInstance.ts
b/airflow/ui/src/queries/usePatchTaskInstance.ts
index 77f499336d5..60544dbd973 100644
--- a/airflow/ui/src/queries/usePatchTaskInstance.ts
+++ b/airflow/ui/src/queries/usePatchTaskInstance.ts
@@ -38,16 +38,18 @@ export const usePatchTaskInstance = ({
dagId,
dagRunId,
mapIndex,
+ onSuccess,
taskId,
}: {
dagId: string;
dagRunId: string;
mapIndex: number;
+ onSuccess?: () => void;
taskId: string;
}) => {
const queryClient = useQueryClient();
- const onSuccess = async () => {
+ const onSuccessFn = async () => {
const queryKeys = [
UseTaskInstanceServiceGetTaskInstanceKeyFn({ dagId, dagRunId, taskId }),
UseTaskInstanceServiceGetMappedTaskInstanceKeyFn({ dagId, dagRunId,
mapIndex, taskId }),
@@ -55,10 +57,14 @@ export const usePatchTaskInstance = ({
];
await Promise.all(queryKeys.map((key) => queryClient.invalidateQueries({
queryKey: key })));
+
+ if (onSuccess) {
+ onSuccess();
+ }
};
return useTaskInstanceServicePatchTaskInstance({
onError,
- onSuccess,
+ onSuccess: onSuccessFn,
});
};
diff --git a/airflow/ui/src/queries/usePatchTaskInstanceDryRun.ts
b/airflow/ui/src/queries/usePatchTaskInstanceDryRun.ts
new file mode 100644
index 00000000000..70da064b63b
--- /dev/null
+++ b/airflow/ui/src/queries/usePatchTaskInstanceDryRun.ts
@@ -0,0 +1,63 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { useQuery, type UseQueryOptions } from "@tanstack/react-query";
+
+import { TaskInstanceService } from "openapi/requests/services.gen";
+import type { PatchTaskInstanceBody, PatchTaskInstanceDryRunResponse } from
"openapi/requests/types.gen";
+
+type Props<TData, TError> = {
+ dagId: string;
+ dagRunId: string;
+ mapIndex: number;
+ options?: Omit<UseQueryOptions<TData, TError>, "queryFn" | "queryKey">;
+ requestBody: PatchTaskInstanceBody;
+ taskId: string;
+};
+
+export const usePatchTaskInstanceDryRun = <TData =
PatchTaskInstanceDryRunResponse, TError = unknown>({
+ dagId,
+ dagRunId,
+ mapIndex,
+ options,
+ requestBody,
+ taskId,
+}: Props<TData, TError>) =>
+ useQuery<TData, TError>({
+ ...options,
+ queryFn: () =>
+ TaskInstanceService.patchTaskInstanceDryRun({
+ dagId,
+ dagRunId,
+ mapIndex,
+ requestBody,
+ taskId,
+ }) as TData,
+ queryKey: [
+ "patchTaskInstanceDryRun",
+ dagId,
+ dagRunId,
+ taskId,
+ mapIndex,
+ requestBody.new_state,
+ requestBody.include_downstream,
+ requestBody.include_future,
+ requestBody.include_past,
+ requestBody.include_upstream,
+ ],
+ });