You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ashb (via GitHub)" <gi...@apache.org> on 2023/02/23 16:37:36 UTC

[GitHub] [airflow] ashb commented on a diff in pull request #29413: Add a new graph inside of the grid view

ashb commented on code in PR #29413:
URL: https://github.com/apache/airflow/pull/29413#discussion_r1115866839


##########
airflow/www/static/js/dag/details/graph/Node.tsx:
##########
@@ -0,0 +1,156 @@
+/*!
+ * 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 React from 'react';
+import {
+  Box,
+  Text,
+  Flex,
+} from '@chakra-ui/react';
+import { Handle, NodeProps, Position } from 'reactflow';
+
+import { SimpleStatus } from 'src/dag/StatusBox';
+import useSelection from 'src/dag/useSelection';
+import type { DagRun, Task, TaskInstance } from 'src/types';
+import { finalStatesMap, hoverDelay } from 'src/utils';
+import Tooltip from 'src/components/Tooltip';
+import InstanceTooltip from 'src/dag/InstanceTooltip';
+import { useContainerRef } from 'src/context/containerRef';
+
+export interface CustomNodeProps {
+  label: string;
+  height?: number;
+  width?: number;
+  isJoinNode?: boolean;
+  instance?: TaskInstance;
+  task?: Task | null;
+  isSelected: boolean;
+  latestDagRunId: DagRun['runId'];
+  childCount?: number;
+  onToggleCollapse: () => void;
+  isOpen?: boolean;
+}
+
+const Node = ({
+  id,
+  data: {
+    label,
+    childCount,
+    height,
+    width,
+    isJoinNode,
+    instance,
+    task,
+    isSelected,
+    latestDagRunId,
+    onToggleCollapse,
+    isOpen,
+  },
+}: NodeProps<CustomNodeProps>) => {
+  const { onSelect } = useSelection();
+  const containerRef = useContainerRef();
+
+  if (isJoinNode) {
+    return (
+      <>
+        <Handle type="target" position={Position.Top} style={{ visibility: 'hidden' }} />
+        <Box height={`${height}px`} width={`${width}px`} borderRadius={width} bg="gray.400" />
+        <Handle type="source" position={Position.Bottom} style={{ visibility: 'hidden' }} />
+      </>
+    );
+  }
+
+  const isMapped = task?.isMapped;
+  const mappedStates = instance?.mappedStates;
+
+  const numMap = finalStatesMap();
+  let numMapped = 0;
+
+  if (isMapped && mappedStates) {
+    Object.keys(mappedStates).forEach((stateKey) => {
+      const num = mappedStates[stateKey];
+      numMapped += num;
+      numMap.set(stateKey || 'no_status', num);
+    });

Review Comment:
   This feels general purpose/like I've seen it somewhere else before. Should this be pulled out in to a common function somewhere?



##########
airflow/www/static/js/dag/details/graph/Edge.tsx:
##########
@@ -0,0 +1,66 @@
+/*!
+ * 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 React from 'react';
+import { Text } from '@chakra-ui/react';
+import type {
+  ElkEdgeSection, ElkLabel, ElkPoint, LayoutOptions,
+} from 'elkjs';
+
+import Edge from 'src/datasets/Graph/Edge';
+import { Group } from '@visx/group';
+
+interface EdgeProps {
+  data?: {
+    rest: {
+      isSelected: boolean | '' | null;

Review Comment:
   What's the reason we allow all three of these types here?



##########
airflow/www/static/js/dag/details/graph/utils.ts:
##########
@@ -0,0 +1,116 @@
+/*!
+ * 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 Color from 'color';
+import type {
+  Node as ReactFlowNode,
+} from 'reactflow';
+import type { ElkExtendedEdge } from 'elkjs';
+
+import type { CustomNodeProps } from './Node';
+
+export const nodeColor = (
+  { data: { height, width, instance } }: ReactFlowNode<CustomNodeProps>,
+) => {
+  if (!height || !width) return '';
+  if (width > 200 || height > 60) {
+    return '#cccccc50';
+  }
+  if (instance?.state) {
+    return `${Color(stateColors[instance.state]).hex()}90`;
+  }
+  return '#cccccc90';
+};
+
+export const nodeStrokeColor = (
+  { data: { isSelected } }: ReactFlowNode<CustomNodeProps>,
+  colors: any,
+) => (isSelected ? colors.blue[500] : '');
+
+interface BuildEdgesProps {
+  edges?: ElkExtendedEdge[];
+  nodes: ReactFlowNode<CustomNodeProps>[];
+  taskId?: string | null;
+}
+
+export const buildEdges = ({

Review Comment:
   Nit: should this instead by in `graph/Edge.tsx`?



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org