Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix task instance and runs tooltips in Grid view #58359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking "Sign up for GitHub", you agree to our terms of service and privacy statement. We'll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pierrejeambrun merged 9 commits into apache:main from RoyLee1224:basic-tooltip
Dec 3, 2025
Merged

Fix task instance and runs tooltips in Grid view #58359

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
127 changes: 127 additions & 0 deletions airflow-core/src/airflow/ui/src/components/BasicTooltip.tsx
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*!
* 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, Portal } from "@chakra-ui/react";
import type { ReactElement, ReactNode } from "react";
import { cloneElement, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";

type Props = {
readonly children: ReactElement;
readonly content: ReactNode;
};

const offset = 8;

export const BasicTooltip = ({ children, content }: Props): ReactElement => {
const triggerRef = useRef(null);
const tooltipRef = useRef(null);
const [isOpen, setIsOpen] = useState(false);
const [showOnTop, setShowOnTop] = useState(false);
const timeoutRef = useRef();

const handleMouseEnter = useCallback(() => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
timeoutRef.current = setTimeout(() => {
setIsOpen(true);
}, 500);
}, []);

const handleMouseLeave = useCallback(() => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
timeoutRef.current = undefined;
}
setIsOpen(false);
}, []);

// Calculate position based on actual tooltip height before paint
useLayoutEffect(() => {
if (isOpen && triggerRef.current && tooltipRef.current) {
const triggerRect = triggerRef.current.getBoundingClientRect();
const tooltipHeight = tooltipRef.current.clientHeight;
const wouldOverflow = triggerRect.bottom + offset + tooltipHeight > globalThis.innerHeight;

setShowOnTop(wouldOverflow);
}
}, [isOpen]);

// Cleanup on unmount
useEffect(
() => () => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
},
[],
);

// Clone children and attach event handlers + ref
const trigger = cloneElement(children, {
onMouseEnter: handleMouseEnter,
onMouseLeave: handleMouseLeave,
ref: triggerRef,
});

if (!isOpen || !triggerRef.current) {
return trigger;
}

const rect = triggerRef.current.getBoundingClientRect();
const { scrollX, scrollY } = globalThis;

return (
<>
{trigger}
bg="bg.inverted"
borderRadius="md"
boxShadow="md"
color="fg.inverted"
fontSize="sm"
left={`${rect.left + scrollX + rect.width / 2}px`}
paddingX="3"
paddingY="2"
pointerEvents="none"
position="absolute"
ref={tooltipRef}
top={showOnTop ? `${rect.top + scrollY - offset}px` : `${rect.bottom + scrollY + offset}px`}
transform={showOnTop ? "translate(-50%, -100%)" : "translateX(-50%)"}
whiteSpace="nowrap"
zIndex="popover"
>
borderLeft="4px solid transparent"
borderRight="4px solid transparent"
height={0}
left="50%"
position="absolute"
transform="translateX(-50%)"
width={0}
{...(showOnTop
? { borderTop: "4px solid var(--chakra-colors-bg-inverted)", bottom: "-4px" }
: { borderBottom: "4px solid var(--chakra-colors-bg-inverted)", top: "-4px" })}
/>
{content}
);
};
2 changes: 1 addition & 1 deletion airflow-core/src/airflow/ui/src/components/DagRunInfo.tsx
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const DagRunInfo = ({ endDate, logicalDate, runAfter, startDate, state }: Props)
{state === undefined ? undefined : (
{translate("state")}: {state}
{translate("state")}: {translate(`common:states.${state}`)}
)}
{Boolean(logicalDate) ? (
Expand Down
63 changes: 0 additions & 63 deletions airflow-core/src/airflow/ui/src/components/HoverTooltip.tsx
View file
Open in desktop

This file was deleted.

5 changes: 4 additions & 1 deletion airflow-core/src/airflow/ui/src/components/TaskInstanceToolt ip.tsx
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ const TaskInstanceTooltip = ({ children, positioning, taskInstance, ...rest }: P
content={
{translate("state")}: {taskInstance.state}
{translate("state")}:{" "}
{taskInstance.state
? translate(`common:states.${taskInstance.state}`)
: translate("common:states.no_status")}
{"dag_run_id" in taskInstance ? (
Expand Down
66 changes: 41 additions & 25 deletions airflow-core/src/airflow/ui/src/layouts/Details/Grid/GridBut ton.tsx
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
* under the License.
*/
import { Flex, type FlexProps } from "@chakra-ui/react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";

import type { DagRunState, TaskInstanceState } from "openapi/requests/types.gen";
import { BasicTooltip } from "src/components/BasicTooltip";

type Props = {
readonly dagId: string;
Expand All @@ -41,39 +43,53 @@ export const GridButton = ({
state,
taskId,
...rest
}: Props) =>
isGroup ? (
background={`${state}.solid`}
borderRadius={2}
height="10px"
minW="14px"
pb="2px"
px="2px"
title={`${label}\n${state}`}
{...rest}
>
{children}
) : (
replace
to={{
pathname: `/dags/${dagId}/runs/${runId}/${taskId === undefined ? "" : `tasks/${taskId}`}`,
search: searchParams.toString(),
}}
>
}: Props) => {
const { t: translate } = useTranslation();

const tooltipContent = (
<>
{label}

{translate("state")}:{" "}
{state ? translate(`common:states.${state}`) : translate("common:states.no_status")}
);

return isGroup ? (
background={`${state}.solid`}
borderRadius={2}
height="10px"
minW="14px"
pb="2px"
px="2px"
title={`${label}\n${state}`}
width="14px"
{...rest}
>
{children}
) : (
replace
to={{
pathname: `/dags/${dagId}/runs/${runId}/${taskId === undefined ? "" : `tasks/${taskId}`}`,
search: searchParams.toString(),
}}
>
background={`${state}.solid`}
borderRadius={2}
height="10px"
pb="2px"
px="2px"
width="14px"
{...rest}
>
{children}
);
};
65 changes: 34 additions & 31 deletions airflow-core/src/airflow/ui/src/layouts/Details/Grid/GridTI. tsx
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import { useTranslation } from "react-i18next";
import { Link, useLocation, useParams, useSearchParams } from "react-router-dom";

import type { LightGridTaskInstanceSummary } from "openapi/requests/types.gen";
import { BasicTooltip } from "src/components/BasicTooltip";
import { StateIcon } from "src/components/StateIcon";
import Time from "src/components/Time";
import { Tooltip } from "src/components/ui";
import { type HoverContextType, useHover } from "src/context/hover";
import { buildTaskInstanceUrl } from "src/utils/links";

Expand Down Expand Up @@ -106,35 +106,38 @@ const Instance = ({ dagId, instance, isGroup, isMapped, onClick, runId, taskId }
py={0}
transition="background-color 0.2s"
>
id={`grid-${runId}-${taskId}`}
onClick={onClick}
replace
to={{
pathname: getTaskUrl(),
search: redirectionSearch,
}}
content={
<>
{translate("taskId")}: {taskId}

{translate("state")}:{" "}
{instance.state
? translate(`common:states.${instance.state}`)
: translate("common:states.no_status")}
{instance.min_start_date !== null && (
<>

{translate("startDate")}:
)}
{instance.max_end_date !== null && (
<>

{translate("endDate")}:
)}
}
>
content={
<>
{translate("taskId")}: {taskId}

{translate("state")}: {instance.state}
{instance.min_start_date !== null && (
<>

{translate("startDate")}:
)}
{instance.max_end_date !== null && (
<>

{translate("endDate")}:
)}
}
id={`grid-${runId}-${taskId}`}
onClick={onClick}
replace
to={{
pathname: getTaskUrl(),
search: redirectionSearch,
}}
>
alignItems="center"
Expand All @@ -150,8 +153,8 @@ const Instance = ({ dagId, instance, isGroup, isMapped, onClick, runId, taskId }
>
Tooltip>
Link>
Link>
BasicTooltip>
);
};
Expand Down
Loading