You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/10/20 20:11:14 UTC
[GitHub] [airflow] ryanahamilton commented on a change in pull request #18675: New Tree View
ryanahamilton commented on a change in pull request #18675:
URL: https://github.com/apache/airflow/pull/18675#discussion_r733109746
##########
File path: airflow/www/static/js/tree/Tree.jsx
##########
@@ -0,0 +1,202 @@
+/*!
+ * 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.
+ */
+
+/* global localStorage */
+
+import React, { useRef, useState } from 'react';
+import {
+ Flex,
+ Box,
+ Text,
+ useDisclosure,
+ Collapse,
+ Switch,
+ FormControl,
+ FormLabel,
+ Spinner,
+} from '@chakra-ui/react';
+import { FiChevronUp, FiChevronDown } from 'react-icons/fi';
+
+import useTreeData from './useTreeData';
+import StatusBox from './StatusBox';
+import DagRunBar from './DagRunBar';
+import getMetaValue from '../meta_value';
+import { getDuration, formatDuration } from './utils';
+
+// dagId comes from dag.html
+const dagId = getMetaValue('dag_id');
+
+const DurationTick = ({ children, ...rest }) => (
+ <Text fontSize={10} color="gray.400" position="absolute" left="calc(100% + 6px)" whiteSpace="nowrap" {...rest}>
+ {children}
+ </Text>
+);
+
+const Tree = () => {
+ const containerRef = useRef();
+ const { data, refreshOn, onToggleRefresh } = useTreeData();
+ const { groups = [], dagRuns = [] } = data;
+ const durations = [];
+ const runs = dagRuns.map((dagRun) => {
+ const duration = getDuration(dagRun.startDate, dagRun.endDate);
+ durations.push(duration);
+ return {
+ ...dagRun,
+ duration,
+ };
+ });
+
+ // calculate dag run bar heights relative to max
+ const max = Math.max.apply(null, durations);
+
+ const renderGroup = (prevGroup, level) => prevGroup.children.map((group) => (
+ <TaskGroup key={group.id} group={group} level={level} prevGroup={prevGroup.id} />
+ ));
+
+ const TaskGroup = ({ prevGroup, group, level }) => {
+ const isGroup = !!group.children;
+
+ const storageKey = `${dagId}-open-groups`;
+ const openGroups = JSON.parse(localStorage.getItem(storageKey)) || [];
+ const isGroupId = openGroups.some((g) => g === group.id);
+
+ const onOpen = () => {
+ localStorage.setItem(storageKey, JSON.stringify([...openGroups, group.id]));
+ };
+ const onClose = () => {
+ localStorage.setItem(storageKey, JSON.stringify(openGroups.filter((g) => g !== group.id)));
+ };
+
+ const { isOpen, onToggle } = useDisclosure({ defaultIsOpen: isGroupId, onClose, onOpen });
+ const [isHover, setHover] = useState(false);
+ // Show only the immediate task id
+ const taskName = group.id.replace(`${prevGroup}.`, '');
+
+ return (
+ <Box backgroundColor={`rgba(203, 213, 224, ${0.25 * level})`}>
+ <Flex
+ justifyContent="space-between"
+ alignItems="center"
+ width="100%"
+ py="1px"
+ borderBottomWidth={1}
+ borderBottomColor={level > 1 ? 'white' : 'gray.200'}
+ backgroundColor={isHover && 'rgba(113, 128, 150, 0.1)'}
+ onMouseEnter={() => setHover(true)}
+ onMouseLeave={() => setHover(false)}
+ >
+ <Flex
+ as={isGroup ? 'button' : 'div'}
+ onClick={() => isGroup && onToggle()}
+ color={(level > 4 || (isHover && level > 3)) && 'white'}
Review comment:
Wondering if you could avoid the `isHover` state with something like this?
```suggestion
role="group"
_hover={{ backgroundColor: 'rgba(113, 128, 150, 0.1'}}
>
<Flex
as={isGroup ? 'button' : 'div'}
onClick={() => isGroup && onToggle()}
color={level > 4 ? 'white' : undefined}
_groupHover={level > 3 && {
color: 'white',
}}
```
##########
File path: airflow/www/static/js/tree/DagRunTooltip.jsx
##########
@@ -0,0 +1,102 @@
+/*!
+ * 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.
+ */
+
+/* global moment */
+
+import React from 'react';
+import { Box, Text } from '@chakra-ui/react';
+import { MdPlayArrow } from 'react-icons/md';
+
+import { formatDateTime } from '../datetime_utils';
+import { formatDuration } from './utils';
+
+const DagRunTooltip = ({
+ dagRun: {
+ state, runId, duration, dataIntervalStart, dataIntervalEnd, startDate, endDate, runType,
+ },
+}) => (
+ <Box fontSize={12}>
+ <br />
Review comment:
Are the `<br />`s at the top and bottom necessary? If you do want extra spacing, maybe add `py={4}` to the parent `Box` instead?
--
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