Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions airflow-core/src/airflow/ui/src/components/Graph/TaskLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,20 @@ type Props = {
} & TaskNameProps;

export const TaskLink = forwardRef<HTMLAnchorElement, Props>(({ id, isGroup, isMapped, ...rest }, ref) => {
const { dagId = "", runId, taskId } = useParams();
const { dagId = "", groupId, runId, taskId } = useParams();
const [searchParams] = useSearchParams();

if (isGroup && runId === undefined) {
return undefined;
}

const pathname = isGroup
? `/dags/${dagId}/runs/${runId}/tasks/group/${id}`
: `/dags/${dagId}/${runId === undefined ? "" : `runs/${runId}/`}${taskId === id ? "" : `tasks/${id}`}${isMapped && taskId !== id && runId !== undefined ? "/mapped" : ""}`;
const basePath = `/dags/${dagId}${runId === undefined ? "" : `/runs/${runId}`}`;
const taskPath = isGroup
? groupId === id
? ""
: `/tasks/group/${id}`
: taskId === id
? ""
: `/tasks/${id}${isMapped && taskId !== id && runId !== undefined ? "/mapped" : ""}`;

return (
<RouterLink
ref={ref}
to={{
pathname,
search: searchParams.toString(),
}}
>
<RouterLink ref={ref} to={{ pathname: basePath + taskPath, search: searchParams.toString() }}>
<TaskName isGroup={isGroup} isMapped={isMapped} {...rest} />
</RouterLink>
);
Expand Down
1 change: 0 additions & 1 deletion airflow-core/src/airflow/ui/src/components/TaskName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const TaskName = ({
setupTeardownType,
...rest
}: TaskNameProps) => {
// We don't have a task group details page to link to
if (isGroup) {
return (
<Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { TogglePause } from "src/components/TogglePause";
import { isStatePending, useAutoRefresh } from "src/utils";

export const DagBreadcrumb = () => {
const { dagId = "", mapIndex = "-1", runId, taskId } = useParams();
const { dagId = "", groupId, mapIndex = "-1", runId, taskId } = useParams();
const refetchInterval = useAutoRefresh({ dagId });

const { data: dag } = useDagServiceGetDagDetails({
Expand Down Expand Up @@ -86,6 +86,23 @@ export const DagBreadcrumb = () => {
});
}

// Add group breadcrumb
if (groupId !== undefined) {
if (runId === undefined) {
links.push({
label: "All Runs",
title: "Dag Run",
value: `/dags/${dagId}/runs`,
});
}

links.push({
label: groupId,
title: "Group",
value: `/dags/${dagId}/groups/${groupId}`,
});
}

// Add task breadcrumb
if (runId !== undefined && taskId !== undefined) {
if (task?.is_mapped) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,26 @@ export const TaskNames = ({ nodes }: Props) => {
transition="background-color 0.2s"
>
{node.isGroup ? (
<Flex>
<TaskName
display="inline"
fontSize="sm"
fontWeight="normal"
isGroup={true}
isMapped={Boolean(node.is_mapped)}
label={node.label}
paddingLeft={node.depth * 3 + 2}
setupTeardownType={node.setup_teardown_type}
/>
<Flex alignItems="center">
<Link data-testid={node.id} display="inline">
<RouterLink
replace
to={{
pathname: `/dags/${dagId}/tasks/group/${node.id}`,
search: searchParams.toString(),
}}
>
<TaskName
fontSize="sm"
fontWeight="normal"
isGroup={true}
isMapped={Boolean(node.is_mapped)}
label={node.label}
paddingLeft={node.depth * 3 + 2}
setupTeardownType={node.setup_teardown_type}
/>
</RouterLink>
</Link>
<chakra.button
aria-label="Toggle group"
display="inline"
Expand Down
26 changes: 26 additions & 0 deletions airflow-core/src/airflow/ui/src/pages/Task/GroupTaskHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*!
* 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 { AiOutlineGroup } from "react-icons/ai";

import type { NodeResponse } from "openapi/requests/types.gen";
import { HeaderCard } from "src/components/HeaderCard";

export const GroupTaskHeader = ({ groupTask }: { readonly groupTask: NodeResponse }) => (
<HeaderCard icon={<AiOutlineGroup />} stats={[]} title={groupTask.label} />
);
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { isStatePending, useAutoRefresh } from "src/utils";
const defaultHour = "24";

export const Overview = () => {
const { dagId = "", taskId } = useParams();
const { dagId = "", groupId, taskId } = useParams();

const now = dayjs();
const [startDate, setStartDate] = useState(now.subtract(Number(defaultHour), "hour").toISOString());
Expand All @@ -46,7 +46,8 @@ export const Overview = () => {
runAfterGte: startDate,
runAfterLte: endDate,
state: ["failed"],
taskId,
taskDisplayNamePattern: groupId ?? undefined,
taskId: Boolean(groupId) ? undefined : taskId,
});

const { data: taskInstances, isLoading: isLoadingTaskInstances } = useTaskInstanceServiceGetTaskInstances(
Expand All @@ -55,7 +56,8 @@ export const Overview = () => {
dagRunId: "~",
limit: 14,
orderBy: "-run_after",
taskId,
taskDisplayNamePattern: groupId ?? undefined,
taskId: Boolean(groupId) ? undefined : taskId,
},
undefined,
{
Expand Down
37 changes: 33 additions & 4 deletions airflow-core/src/airflow/ui/src/pages/Task/Task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import { LuChartColumn } from "react-icons/lu";
import { MdOutlineEventNote, MdOutlineTask } from "react-icons/md";
import { useParams } from "react-router-dom";

import { useDagServiceGetDagDetails, useTaskServiceGetTask } from "openapi/queries";
import { useDagServiceGetDagDetails, useGridServiceGridData, useTaskServiceGetTask } from "openapi/queries";
import { DetailsLayout } from "src/layouts/Details/DetailsLayout";
import { getGroupTask } from "src/utils/groupTask";

import { GroupTaskHeader } from "./GroupTaskHeader";
import { Header } from "./Header";

const tabs = [
Expand All @@ -33,9 +35,30 @@ const tabs = [
];

export const Task = () => {
const { dagId = "", taskId = "" } = useParams();
const { dagId = "", groupId, taskId } = useParams();

const { data: task, error, isLoading } = useTaskServiceGetTask({ dagId, taskId });
const displayTabs = groupId === undefined ? tabs : tabs.filter((tab) => tab.label !== "Events");

const {
data: task,
error,
isLoading,
} = useTaskServiceGetTask({ dagId, taskId: groupId ?? taskId }, undefined, {
enabled: groupId === undefined,
});

const { data: gridData } = useGridServiceGridData(
{
dagId,
includeDownstream: true,
includeUpstream: true,
},
undefined,
{ enabled: groupId !== undefined },
);

const groupTask =
groupId === undefined ? undefined : getGroupTask(gridData?.structure.nodes ?? [], groupId);

const {
data: dag,
Expand All @@ -47,8 +70,14 @@ export const Task = () => {

return (
<ReactFlowProvider>
<DetailsLayout dag={dag} error={error ?? dagError} isLoading={isLoading || isDagLoading} tabs={tabs}>
<DetailsLayout
dag={dag}
error={error ?? dagError}
isLoading={isLoading || isDagLoading}
tabs={displayTabs}
>
{task === undefined ? undefined : <Header task={task} />}
{groupTask ? <GroupTaskHeader groupTask={groupTask} /> : undefined}
</DetailsLayout>
</ReactFlowProvider>
);
Expand Down
8 changes: 8 additions & 0 deletions airflow-core/src/airflow/ui/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ export const routerConfig = [
element: <GroupTaskInstance />,
path: "dags/:dagId/runs/:runId/tasks/group/:groupId",
},
{
children: [
{ element: <TaskOverview />, index: true },
{ element: <TaskInstances />, path: "task_instances" },
],
element: <Task />,
path: "dags/:dagId/tasks/group/:groupId",
},
{
children: taskInstanceRoutes,
element: <TaskInstance />,
Expand Down
55 changes: 55 additions & 0 deletions airflow-core/src/airflow/ui/src/utils/groupTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*!
* 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 type { NodeResponse } from "openapi/requests/types.gen";

/**
* Finds a task node by its ID in a tree of nodes
* @param nodes - Array of root nodes to search through
* @param targetId - ID of the node to find
* @returns The found node or undefined if not found
*/
export const getGroupTask = (nodes: Array<NodeResponse>, targetId: string): NodeResponse | undefined => {
if (!nodes.length || !targetId) {
return undefined;
}

const queue: Array<NodeResponse> = [...nodes];
const [root] = targetId.split(".");

while (queue.length > 0) {
const node = queue.shift();

if (node) {
if (node.id === targetId) {
return node;
}

if (node.children && node.children.length > 0) {
const nextNode =
node.id === root && targetId.includes(".")
? node.children.find((child) => child.id === targetId)
: undefined;

queue.unshift(...(nextNode ? [nextNode] : node.children));
}
}
}

return undefined;
};