Skip to content

Commit

Permalink
Refactor TaskName, hide null tooltips, and add fake tab link
Browse files Browse the repository at this point in the history
  • Loading branch information
bbovenzi committed Feb 13, 2024
1 parent 5b2e8a4 commit 7752e9b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 29 deletions.
21 changes: 9 additions & 12 deletions airflow/www/static/js/dag/TaskName.test.tsx
Expand Up @@ -28,28 +28,25 @@ import TaskName from "./TaskName";

describe("Test TaskName", () => {
test("Displays a normal task name", () => {
const { getByText } = render(
<TaskName label="test" id="test" onToggle={() => {}} />,
{ wrapper: ChakraWrapper }
);
const { getByText } = render(<TaskName label="test" id="test" />, {
wrapper: ChakraWrapper,
});

expect(getByText("test")).toBeDefined();
});

test("Displays a mapped task name", () => {
const { getByText } = render(
<TaskName label="test" id="test" isMapped onToggle={() => {}} />,
{ wrapper: ChakraWrapper }
);
const { getByText } = render(<TaskName label="test" id="test" isMapped />, {
wrapper: ChakraWrapper,
});

expect(getByText("test [ ]")).toBeDefined();
});

test("Displays a group task name", () => {
const { getByText } = render(
<TaskName label="test" id="test" isGroup onToggle={() => {}} />,
{ wrapper: ChakraWrapper }
);
const { getByText } = render(<TaskName label="test" id="test" isGroup />, {
wrapper: ChakraWrapper,
});

expect(getByText("test")).toBeDefined();
});
Expand Down
7 changes: 2 additions & 5 deletions airflow/www/static/js/dag/TaskName.tsx
Expand Up @@ -17,14 +17,13 @@
* under the License.
*/

import React, { MouseEventHandler, CSSProperties } from "react";
import React, { CSSProperties } from "react";
import { Text, TextProps, useTheme } from "@chakra-ui/react";
import { FiChevronUp, FiArrowUpRight, FiArrowDownRight } from "react-icons/fi";

interface Props extends TextProps {
isGroup?: boolean;
isMapped?: boolean;
onToggle: MouseEventHandler<HTMLDivElement>;
isOpen?: boolean;
label: string;
id?: string;
Expand All @@ -35,7 +34,6 @@ interface Props extends TextProps {
const TaskName = ({
isGroup = false,
isMapped = false,
onToggle,
isOpen = false,
label,
id,
Expand All @@ -51,8 +49,7 @@ const TaskName = ({
};
return (
<Text
cursor={isGroup ? "pointer" : undefined}
onClick={onToggle}
cursor="pointer"
data-testid={id}
width="100%"
color={colors.gray[800]}
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/static/js/dag/details/graph/Node.tsx
Expand Up @@ -144,7 +144,7 @@ export const BaseNode = ({
label={taskName}
isOpen={isOpen}
isGroup={!!childCount}
onToggle={(e) => {
onClick={(e) => {
e.stopPropagation();
onToggleCollapse();
}}
Expand Down
27 changes: 26 additions & 1 deletion airflow/www/static/js/dag/details/index.tsx
Expand Up @@ -27,6 +27,7 @@ import {
TabPanels,
Tab,
Text,
Button,
} from "@chakra-ui/react";
import { useSearchParams } from "react-router-dom";

Expand All @@ -40,6 +41,7 @@ import {
MdCode,
MdOutlineViewTimeline,
MdSyncAlt,
MdHourglassBottom,
} from "react-icons/md";
import { BiBracket } from "react-icons/bi";
import URLSearchParamsWrapper from "src/utils/URLSearchParamWrapper";
Expand Down Expand Up @@ -174,7 +176,8 @@ const Details = ({
// Default to graph tab when navigating from a task instance to a group/dag/dagrun
const tabCount = runId && taskId && !isGroup ? 5 : 4;
if (tabCount === 4 && tabIndex > 3) {
onChangeTab(1);
if (!runId && taskId) onChangeTab(0);
else onChangeTab(1);
}
}, [runId, taskId, tabIndex, isGroup, onChangeTab]);

Expand Down Expand Up @@ -292,6 +295,28 @@ const Details = ({
</Text>
</Tab>
)}
{/* Match the styling of a tab but its actually a button */}
{!!taskId && !!runId && (
<Button
variant="unstyled"
display="flex"
alignItems="center"
fontSize="lg"
py={3}
// need to split pl and pr instead of px
pl={4}
pr={4}
mt="4px"
onClick={() => {
onSelect({ taskId });
}}
>
<MdHourglassBottom size={16} />
<Text as="strong" ml={1}>
Task Duration
</Text>
</Button>
)}
</TabList>
<TabPanels height="100%">
<TabPanel height="100%">
Expand Down
22 changes: 15 additions & 7 deletions airflow/www/static/js/dag/details/task/TaskDuration.tsx
Expand Up @@ -134,16 +134,24 @@ const TaskDuration = () => {
return `
Run Id: ${runId} <br>
${startCase(orderingLabel)}: ${formatDateTime(data[orderingLabel])} <br>
Try Number: ${tryNumber} <br>
${tryNumber && tryNumber > -1 ? `Try Number: ${tryNumber} <br>` : ""}
State: ${state} <br>
Queued: ${queuedDttm && formatDateTime(queuedDttm)} <br>
${queuedDttm ? `Queued: ${formatDateTime(queuedDttm)} <br>` : ""}
Started: ${startDate && formatDateTime(startDate)} <br>
Ended: ${endDate && formatDateTime(endDate)} <br>
Queued duration: ${queuedDurationUnit.toFixed(2)} ${unit}<br>
Ended: ${endDate && formatDateTime(endDate || undefined)} <br>
${
queuedDttm
? `Queued duration: ${queuedDurationUnit.toFixed(2)} ${unit}<br>`
: ""
}
Run duration: ${runDurationUnit.toFixed(2)} ${unit}<br>
Total duration: ${(queuedDurationUnit + runDurationUnit).toFixed(
2
)} ${unit}<br>
${
queuedDttm
? `Total duration: ${(queuedDurationUnit + runDurationUnit).toFixed(
2
)} ${unit}<br>`
: ""
}
`;
}

Expand Down
10 changes: 7 additions & 3 deletions airflow/www/static/js/dag/grid/renderTaskRows.tsx
Expand Up @@ -176,15 +176,19 @@ const Row = (props: RowProps) => {
zIndex={1}
>
<TaskName
onToggle={memoizedToggle}
onClick={(e) => {
if (isGroup) {
e.stopPropagation();
memoizedToggle();
}
}}
isGroup={isGroup}
isMapped={task.isMapped && !isParentMapped}
label={task.label || task.id || ""}
id={task.id || ""}
isOpen={isOpen}
ml={level * 4 + 4}
pl={level * 4 + 4}
setupTeardownType={task.setupTeardownType}
mr={4}
fontWeight={
isGroup || (task.isMapped && !isParentMapped)
? "bold"
Expand Down

0 comments on commit 7752e9b

Please sign in to comment.