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


##########
airflow-core/src/airflow/ui/src/pages/Dag/Calendar/Calendar.tsx:
##########
@@ -0,0 +1,280 @@
+/*!
+ * 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, HStack, Text, IconButton, Button, ButtonGroup } from 
"@chakra-ui/react";
+import { keyframes } from "@emotion/react";
+import dayjs from "dayjs";
+import { useState, useMemo } from "react";
+import { useTranslation } from "react-i18next";
+import { FiMinus, FiPlus, FiChevronLeft, FiChevronRight } from 
"react-icons/fi";
+import { useParams } from "react-router-dom";
+import { useLocalStorage } from "usehooks-ts";
+
+import { useCalendarServiceGetCalendar } from "openapi/queries";
+import { ErrorAlert } from "src/components/ErrorAlert";
+
+import { CalendarLegend } from "./CalendarLegend";
+import { DailyCalendarView } from "./DailyCalendarView";
+import { HourlyCalendarView } from "./HourlyCalendarView";
+
+const spin = keyframes`
+  from { transform: rotate(0deg); }
+  to { transform: rotate(360deg); }
+`;
+
+export const Calendar = () => {
+  const { dagId = "" } = useParams();
+  const { t: translate } = useTranslation("dag");
+  const [cellSize, setCellSize] = useLocalStorage("calendar-cell-size", 18);
+  const [selectedDate, setSelectedDate] = useState(dayjs());
+  const [granularity, setGranularity] = useLocalStorage<"daily" | 
"hourly">("calendar-granularity", "daily");
+
+  const currentDate = dayjs();
+
+  const dateRange = useMemo(() => {
+    if (granularity === "daily") {
+      const yearStart = selectedDate.startOf("year");
+      const yearEnd = selectedDate.endOf("year");
+
+      return {
+        logicalDateGte: yearStart.format("YYYY-MM-DD[T]HH:mm:ss[Z]"),
+        logicalDateLte: yearEnd.format("YYYY-MM-DD[T]HH:mm:ss[Z]"),
+      };
+    } else {
+      const monthStart = selectedDate.startOf("month");
+      const monthEnd = selectedDate.endOf("month");
+
+      return {
+        logicalDateGte: monthStart.format("YYYY-MM-DD[T]HH:mm:ss[Z]"),
+        logicalDateLte: monthEnd.format("YYYY-MM-DD[T]HH:mm:ss[Z]"),
+      };
+    }
+  }, [granularity, selectedDate]);
+
+  const { data, error, isLoading } = useCalendarServiceGetCalendar(
+    {
+      dagId,
+      granularity,
+      ...dateRange,
+    },
+    undefined,
+    { enabled: Boolean(dagId) },
+  );
+
+  if (!data && !isLoading) {
+    return (
+      <Box p={4}>
+        <Text>{translate("calendar.noData")}</Text>
+      </Box>
+    );
+  }
+
+  return (
+    <Box p={6}>
+      <ErrorAlert error={error} />
+      <HStack justify="space-between" mb={6}>
+        <HStack gap={4}>
+          {granularity === "daily" ? (
+            <HStack gap={2}>
+              <IconButton
+                aria-label="Previous year"
+                onClick={() => setSelectedDate(selectedDate.subtract(1, 
"year"))}
+                size="sm"
+                variant="ghost"
+              >
+                <FiChevronLeft />
+              </IconButton>
+              <Text
+                _hover={selectedDate.year() === currentDate.year() ? {} : { 
textDecoration: "underline" }}
+                color={selectedDate.year() === currentDate.year() ? "fg.info" 
: "inherit"}
+                cursor={selectedDate.year() === currentDate.year() ? "default" 
: "pointer"}
+                fontSize="xl"
+                fontWeight="bold"
+                minWidth="120px"
+                onClick={() => {
+                  if (selectedDate.year() !== currentDate.year()) {
+                    setSelectedDate(currentDate.startOf("year"));
+                  }
+                }}
+                textAlign="center"
+              >
+                {selectedDate.year()}
+              </Text>
+              <IconButton
+                aria-label="Next year"

Review Comment:
   Let's translate all the aria-labels



##########
airflow-core/src/airflow/ui/src/pages/Dag/Calendar/Calendar.tsx:
##########
@@ -0,0 +1,280 @@
+/*!
+ * 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, HStack, Text, IconButton, Button, ButtonGroup } from 
"@chakra-ui/react";
+import { keyframes } from "@emotion/react";
+import dayjs from "dayjs";
+import { useState, useMemo } from "react";
+import { useTranslation } from "react-i18next";
+import { FiMinus, FiPlus, FiChevronLeft, FiChevronRight } from 
"react-icons/fi";
+import { useParams } from "react-router-dom";
+import { useLocalStorage } from "usehooks-ts";
+
+import { useCalendarServiceGetCalendar } from "openapi/queries";
+import { ErrorAlert } from "src/components/ErrorAlert";
+
+import { CalendarLegend } from "./CalendarLegend";
+import { DailyCalendarView } from "./DailyCalendarView";
+import { HourlyCalendarView } from "./HourlyCalendarView";
+
+const spin = keyframes`
+  from { transform: rotate(0deg); }
+  to { transform: rotate(360deg); }
+`;
+
+export const Calendar = () => {
+  const { dagId = "" } = useParams();
+  const { t: translate } = useTranslation("dag");
+  const [cellSize, setCellSize] = useLocalStorage("calendar-cell-size", 18);
+  const [selectedDate, setSelectedDate] = useState(dayjs());
+  const [granularity, setGranularity] = useLocalStorage<"daily" | 
"hourly">("calendar-granularity", "daily");
+
+  const currentDate = dayjs();
+
+  const dateRange = useMemo(() => {
+    if (granularity === "daily") {
+      const yearStart = selectedDate.startOf("year");
+      const yearEnd = selectedDate.endOf("year");
+
+      return {
+        logicalDateGte: yearStart.format("YYYY-MM-DD[T]HH:mm:ss[Z]"),
+        logicalDateLte: yearEnd.format("YYYY-MM-DD[T]HH:mm:ss[Z]"),
+      };
+    } else {
+      const monthStart = selectedDate.startOf("month");
+      const monthEnd = selectedDate.endOf("month");
+
+      return {
+        logicalDateGte: monthStart.format("YYYY-MM-DD[T]HH:mm:ss[Z]"),
+        logicalDateLte: monthEnd.format("YYYY-MM-DD[T]HH:mm:ss[Z]"),
+      };
+    }
+  }, [granularity, selectedDate]);
+
+  const { data, error, isLoading } = useCalendarServiceGetCalendar(
+    {
+      dagId,
+      granularity,
+      ...dateRange,
+    },
+    undefined,
+    { enabled: Boolean(dagId) },
+  );
+
+  if (!data && !isLoading) {
+    return (
+      <Box p={4}>
+        <Text>{translate("calendar.noData")}</Text>
+      </Box>
+    );
+  }
+
+  return (
+    <Box p={6}>
+      <ErrorAlert error={error} />
+      <HStack justify="space-between" mb={6}>
+        <HStack gap={4}>
+          {granularity === "daily" ? (
+            <HStack gap={2}>
+              <IconButton
+                aria-label="Previous year"

Review Comment:
   Translation needed



##########
airflow-core/src/airflow/ui/src/pages/Dag/Calendar/DailyCalendarView.tsx:
##########
@@ -0,0 +1,129 @@
+/*!
+ * 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.
+ */
+
+/*
+ * 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, Text } from "@chakra-ui/react";
+import dayjs from "dayjs";
+
+import type { CalendarTimeRangeResponse } from "openapi/requests/types.gen";
+
+import { CalendarTooltip } from "./CalendarTooltip";
+import { createTooltipContent, generateDailyCalendarData, getCalendarCellColor 
} from "./calendarUtils";
+import { useDelayedTooltip } from "./useDelayedTooltip";
+
+type Props = {
+  readonly cellSize: number;
+  readonly data: Array<CalendarTimeRangeResponse>;
+  readonly selectedYear: number;
+};
+
+export const DailyCalendarView = ({ cellSize, data, selectedYear }: Props) => {
+  const dailyData = generateDailyCalendarData(data, selectedYear);
+  const { handleMouseEnter, handleMouseLeave } = useDelayedTooltip();
+
+  return (
+    <Box mb={4}>
+      <Box display="flex" mb={2}>
+        <Box width="50px" />
+        <Box display="flex" gap={1}>
+          {dailyData.map((week, index) => (
+            <Box key={`month-${week[0]?.date ?? index}`} position="relative" 
width={`${cellSize}px`}>
+              {Boolean(week[0] && dayjs(week[0].date).date() <= 7) && (
+                <Text color="fg.muted" fontSize="xs" left="0" 
position="absolute" top="-20px">
+                  {dayjs(week[0]?.date).format("MMM")}
+                </Text>
+              )}
+            </Box>
+          ))}
+        </Box>
+      </Box>
+      <Box display="flex" gap={2}>
+        <Box display="flex" flexDirection="column" gap={1}>
+          {["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"].map((day) => (

Review Comment:
   Should days be translated?



##########
airflow-core/src/airflow/ui/public/i18n/locales/en/dag.json:
##########
@@ -5,6 +5,26 @@
     "reason": "Reason",
     "title": "Dependencies Blocking Task From Getting Scheduled"
   },
+  "calendar": {
+    "cellSize": "Cell Size",
+    "daily": "Daily",
+    "decreaseSize": "Decrease size",
+    "hourly": "Hourly",
+    "increaseSize": "Increase size",
+    "legend": {
+      "successRateSpectrum": "Success Rate Spectrum",
+      "tooltips": {
+        "failed": "Less than 20% Success",
+        "success100": "100% Success",
+        "successRate20": "20%+ Success Rate",
+        "successRate40": "40%+ Success Rate",
+        "successRate60": "60%+ Success Rate",
+        "successRate80": "80%+ Success Rate"

Review Comment:
   I wonder if we want to pass the number into the translation so its easier to 
change the values in the future without new translations



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