yuseok89 commented on code in PR #70470:
URL: https://github.com/apache/airflow/pull/70470#discussion_r4138931709


##########
airflow-core/src/airflow/ui/src/components/FilterBar/filters/RunStateFilter.tsx:
##########
@@ -0,0 +1,234 @@
+/*!
+ * 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 { useRef, useState } from "react";
+
+import { Box, HStack, createListCollection } from "@chakra-ui/react";
+import { useTranslation } from "react-i18next";
+import { FiClock, FiZap } from "react-icons/fi";
+
+import { Select } from "src/system-components";
+
+import { FilterPill } from "../FilterPill";
+import type { FilterConfig, FilterPluginProps } from "../types";
+import { RUN_STATE_LOOKBACKS, isRunStateValue, type RunStateLookback } from 
"./runStateParams";
+
+const LOOKBACK_LABEL_KEYS: Record<RunStateLookback, string> = {
+  "24": "last24Hours",
+  "168": "last7Days",
+  "720": "last30Days",
+  any: "anyTime",
+  latest: "latestRun",
+};
+
+type SelectOption = {
+  label: string;
+  value: string;
+};
+
+type RunStateFilterConfig = {
+  options: Array<SelectOption>;
+};
+
+const collapsePill = () => {
+  setTimeout(() => {
+    const activeElement = document.activeElement as HTMLElement;
+
+    activeElement.blur();
+  }, 0);
+};
+
+/**
+ * One pill filtering Dags on a run state matched within a lookback: the 
latest run only, a
+ * recent time window, or the whole run history. Committed as a composite 
value that the
+ * config's projections spread over the underlying URL params.
+ */
+export const RunStateFilter = ({ filter, onChange, onRemove }: 
FilterPluginProps) => {
+  const { t: translate } = useTranslation(["common"]);
+  const config = filter.config as FilterConfig & RunStateFilterConfig;
+  const value = isRunStateValue(filter.value) ? filter.value : undefined;
+
+  // Holds a lookback picked before any state is chosen, when there is nothing 
to commit yet.
+  const [pendingLookback, setPendingLookback] = 
useState<RunStateLookback>(value?.lookback ?? "latest");
+
+  // Selecting an option closes the menu in the same tick as the value 
commits, before React has
+  // re-rendered. Recording the selection keeps the close from being mistaken 
for an abandoned
+  // filter, which a timing-based check gets wrong.
+  const hasJustSelected = useRef(false);
+
+  const handleStateChange = ({ value: selected }: { value: Array<string> }) => 
{
+    const [newState] = selected;
+
+    if (newState === undefined) {
+      return;
+    }
+    hasJustSelected.current = true;
+    onChange({ lookback: value?.lookback ?? pendingLookback, state: newState 
});
+    collapsePill();
+  };
+
+  const handleLookbackChange = ({ value: selected }: { value: Array<string> }) 
=> {
+    const [newLookback] = selected as Array<RunStateLookback>;

Review Comment:
   Done, thanks!
   I used a `Set` for the guards instead of `.some(...)`.
   Our `prefer-includes` lint rule autofixes `.some((lookback) => lookback === 
value)` into `.includes(value)`, which then fails type checking since `value` 
is a `string`.



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