bbovenzi commented on code in PR #54722: URL: https://github.com/apache/airflow/pull/54722#discussion_r2342052397
########## airflow-core/src/airflow/ui/src/components/FilterTaskButton.tsx: ########## @@ -0,0 +1,122 @@ +/*! + * 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 { useTranslation } from "react-i18next"; +import { MdFilterList } from "react-icons/md"; +import { useSearchParams, useParams } from "react-router-dom"; + +import { Menu } from "src/components/ui"; +import { Button } from "src/components/ui"; +import ActionButton from "src/components/ui/ActionButton"; + +const FILTER_PARAM = "task_filter"; + +const OPTIONS = [ + { buttonKey: "taskFilter.button_all", itemKey: "taskFilter.all", value: "all" }, + { buttonKey: "taskFilter.upstream", itemKey: "taskFilter.upstream", value: "upstream" }, + { buttonKey: "taskFilter.downstream", itemKey: "taskFilter.downstream", value: "downstream" }, + { buttonKey: "taskFilter.both", itemKey: "taskFilter.both", value: "both" }, +] as const; + +type FilterValue = (typeof OPTIONS)[number]["value"]; + +type Props = { + readonly withText?: boolean; +}; + +const FilterTaskButton = ({ withText = true }: Props) => { + const { t: translate } = useTranslation("components"); + const [searchParams, setSearchParams] = useSearchParams(); + const { taskId } = useParams<{ taskId?: string }>(); + + const rawFilter = searchParams.get(FILTER_PARAM) as FilterValue | null; + const currentFilter = rawFilter ?? "all"; + + const isActiveForThisTask = currentFilter !== "all"; + + const handleSelect = (value: FilterValue) => { + const next = new URLSearchParams(searchParams.toString()); + + if (value === "all") { + next.delete(FILTER_PARAM); + } else { + if (taskId === undefined) { + return; // optional: show tooltip instead + } + next.set(FILTER_PARAM, value); + } + + setSearchParams(next, { replace: true }); + }; + + const selectedOption = OPTIONS.find((opt) => opt.value === currentFilter) ?? OPTIONS[0]; + const buttonLabel = translate(selectedOption.buttonKey); + + return ( + <Box display="inline-block" position="relative"> + <Menu.Root positioning={{ gutter: 0, placement: "bottom" }}> + <Menu.Trigger asChild> + <Box position="relative"> + <ActionButton + actionName={`${translate("taskFilter.action_prefix", { defaultValue: "Filter" })}: ${buttonLabel}`} + flexDirection="row-reverse" + icon={<MdFilterList />} + text={buttonLabel} + withText={withText} + /> + {isActiveForThisTask ? ( + <Box + bg="blue.500" Review Comment: We should use a semantic token here instead of hard coding blue.500 ########## airflow-core/src/airflow/ui/public/i18n/locales/en/components.json: ########## @@ -94,6 +94,14 @@ "sortedAscending": "sorted ascending", "sortedDescending": "sorted descending", "sortedUnsorted": "unsorted", + "taskFilter": { + "action_prefix": "Filter", + "all": "All", + "both": "Both upstream & downstream", + "button_all": "Filter DAG by task", + "downstream": "Only downstream", + "upstream": "Only upstream" + }, Review Comment: This is after translation freeze. You should post this PR in the i18n channel of the Airflow Slack. ########## airflow-core/src/airflow/ui/src/pages/TaskInstance/Header.tsx: ########## @@ -119,6 +120,7 @@ export const Header = ({ taskInstance={taskInstance} withText={containerWidth > 700} /> + <FilterTaskButton withText={containerWidth > 700} /> Review Comment: We should change this hardcode value now that there are so many buttons. Do you mind making it `const HEADER_BREAKPOINT = 1000;`? -- 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]
