-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Feature(UI) : Add upstream/downstream task filtering in Graph & Grid views (#53458) #54722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d211557
8790152
80c6c02
7a87108
7a6e1f7
6ce4be5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
| }, | ||
|
Comment on lines
+97
to
+104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is after translation freeze. You should post this PR in the i18n channel of the Airflow Slack. |
||
| "taskTries": "Task Tries", | ||
| "toggleCardView": "Show card view", | ||
| "toggleTableView": "Show table view", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use a semantic token here instead of hard coding blue.500 |
||
| borderRadius="full" | ||
| height={2.5} | ||
| position="absolute" | ||
| right={1} // adjust to align correctly | ||
| top={1} // adjust to align correctly | ||
| width={2.5} | ||
| /> | ||
| ) : undefined} | ||
| </Box> | ||
| </Menu.Trigger> | ||
|
|
||
| <Menu.Content> | ||
| {OPTIONS.map((option) => ( | ||
| <Menu.Item | ||
| asChild | ||
| disabled={currentFilter === option.value} | ||
| key={option.value} | ||
| value={option.value} | ||
| > | ||
| <Button | ||
| justifyContent="start" | ||
| onClick={() => handleSelect(option.value)} | ||
| size="sm" | ||
| variant="ghost" | ||
| width="100%" | ||
| > | ||
| {translate(option.itemKey)} | ||
| </Button> | ||
| </Menu.Item> | ||
| ))} | ||
| </Menu.Content> | ||
| </Menu.Root> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default FilterTaskButton; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.