pierrejeambrun commented on code in PR #58059:
URL: https://github.com/apache/airflow/pull/58059#discussion_r2581249892
##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetGraph.tsx:
##########
@@ -29,15 +29,42 @@ import { useGraphLayout } from
"src/components/Graph/useGraphLayout";
import { useColorMode } from "src/context/colorMode";
import { useDependencyGraph } from "src/queries/useDependencyGraph";
import { getReactFlowThemeStyle } from "src/theme";
+import { getTaskLevelDependencies } from "src/utils/assetGraph";
-export const AssetGraph = ({ asset }: { readonly asset?: AssetResponse }) => {
+export const AssetGraph = ({
+ asset,
+ showDagLevelDependencies = true,
+ showTaskLevelDependencies = false,
+}: {
+ readonly asset?: AssetResponse;
+ readonly showDagLevelDependencies?: boolean;
+ readonly showTaskLevelDependencies?: boolean;
+}) => {
const { assetId } = useParams();
const { colorMode = "light" } = useColorMode();
- const { data = { edges: [], nodes: [] } } =
useDependencyGraph(`asset:${assetId}`);
+ const { data: dagLevelGraphData = { edges: [], nodes: [] } } =
useDependencyGraph(`asset:${assetId}`);
+ const taskLevelGraphData = getTaskLevelDependencies({ edges: [], nodes: []
}, asset);
+
+ const combinedGraphData = {
+ edges: [
+ ...(showDagLevelDependencies ? dagLevelGraphData.edges : []),
+ ...(showTaskLevelDependencies ? taskLevelGraphData.edges : []),
+ ],
+ nodes: [
+ // Always show the asset nodes from DAG level data
+ ...dagLevelGraphData.nodes.filter((node) => node.id ===
`asset:${assetId}`),
+ // Conditionally show dag nodes
+ ...(showDagLevelDependencies
+ ? dagLevelGraphData.nodes.filter((node) => node.id !==
`asset:${assetId}`)
+ : []),
+ // Conditionally show task nodes
+ ...(showTaskLevelDependencies ? taskLevelGraphData.nodes : []),
+ ],
+ };
Review Comment:
This probably shouldn't be done in the front-end.
Because here you'll get only 1 level depth of task dependencies I think. But
if we want to trace the whole `data` lineage, we probably need to call that on
neighbors tasks as well, to see the full dependency graph of `inlets/outlets`.
##########
airflow-core/src/airflow/ui/src/pages/Asset/AssetGraph.tsx:
##########
@@ -29,15 +29,42 @@ import { useGraphLayout } from
"src/components/Graph/useGraphLayout";
import { useColorMode } from "src/context/colorMode";
import { useDependencyGraph } from "src/queries/useDependencyGraph";
import { getReactFlowThemeStyle } from "src/theme";
+import { getTaskLevelDependencies } from "src/utils/assetGraph";
-export const AssetGraph = ({ asset }: { readonly asset?: AssetResponse }) => {
+export const AssetGraph = ({
+ asset,
+ showDagLevelDependencies = true,
+ showTaskLevelDependencies = false,
+}: {
+ readonly asset?: AssetResponse;
+ readonly showDagLevelDependencies?: boolean;
+ readonly showTaskLevelDependencies?: boolean;
+}) => {
const { assetId } = useParams();
const { colorMode = "light" } = useColorMode();
- const { data = { edges: [], nodes: [] } } =
useDependencyGraph(`asset:${assetId}`);
+ const { data: dagLevelGraphData = { edges: [], nodes: [] } } =
useDependencyGraph(`asset:${assetId}`);
+ const taskLevelGraphData = getTaskLevelDependencies({ edges: [], nodes: []
}, asset);
+
+ const combinedGraphData = {
+ edges: [
+ ...(showDagLevelDependencies ? dagLevelGraphData.edges : []),
+ ...(showTaskLevelDependencies ? taskLevelGraphData.edges : []),
+ ],
+ nodes: [
+ // Always show the asset nodes from DAG level data
+ ...dagLevelGraphData.nodes.filter((node) => node.id ===
`asset:${assetId}`),
+ // Conditionally show dag nodes
+ ...(showDagLevelDependencies
+ ? dagLevelGraphData.nodes.filter((node) => node.id !==
`asset:${assetId}`)
+ : []),
+ // Conditionally show task nodes
+ ...(showTaskLevelDependencies ? taskLevelGraphData.nodes : []),
+ ],
+ };
Review Comment:
This probably shouldn't be done in the front-end.
Because here you'll get only 1 level depth of task dependencies I think. But
if we want to trace the whole `data` lineage, we probably need to call that on
neighbors tasks as well, to see the full dependency graph of `inlets/outlets`
tasks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]