pierrejeambrun commented on code in PR #58059:
URL: https://github.com/apache/airflow/pull/58059#discussion_r2581232914


##########
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:
   All that logic should probably be done in the backend, what do you think ?
   
   (We do something similar when resolving asset aliases and downstream assets) 
for structure_data endpoint https://github.com/apache/airflow/pull/51401/files



-- 
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]

Reply via email to