RoyLee1224 commented on code in PR #54049: URL: https://github.com/apache/airflow/pull/54049#discussion_r2267002317
########## airflow-core/src/airflow/ui/src/pages/XCom/XComFilters.tsx: ########## @@ -0,0 +1,180 @@ +/*! + * 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, Button, HStack, Text, VStack } from "@chakra-ui/react"; +import { useCallback, useMemo, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { LuX } from "react-icons/lu"; +import { useSearchParams } from "react-router-dom"; + +import { useTableURLState } from "src/components/DataTable/useTableUrlState"; +import { DateTimeInput } from "src/components/DateTimeInput"; +import { SearchBar } from "src/components/SearchBar"; +import { SearchParamsKeys } from "src/constants/searchParams"; + +const FILTERS = [ + { + hotkeyDisabled: false, + key: SearchParamsKeys.KEY_PATTERN, + translationKey: "keyPlaceholder", + type: "search", + }, + { + hotkeyDisabled: true, + key: SearchParamsKeys.DAG_DISPLAY_NAME_PATTERN, + translationKey: "dagDisplayNamePlaceholder", + type: "search", + }, + { + hotkeyDisabled: true, + key: SearchParamsKeys.RUN_ID_PATTERN, + translationKey: "runIdPlaceholder", + type: "search", + }, + { + hotkeyDisabled: true, + key: SearchParamsKeys.TASK_ID_PATTERN, + translationKey: "taskIdPlaceholder", + type: "search", + }, + { + hotkeyDisabled: true, + key: SearchParamsKeys.MAP_INDEX, + translationKey: "mapIndexPlaceholder", + type: "search", + }, + { + key: SearchParamsKeys.LOGICAL_DATE_GTE, + translationKey: "logicalDateFromPlaceholder", + type: "datetime", + }, + { + key: SearchParamsKeys.LOGICAL_DATE_LTE, + translationKey: "logicalDateToPlaceholder", + type: "datetime", + }, + { + key: SearchParamsKeys.RUN_AFTER_GTE, + translationKey: "runAfterFromPlaceholder", + type: "datetime", + }, + { + key: SearchParamsKeys.RUN_AFTER_LTE, + translationKey: "runAfterToPlaceholder", + type: "datetime", + }, +] as const; + +export const XComFilters = () => { + const [searchParams, setSearchParams] = useSearchParams(); + const { setTableURLState, tableURLState } = useTableURLState(); + const { pagination, sorting } = tableURLState; + const { t: translate } = useTranslation(["browse", "common"]); + const [resetKey, setResetKey] = useState(0); + + const handleFilterChange = useCallback( + (paramKey: string) => (value: string) => { + if (value === "") { + searchParams.delete(paramKey); + } else { + searchParams.set(paramKey, value); + } + setTableURLState({ + pagination: { ...pagination, pageIndex: 0 }, + sorting, + }); + setSearchParams(searchParams); + }, + [pagination, searchParams, setSearchParams, setTableURLState, sorting], + ); + + const filterCount = useMemo( + () => + FILTERS.filter((filter) => { + const value = searchParams.get(filter.key); + + return value !== null && value !== ""; + }).length, + [searchParams], + ); + + const handleResetFilters = useCallback(() => { + FILTERS.forEach((filter) => { + searchParams.delete(filter.key); + }); + setTableURLState({ + pagination: { ...pagination, pageIndex: 0 }, + sorting, + }); + setSearchParams(searchParams); + setResetKey((prev) => prev + 1); + }, [pagination, searchParams, setSearchParams, setTableURLState, sorting]); + + const renderFilterInput = (filter: (typeof FILTERS)[number]) => { + const { key, translationKey, type } = filter; + + return ( + <Box key={key} w="200px"> + <Text fontSize="xs" marginBottom={1}> + {type === "search" ? "\u00A0" : translate(`common:filters.${translationKey}`)} Review Comment: Using `\u00A0` ensures the search filter container has the same height as those time-related filters (e.g., "Logical Date from"). Without it, the search box would be higher than the rest. Like this: <img width="2134" height="368" alt="filter" src="https://github.com/user-attachments/assets/fdb85622-e920-4e6b-8104-d743522c8e98" /> -- 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]
