Skip to content

Commit 91a9347

Browse files
authored
Add asset event information to Dag Graph (apache#47410)
1 parent 1308e53 commit 91a9347

File tree

2 files changed

+70
-33
lines changed

2 files changed

+70
-33
lines changed

airflow/ui/src/components/Graph/AssetNode.tsx

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,72 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { Flex, Heading, HStack } from "@chakra-ui/react";
19+
import { Flex, Heading, HStack, Text } from "@chakra-ui/react";
2020
import type { NodeProps, Node as NodeType } from "@xyflow/react";
2121
import { FiDatabase } from "react-icons/fi";
22+
import { useParams } from "react-router-dom";
2223

24+
import { useAssetServiceGetAssetEvents, useDagRunServiceGetUpstreamAssetEvents } from "openapi/queries";
25+
import { pluralize } from "src/utils";
26+
27+
import Time from "../Time";
2328
import { NodeWrapper } from "./NodeWrapper";
2429
import type { CustomNodeProps } from "./reactflowUtils";
2530

2631
export const AssetNode = ({
2732
data: { height, isSelected, label, width },
28-
}: NodeProps<NodeType<CustomNodeProps, "asset">>) => (
29-
<NodeWrapper>
30-
<Flex
31-
bg="bg"
32-
borderColor={isSelected ? "border.inverted" : "border"}
33-
borderRadius={5}
34-
borderWidth={isSelected ? 6 : 2}
35-
cursor="default"
36-
flexDirection="column"
37-
height={`${height}px`}
38-
px={3}
39-
py={isSelected ? 0 : 1}
40-
width={`${width}px`}
41-
>
42-
<HStack>
43-
<Heading ml={-2} size="sm">
44-
<FiDatabase />
45-
</Heading>
46-
{label}
47-
</HStack>
48-
</Flex>
49-
</NodeWrapper>
50-
);
33+
}: NodeProps<NodeType<CustomNodeProps, "asset">>) => {
34+
const { dagId = "", runId = "" } = useParams();
35+
const { data: upstreamEventsData } = useDagRunServiceGetUpstreamAssetEvents(
36+
{ dagId, dagRunId: runId },
37+
undefined,
38+
{ enabled: Boolean(dagId) && Boolean(runId) },
39+
);
40+
41+
const { data: downstreamEventsData } = useAssetServiceGetAssetEvents(
42+
{ sourceDagId: dagId, sourceRunId: runId },
43+
undefined,
44+
{ enabled: Boolean(dagId) && Boolean(runId) },
45+
);
46+
47+
const datasetEvent = [
48+
...(upstreamEventsData?.asset_events ?? []),
49+
...(downstreamEventsData?.asset_events ?? []),
50+
].find((event) => event.name === label);
51+
52+
return (
53+
<NodeWrapper>
54+
<Flex
55+
bg="bg"
56+
borderColor={isSelected ? "border.inverted" : "border"}
57+
borderRadius={5}
58+
borderWidth={isSelected ? 6 : 2}
59+
cursor="default"
60+
flexDirection="column"
61+
height={`${height}px`}
62+
px={3}
63+
py={isSelected ? 0 : 1}
64+
width={`${width}px`}
65+
>
66+
<HStack>
67+
<Heading ml={-2} size="sm">
68+
<FiDatabase />
69+
</Heading>
70+
{label}
71+
</HStack>
72+
{datasetEvent === undefined ? undefined : (
73+
<>
74+
<Text color="fg.muted">
75+
<Time datetime={datasetEvent.timestamp} />
76+
</Text>
77+
{datasetEvent.created_dagruns.length && datasetEvent.created_dagruns.length > 1 ? (
78+
<Text color="fg.muted" fontSize="sm">
79+
+{pluralize("other Dag Run", datasetEvent.created_dagruns.length)}
80+
</Text>
81+
) : undefined}
82+
</>
83+
)}
84+
</Flex>
85+
</NodeWrapper>
86+
);
87+
};

airflow/ui/src/components/Graph/DagNode.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ export const DagNode = ({
4545
py={isSelected ? 0 : 1}
4646
width={`${width}px`}
4747
>
48-
<HStack alignItems="center" gap={1}>
48+
<HStack alignItems="center" justifyContent="space-between">
4949
<DagIcon />
50-
<Link asChild color="fg.info" mb={2}>
51-
<RouterLink to={`/dags/${dag?.dag_id ?? label}`}>{dag?.dag_display_name ?? label}</RouterLink>
52-
</Link>
50+
<TogglePause
51+
dagId={dag?.dag_id ?? label}
52+
disabled={!Boolean(dag)}
53+
isPaused={dag?.is_paused ?? false}
54+
/>
5355
</HStack>
54-
<TogglePause
55-
dagId={dag?.dag_id ?? label}
56-
disabled={!Boolean(dag)}
57-
isPaused={dag?.is_paused ?? false}
58-
/>
56+
<Link asChild color="fg.info" mb={2}>
57+
<RouterLink to={`/dags/${dag?.dag_id ?? label}`}>{dag?.dag_display_name ?? label}</RouterLink>
58+
</Link>
5959
</Flex>
6060
</NodeWrapper>
6161
);

0 commit comments

Comments
 (0)