bbovenzi commented on code in PR #51667:
URL: https://github.com/apache/airflow/pull/51667#discussion_r2146971124


##########
airflow-core/src/airflow/ui/src/components/StatsDisplay.tsx:
##########
@@ -0,0 +1,79 @@
+/*!
+ * 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 { Box, GridItem, Heading, HStack, VStack } from "@chakra-ui/react";
+import { useState } from "react";
+import { MdInfoOutline } from "react-icons/md";
+
+import { Stat } from "src/components/Stat";
+import { Dialog } from "src/components/ui";
+
+import ActionButton from "./ui/ActionButton";
+
+const StatsDisplay = ({
+  isCompact = false,
+  stats,
+  title,
+}: {
+  readonly isCompact?: boolean;
+  readonly stats: Array<{ label: string; value: React.ReactNode | string }>;
+  readonly title?: string;
+}) => {
+  const [isOpen, setIsOpen] = useState(false);
+
+  if (isCompact) {
+    return (
+      <Box>
+        <ActionButton
+          actionName="Show stats"
+          icon={<MdInfoOutline />}
+          onClick={() => setIsOpen(true)}
+          text="Stats"
+          withText={false}
+        />
+        <Dialog.Root lazyMount onOpenChange={() => setIsOpen(false)} 
open={isOpen} size="md">
+          <Dialog.Content backdrop>
+            <Dialog.Header bg="blue.muted">
+              <Heading size="xl">{title ?? "Statistics"}</Heading>

Review Comment:
   Translation needed here as well



##########
airflow-core/src/airflow/ui/src/components/HeaderCard.tsx:
##########
@@ -33,24 +37,39 @@ type Props = {
   readonly title: ReactNode | string;
 };
 
-export const HeaderCard = ({ actions, icon, isRefreshing, state, stats, 
subTitle, title }: Props) => (
-  <Box borderColor="border" borderRadius={8} borderWidth={1} ml={2} p={2}>
-    <Flex alignItems="center" flexWrap="wrap" justifyContent="space-between" 
mb={2}>
-      <Flex alignItems="center" flexWrap="wrap" gap={2}>
-        <Heading size="xl">{icon}</Heading>
-        <Heading size="lg">{title}</Heading>
-        <Heading size="lg">{subTitle}</Heading>
-        {state === undefined ? undefined : <StateBadge 
state={state}>{state}</StateBadge>}
-        {isRefreshing ? <Spinner /> : <div />}
+export const HeaderCard = ({ actions, icon, isRefreshing, state, stats, 
subTitle, title }: Props) => {
+  const containerRef = useRef<HTMLDivElement>();
+  const containerWidth = useContainerWidth(containerRef);
+  const isGanttPage = useLocation().pathname.includes("/gantt");
+
+  return (
+    <Box
+      borderColor="border"
+      borderRadius={8}
+      borderWidth={1}
+      h={isGanttPage ? 52 : undefined}
+      ml={2}
+      overflow="auto"
+      p={2}
+      ref={containerRef}
+    >
+      <Flex alignItems="center" flexWrap="wrap" justifyContent="space-between" 
mb={2}>
+        <Flex alignItems="center" flexWrap="wrap" gap={2}>
+          <Heading size="xl">{icon}</Heading>
+          <Heading size="lg">{title}</Heading>
+          <Heading size="lg">{subTitle}</Heading>
+          {state === undefined ? undefined : <StateBadge 
state={state}>{state}</StateBadge>}
+          {isRefreshing ? <Spinner /> : <div />}
+        </Flex>
+        <Stack direction={isGanttPage && containerWidth <= 380 ? "row" : 
"column"} mt={2} w="100%">
+          <HStack gap={1}>{actions}</HStack>
+          <StatsDisplay

Review Comment:
   Nice call on moving it to an Info tooltip on small sizes.



##########
airflow-core/src/airflow/ui/src/components/StatsDisplay.tsx:
##########
@@ -0,0 +1,79 @@
+/*!
+ * 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 { Box, GridItem, Heading, HStack, VStack } from "@chakra-ui/react";
+import { useState } from "react";
+import { MdInfoOutline } from "react-icons/md";
+
+import { Stat } from "src/components/Stat";
+import { Dialog } from "src/components/ui";
+
+import ActionButton from "./ui/ActionButton";
+
+const StatsDisplay = ({
+  isCompact = false,
+  stats,
+  title,
+}: {
+  readonly isCompact?: boolean;
+  readonly stats: Array<{ label: string; value: React.ReactNode | string }>;
+  readonly title?: string;
+}) => {
+  const [isOpen, setIsOpen] = useState(false);
+
+  if (isCompact) {
+    return (
+      <Box>
+        <ActionButton
+          actionName="Show stats"
+          icon={<MdInfoOutline />}
+          onClick={() => setIsOpen(true)}
+          text="Stats"

Review Comment:
   Here too



##########
airflow-core/src/airflow/ui/src/components/StatsDisplay.tsx:
##########
@@ -0,0 +1,79 @@
+/*!
+ * 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 { Box, GridItem, Heading, HStack, VStack } from "@chakra-ui/react";
+import { useState } from "react";
+import { MdInfoOutline } from "react-icons/md";
+
+import { Stat } from "src/components/Stat";
+import { Dialog } from "src/components/ui";
+
+import ActionButton from "./ui/ActionButton";
+
+const StatsDisplay = ({
+  isCompact = false,
+  stats,
+  title,
+}: {
+  readonly isCompact?: boolean;
+  readonly stats: Array<{ label: string; value: React.ReactNode | string }>;
+  readonly title?: string;
+}) => {
+  const [isOpen, setIsOpen] = useState(false);
+
+  if (isCompact) {
+    return (
+      <Box>
+        <ActionButton
+          actionName="Show stats"

Review Comment:
   Translation needed



##########
airflow-core/src/airflow/ui/src/components/StatsDisplay.tsx:
##########
@@ -0,0 +1,79 @@
+/*!
+ * 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 { Box, GridItem, Heading, HStack, VStack } from "@chakra-ui/react";
+import { useState } from "react";
+import { MdInfoOutline } from "react-icons/md";
+
+import { Stat } from "src/components/Stat";
+import { Dialog } from "src/components/ui";
+
+import ActionButton from "./ui/ActionButton";
+
+const StatsDisplay = ({
+  isCompact = false,
+  stats,
+  title,
+}: {
+  readonly isCompact?: boolean;
+  readonly stats: Array<{ label: string; value: React.ReactNode | string }>;
+  readonly title?: string;
+}) => {
+  const [isOpen, setIsOpen] = useState(false);
+
+  if (isCompact) {
+    return (
+      <Box>
+        <ActionButton
+          actionName="Show stats"
+          icon={<MdInfoOutline />}
+          onClick={() => setIsOpen(true)}
+          text="Stats"
+          withText={false}
+        />
+        <Dialog.Root lazyMount onOpenChange={() => setIsOpen(false)} 
open={isOpen} size="md">

Review Comment:
   Do we need a full dialog? I feel like a 
[Popover](https://www.chakra-ui.com/docs/components/popover) is sufficient



##########
airflow-core/src/airflow/ui/src/components/HeaderCard.tsx:
##########
@@ -33,24 +37,39 @@ type Props = {
   readonly title: ReactNode | string;
 };
 
-export const HeaderCard = ({ actions, icon, isRefreshing, state, stats, 
subTitle, title }: Props) => (
-  <Box borderColor="border" borderRadius={8} borderWidth={1} ml={2} p={2}>
-    <Flex alignItems="center" flexWrap="wrap" justifyContent="space-between" 
mb={2}>
-      <Flex alignItems="center" flexWrap="wrap" gap={2}>
-        <Heading size="xl">{icon}</Heading>
-        <Heading size="lg">{title}</Heading>
-        <Heading size="lg">{subTitle}</Heading>
-        {state === undefined ? undefined : <StateBadge 
state={state}>{state}</StateBadge>}
-        {isRefreshing ? <Spinner /> : <div />}
+export const HeaderCard = ({ actions, icon, isRefreshing, state, stats, 
subTitle, title }: Props) => {
+  const containerRef = useRef<HTMLDivElement>();
+  const containerWidth = useContainerWidth(containerRef);
+  const isGanttPage = useLocation().pathname.includes("/gantt");

Review Comment:
   How does this look when switching tabs? It might be better to stay 
consistent and always change the header based on containerWidth



##########
airflow-core/src/airflow/ui/src/layouts/Details/Grid/GridTI.tsx:
##########
@@ -72,7 +72,7 @@ const Instance = ({ dagId, isGroup, isMapped, runId, search, 
state, taskId }: Pr
       <Link
         replace
         to={{
-          pathname: `/dags/${dagId}/runs/${runId}/tasks/${isGroup ? "group/" : 
""}${taskId}${isMapped ? "/mapped" : ""}`,
+          pathname: `/dags/${dagId}/runs/${runId}/tasks/${isGroup ? "group/" : 
""}${taskId}${isMapped ? "/mapped" : ""}/gantt`,

Review Comment:
   Let's drop `gantt` from here or let's make sure we persist whatever the 
selected tab is



##########
airflow-core/src/airflow/ui/src/layouts/Details/Gantt/Gantt.tsx:
##########
@@ -0,0 +1,210 @@
+/*!
+ * 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 { Box } from "@chakra-ui/react";
+import {
+  Chart as ChartJS,
+  CategoryScale,
+  LinearScale,
+  PointElement,
+  LineElement,
+  BarElement,
+  Filler,
+  Title,
+  Tooltip,
+  Legend,
+  TimeScale,
+} from "chart.js";
+import "chart.js/auto";
+import "chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm";
+import annotationPlugin from "chartjs-plugin-annotation";
+import dayjs from "dayjs";
+import { useMemo, useRef } from "react";
+import { Bar } from "react-chartjs-2";
+import { useTranslation } from "react-i18next";
+import { useParams } from "react-router-dom";
+
+import { useOpenGroups } from "src/context/openGroups";
+import { useTimezone } from "src/context/timezone";
+import { flattenNodes } from "src/layouts/Details/Grid/utils";
+import { useGrid } from "src/queries/useGrid";
+import { system } from "src/theme";
+import { getDuration } from "src/utils";
+
+ChartJS.register(
+  CategoryScale,
+  LinearScale,
+  PointElement,
+  BarElement,
+  LineElement,
+  Filler,
+  Title,
+  Tooltip,
+  Legend,
+  annotationPlugin,
+  TimeScale,
+);
+
+const CHART_PADDING = 38;
+const CHART_ROW_HEIGHT = 20;
+
+export const Gantt = () => {
+  const { groupId: selectedGroupId, runId, taskId: selectedTaskId } = 
useParams();
+  const { openGroupIds } = useOpenGroups();
+  const { t: translate } = useTranslation("common");
+  const { selectedTimezone } = useTimezone();
+  const ref = useRef();
+
+  const { data: gridData, isLoading } = useGrid();
+
+  const { flatNodes } = useMemo(
+    () => flattenNodes(gridData === undefined ? [] : gridData.structure.nodes, 
openGroupIds),
+    [gridData, openGroupIds],
+  );
+
+  const runs = gridData?.dag_runs ?? [];
+
+  const taskInstances = runs.find((run) => run.dag_run_id === 
runId)?.task_instances;
+
+  if (isLoading || taskInstances === undefined || runId === undefined) {
+    return undefined;
+  }
+
+  const validTaskInstances = flatNodes
+    .map((node) => taskInstances.find((ti) => ti.task_id === node.id))
+    .filter((ti) => ti !== undefined);
+
+  const data = validTaskInstances.map((taskInstance) => ({
+    state: taskInstance.state,
+    x: [
+      dayjs(taskInstance.start_date).tz(selectedTimezone).format("YYYY-MM-DD 
HH:mm:ss.SSS"),

Review Comment:
   Want to put the format as a const string at the top of the file or in 
datetimeUtils.ts? We repeat it a lot



##########
airflow-core/src/airflow/ui/src/pages/GroupTaskInstance/GroupTaskInstance.tsx:
##########
@@ -72,7 +73,10 @@ export const GroupTaskInstance = () => {
     .find((dr) => dr.dag_run_id === runId)
     ?.task_instances.find((ti) => ti.task_id === groupId);
 
-  const tabs = [{ icon: <MdOutlineTask />, label: "Task Instances", value: "" 
}];
+  const tabs = [
+    { icon: <MdOutlineTask />, label: "Task Instances", value: "" },
+    { icon: <LuChartGantt />, label: "Gantt", value: "gantt" },

Review Comment:
   Looks like we forgot to include translations here.



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