pierrejeambrun commented on code in PR #54484: URL: https://github.com/apache/airflow/pull/54484#discussion_r2290364695
########## airflow-core/src/airflow/ui/src/pages/Dag/Tasks/AttrSelectFilter.tsx: ########## @@ -0,0 +1,60 @@ +/*! + * 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 { type CollectionItem, createListCollection, type SelectValueChangeDetails } from "@chakra-ui/react"; Review Comment: It would be great to move everything related to 'filters' inside a `TaskFilter` folder within the `Dag/Tasks` one, and move everything related to it there, then only export the `TaskFilters`. Similarly to the DagsList folder, the `TaskFilters` is the only component needed. ########## airflow-core/src/airflow/ui/src/pages/Dag/Tasks/AttrSelectFilter.tsx: ########## @@ -0,0 +1,60 @@ +/*! + * 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 { type CollectionItem, createListCollection, type SelectValueChangeDetails } from "@chakra-ui/react"; Review Comment: <img width="208" height="275" alt="Screenshot 2025-08-21 at 10 52 07" src="https://github.com/user-attachments/assets/163e3dd0-d0b9-4c80-acbf-cd4686819ad3" /> So we would just have `TaskFilters` folder and `Tasks.tsx` for now in here. ########## airflow-core/src/airflow/ui/src/pages/Dag/Tasks/TaskFilters.tsx: ########## @@ -0,0 +1,135 @@ +/*! + * 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, HStack, Stack } from "@chakra-ui/react"; +import { useTranslation } from "react-i18next"; +import { useSearchParams } from "react-router-dom"; + +import type { TaskCollectionResponse } from "openapi/requests"; +import { SearchBar } from "src/components/SearchBar.tsx"; +import { ResetButton } from "src/components/ui"; +import { SearchParamsKeys } from "src/constants/searchParams.ts"; +import { AttrSelectFilter } from "src/pages/Dag/Tasks/AttrSelectFilter.tsx"; +import { AttrSelectFilterMulti } from "src/pages/Dag/Tasks/AttrSelectFilterMulti.tsx"; + +export const TaskFilters = ({ tasksData }: { readonly tasksData: TaskCollectionResponse | undefined }) => { + const { MAPPED, NAME_PATTERN, OPERATOR, RETRIES, TRIGGER_RULE } = SearchParamsKeys; + const { t: translate } = useTranslation(); + const [searchParams, setSearchParams] = useSearchParams(); + const selectedOperators = searchParams.getAll(OPERATOR); + const selectedTriggerRules = searchParams.getAll(TRIGGER_RULE); + const selectedRetries = searchParams.getAll(RETRIES); + const selectedMapped = searchParams.get(MAPPED) ?? undefined; + + const handleSelectedOperators = (value: Array<string> | undefined) => { + searchParams.delete(OPERATOR); + value?.forEach((x) => searchParams.append(OPERATOR, x)); + setSearchParams(searchParams); + }; + const handleSelectedRetries = (value: Array<string> | undefined) => { + searchParams.delete(RETRIES); + value?.forEach((x) => searchParams.append(RETRIES, x)); + setSearchParams(searchParams); + }; + const handleSelectedTriggerRules = (value: Array<string> | undefined) => { + searchParams.delete(TRIGGER_RULE); + value?.forEach((x) => searchParams.append(TRIGGER_RULE, x)); + setSearchParams(searchParams); + }; + const handleSelectedMapped = (value: string | undefined) => { + searchParams.delete(MAPPED); + if (value !== undefined) { + searchParams.set(MAPPED, value); + } + setSearchParams(searchParams); + }; + + const onClearFilters = () => { + setSearchParams(); + }; + + const allOperatorNames: Array<string> = [ + ...new Set(tasksData?.tasks.map((task) => task.operator_name).filter((item) => item !== null) ?? []), + ]; + const allTriggerRules: Array<string> = [ + ...new Set(tasksData?.tasks.map((task) => task.trigger_rule).filter((item) => item !== null) ?? []), + ]; + const allRetryValues: Array<string> = [ + ...new Set( + tasksData?.tasks.map((task) => task.retries?.toString()).filter((item) => item !== undefined) ?? [], + ), + ]; + const allMappedValues = [ + { key: "true", label: translate("mapped") }, + { key: "false", label: translate("notMapped") }, + ]; + const taskNamePattern = searchParams.get(NAME_PATTERN) ?? ""; + const handleSearchChange = (value: string) => { + if (value) { + searchParams.set(NAME_PATTERN, value); + } else { + searchParams.delete(NAME_PATTERN); + } + setSearchParams(searchParams); + }; + + return ( + <> + <HStack> + <SearchBar + defaultValue={taskNamePattern} + hideAdvanced={true} + onChange={handleSearchChange} + placeHolder={translate("searchTasks")} + /> + </HStack> + <Stack direction={{ base: "column", md: "row" }}> + <AttrSelectFilterMulti + displayPrefix={undefined} + handleSelect={handleSelectedOperators} + placeholderText={translate("selectOperator")} + selectedValues={selectedOperators} + values={allOperatorNames} + /> + <AttrSelectFilterMulti + displayPrefix={undefined} + handleSelect={handleSelectedTriggerRules} + placeholderText={translate("selectTriggerRules")} + selectedValues={selectedTriggerRules} + values={allTriggerRules} + /> + <AttrSelectFilterMulti + displayPrefix={translate("retries")} + handleSelect={handleSelectedRetries} + placeholderText={translate("selectRetryValues")} + selectedValues={selectedRetries} + values={allRetryValues} + /> + <AttrSelectFilter + handleSelect={handleSelectedMapped} + placeholderText={translate("selectMapped")} + selectedValue={selectedMapped} + values={allMappedValues} + /> + <Box> + <ResetButton filterCount={2} onClearFilters={onClearFilters} /> + </Box> + </Stack> Review Comment: The button parrent flexbox should `justifyContent="space-between"` for the button to align on the righ similarly to other pages <img width="1920" height="358" alt="Screenshot 2025-08-21 at 10 47 57" src="https://github.com/user-attachments/assets/39c2052d-2610-46a1-8c1a-279cccf90036" /> ########## airflow-core/src/airflow/ui/src/pages/Dag/Tasks/TaskFilters.tsx: ########## @@ -0,0 +1,135 @@ +/*! + * 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, HStack, Stack } from "@chakra-ui/react"; +import { useTranslation } from "react-i18next"; +import { useSearchParams } from "react-router-dom"; + +import type { TaskCollectionResponse } from "openapi/requests"; +import { SearchBar } from "src/components/SearchBar.tsx"; +import { ResetButton } from "src/components/ui"; +import { SearchParamsKeys } from "src/constants/searchParams.ts"; +import { AttrSelectFilter } from "src/pages/Dag/Tasks/AttrSelectFilter.tsx"; +import { AttrSelectFilterMulti } from "src/pages/Dag/Tasks/AttrSelectFilterMulti.tsx"; + +export const TaskFilters = ({ tasksData }: { readonly tasksData: TaskCollectionResponse | undefined }) => { + const { MAPPED, NAME_PATTERN, OPERATOR, RETRIES, TRIGGER_RULE } = SearchParamsKeys; + const { t: translate } = useTranslation(); + const [searchParams, setSearchParams] = useSearchParams(); + const selectedOperators = searchParams.getAll(OPERATOR); + const selectedTriggerRules = searchParams.getAll(TRIGGER_RULE); + const selectedRetries = searchParams.getAll(RETRIES); + const selectedMapped = searchParams.get(MAPPED) ?? undefined; + + const handleSelectedOperators = (value: Array<string> | undefined) => { + searchParams.delete(OPERATOR); + value?.forEach((x) => searchParams.append(OPERATOR, x)); + setSearchParams(searchParams); + }; + const handleSelectedRetries = (value: Array<string> | undefined) => { + searchParams.delete(RETRIES); + value?.forEach((x) => searchParams.append(RETRIES, x)); + setSearchParams(searchParams); + }; + const handleSelectedTriggerRules = (value: Array<string> | undefined) => { + searchParams.delete(TRIGGER_RULE); + value?.forEach((x) => searchParams.append(TRIGGER_RULE, x)); + setSearchParams(searchParams); + }; + const handleSelectedMapped = (value: string | undefined) => { + searchParams.delete(MAPPED); + if (value !== undefined) { + searchParams.set(MAPPED, value); + } + setSearchParams(searchParams); + }; + + const onClearFilters = () => { + setSearchParams(); + }; + + const allOperatorNames: Array<string> = [ + ...new Set(tasksData?.tasks.map((task) => task.operator_name).filter((item) => item !== null) ?? []), + ]; + const allTriggerRules: Array<string> = [ + ...new Set(tasksData?.tasks.map((task) => task.trigger_rule).filter((item) => item !== null) ?? []), + ]; + const allRetryValues: Array<string> = [ + ...new Set( + tasksData?.tasks.map((task) => task.retries?.toString()).filter((item) => item !== undefined) ?? [], + ), + ]; + const allMappedValues = [ + { key: "true", label: translate("mapped") }, + { key: "false", label: translate("notMapped") }, + ]; + const taskNamePattern = searchParams.get(NAME_PATTERN) ?? ""; + const handleSearchChange = (value: string) => { + if (value) { + searchParams.set(NAME_PATTERN, value); + } else { + searchParams.delete(NAME_PATTERN); + } + setSearchParams(searchParams); + }; + + return ( + <> + <HStack> + <SearchBar + defaultValue={taskNamePattern} + hideAdvanced={true} + onChange={handleSearchChange} + placeHolder={translate("searchTasks")} + /> + </HStack> + <Stack direction={{ base: "column", md: "row" }}> + <AttrSelectFilterMulti + displayPrefix={undefined} + handleSelect={handleSelectedOperators} + placeholderText={translate("selectOperator")} + selectedValues={selectedOperators} + values={allOperatorNames} + /> + <AttrSelectFilterMulti + displayPrefix={undefined} + handleSelect={handleSelectedTriggerRules} + placeholderText={translate("selectTriggerRules")} + selectedValues={selectedTriggerRules} + values={allTriggerRules} + /> + <AttrSelectFilterMulti + displayPrefix={translate("retries")} + handleSelect={handleSelectedRetries} + placeholderText={translate("selectRetryValues")} + selectedValues={selectedRetries} + values={allRetryValues} + /> + <AttrSelectFilter + handleSelect={handleSelectedMapped} + placeholderText={translate("selectMapped")} + selectedValue={selectedMapped} + values={allMappedValues} + /> + <Box> + <ResetButton filterCount={2} onClearFilters={onClearFilters} /> + </Box> + </Stack> Review Comment: Why do we hardcode `2` here? Resetfilter buttons is always appearing even when no filters are selected (clicking on it has no effect). -- 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]
