bbovenzi commented on code in PR #64271: URL: https://github.com/apache/airflow/pull/64271#discussion_r3073739104
########## airflow-core/src/airflow/ui/src/components/GraphTaskFilters.tsx: ########## @@ -0,0 +1,220 @@ +/*! + * 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 { + Button, + IconButton, + type NumberInputValueChangeDetails, + Portal, + Separator, + Text, + VStack, +} from "@chakra-ui/react"; +import { useState } from "react"; +import { useHotkeys } from "react-hotkeys-hook"; +import { useTranslation } from "react-i18next"; +import { FiSearch } from "react-icons/fi"; +import { useParams, useSearchParams } from "react-router-dom"; + +import type { TaskInstanceState } from "openapi/requests/types.gen"; +import { AttrSelectFilterMulti } from "src/components/AttrSelectFilterMulti"; +import { StateBadge } from "src/components/StateBadge"; +import { Select } from "src/components/ui"; +import { Menu } from "src/components/ui/Menu"; +import { NumberInputField, NumberInputRoot } from "src/components/ui/NumberInput"; +import { SearchParamsKeys } from "src/constants/searchParams"; +import { taskInstanceStateOptions } from "src/constants/stateOptions"; +import { useGroups } from "src/context/groups"; + +export const GraphTaskFilters = () => { + const { t: translate } = useTranslation(["dag", "tasks"]); + const { runId } = useParams(); + const [searchParams, setSearchParams] = useSearchParams(); + + const { allGroupIds: allTaskGroups, allOperators } = useGroups(); + + const selectedOperators = searchParams.getAll(SearchParamsKeys.GRAPH_OPERATOR); + const selectedTaskGroups = searchParams.getAll(SearchParamsKeys.GRAPH_TASK_GROUP); + const selectedStates = searchParams.getAll(SearchParamsKeys.GRAPH_TASK_STATE); + const mapIndexParam = searchParams.get(SearchParamsKeys.GRAPH_MAP_INDEX) ?? ""; + const durationGteParam = searchParams.get(SearchParamsKeys.GRAPH_DURATION_GTE) ?? ""; + + const hasActiveFilters = + selectedOperators.length > 0 || + selectedTaskGroups.length > 0 || + selectedStates.length > 0 || + mapIndexParam !== "" || + durationGteParam !== ""; + + const stateItems = taskInstanceStateOptions.items.filter( + (item) => item.value !== "all" && item.value !== "none", + ); + + const handleMultiChange = (key: string) => (values: Array<string> | undefined) => { + searchParams.delete(key); + values?.forEach((val) => searchParams.append(key, val)); + setSearchParams(searchParams); + }; + + const handleNumberChange = + (key: string, condition: (n: number) => boolean) => (details: NumberInputValueChangeDetails) => { + if (condition(details.valueAsNumber)) { + searchParams.set(key, details.value); + } else { + searchParams.delete(key); + } + setSearchParams(searchParams); + }; + + const clearAllFilters = () => { + [ + SearchParamsKeys.GRAPH_OPERATOR, + SearchParamsKeys.GRAPH_TASK_GROUP, + SearchParamsKeys.GRAPH_TASK_STATE, + SearchParamsKeys.GRAPH_MAP_INDEX, + SearchParamsKeys.GRAPH_DURATION_GTE, + ].forEach((key) => searchParams.delete(key)); + setSearchParams(searchParams); + }; + + const [isOpen, setIsOpen] = useState(false); + + useHotkeys("mod+f", () => setIsOpen(true), { preventDefault: true }); Review Comment: Ok I realize this overrides all mod+f searches on the page. So we should scope this just to when the graph is in focus. Or change the hotkey -- 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]
