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


##########
airflow-core/src/airflow/ui/src/pages/DagsList/DagRunStateCounts.tsx:
##########
@@ -0,0 +1,87 @@
+/*!
+ * 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 { HStack, Skeleton } from "@chakra-ui/react";
+import { useTranslation } from "react-i18next";
+
+import type { DagRunState } from "openapi/requests/types.gen";
+import { StateBadge } from "src/components/StateBadge";
+import { RouterLink, Tooltip } from "src/components/ui";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+const DISPLAYED_STATES: ReadonlyArray<DagRunState> = ["success", "failed", 
"running", "queued"];
+
+type Props = {
+  readonly compact?: boolean;
+  readonly counts: Record<string, number> | undefined;
+  readonly dagId: string;
+  readonly isLoading: boolean;
+  readonly stateCountLimit: number | undefined;
+};
+
+export const DagRunStateCounts = ({ compact = false, counts, dagId, isLoading, 
stateCountLimit }: Props) => {
+  const { t: translate } = useTranslation(["dags", "common"]);
+  const gap = compact ? 0.5 : 1;
+  const fontSize = compact ? "xs" : "sm";
+
+  if (isLoading || counts === undefined) {
+    // Render skeletons sized to a typical badge so the row doesn't reflow when
+    // counts arrive. Rendering zeros while loading would mislead the operator.
+    return (
+      <HStack
+        aria-label={translate("runStateCounts.loading")}
+        data-testid={`run-state-counts-loading-${dagId}`}
+        gap={gap}
+      >
+        {DISPLAYED_STATES.map((state) => (
+          <Skeleton borderRadius="full" height="22px" key={state} width="44px" 
/>
+        ))}
+      </HStack>
+    );
+  }
+
+  return (
+    <HStack data-testid={`run-state-counts-${dagId}`} gap={gap}>
+      {DISPLAYED_STATES.map((state) => {
+        const count = counts[state] ?? 0;
+        // A count that reached the API cap is only a lower bound; suffix it 
with "+".
+        const isCapped = stateCountLimit !== undefined && count >= 
stateCountLimit;
+        const suffix = isCapped ? "+" : "";
+        const translatedState = translate(`common:states.${state}` as const);
+        const tooltipContent = translate("runStateCounts.tooltip", {
+          formattedCount: `${count}${suffix}`,
+          state: translatedState,
+        });
+
+        return (
+          <Tooltip content={tooltipContent} key={state}>
+            <RouterLink
+              aria-label={tooltipContent}
+              data-testid={`run-state-count-${state}-${dagId}`}
+              to={`/dags/${dagId}/runs?${SearchParamsKeys.STATE}=${state}`}
+            >
+              <StateBadge fontSize={fontSize} opacity={count === 0 ? 0.4 : 1} 
state={state}>
+                {`${count}${suffix}`}

Review Comment:
   The description mentions large counts in compact notation (1.2K / 1.5M), but 
this renders the raw capped count plus `+` (for example `1000+`). Update the 
description



##########
airflow-core/src/airflow/ui/src/pages/DagsList/DagRunStateCounts.tsx:
##########
@@ -0,0 +1,87 @@
+/*!
+ * 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 { HStack, Skeleton } from "@chakra-ui/react";
+import { useTranslation } from "react-i18next";
+
+import type { DagRunState } from "openapi/requests/types.gen";
+import { StateBadge } from "src/components/StateBadge";
+import { RouterLink, Tooltip } from "src/components/ui";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+const DISPLAYED_STATES: ReadonlyArray<DagRunState> = ["success", "failed", 
"running", "queued"];
+
+type Props = {
+  readonly compact?: boolean;
+  readonly counts: Record<string, number> | undefined;
+  readonly dagId: string;
+  readonly isLoading: boolean;
+  readonly stateCountLimit: number | undefined;
+};
+
+export const DagRunStateCounts = ({ compact = false, counts, dagId, isLoading, 
stateCountLimit }: Props) => {
+  const { t: translate } = useTranslation(["dags", "common"]);
+  const gap = compact ? 0.5 : 1;
+  const fontSize = compact ? "xs" : "sm";
+
+  if (isLoading || counts === undefined) {
+    // Render skeletons sized to a typical badge so the row doesn't reflow when
+    // counts arrive. Rendering zeros while loading would mislead the operator.
+    return (
+      <HStack
+        aria-label={translate("runStateCounts.loading")}
+        data-testid={`run-state-counts-loading-${dagId}`}
+        gap={gap}
+      >
+        {DISPLAYED_STATES.map((state) => (
+          <Skeleton borderRadius="full" height="22px" key={state} width="44px" 
/>
+        ))}
+      </HStack>
+    );
+  }
+
+  return (
+    <HStack data-testid={`run-state-counts-${dagId}`} gap={gap}>
+      {DISPLAYED_STATES.map((state) => {
+        const count = counts[state] ?? 0;
+        // A count that reached the API cap is only a lower bound; suffix it 
with "+".
+        const isCapped = stateCountLimit !== undefined && count >= 
stateCountLimit;
+        const suffix = isCapped ? "+" : "";
+        const translatedState = translate(`common:states.${state}` as const);
+        const tooltipContent = translate("runStateCounts.tooltip", {
+          formattedCount: `${count}${suffix}`,
+          state: translatedState,
+        });
+
+        return (
+          <Tooltip content={tooltipContent} key={state}>
+            <RouterLink
+              aria-label={tooltipContent}
+              data-testid={`run-state-count-${state}-${dagId}`}
+              to={`/dags/${dagId}/runs?${SearchParamsKeys.STATE}=${state}`}
+            >
+              <StateBadge fontSize={fontSize} opacity={count === 0 ? 0.4 : 1} 
state={state}>
+                {`${count}${suffix}`}

Review Comment:
   nit: The description mentions large counts in compact notation (1.2K / 
1.5M), but this renders the raw capped count plus `+` (for example `1000+`). 
Update the description



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