bbovenzi commented on code in PR #54210: URL: https://github.com/apache/airflow/pull/54210#discussion_r2270480869
########## airflow-core/src/airflow/ui/src/pages/Events/ResetButton.tsx: ########## @@ -0,0 +1,42 @@ +/*! + * 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 } from "@chakra-ui/react"; +import { useTranslation } from "react-i18next"; +import { LuX } from "react-icons/lu"; + +export const ResetButton = ({ + filterCount, + onClearFilters, +}: { + readonly filterCount: number; + readonly onClearFilters: () => void; +}) => { + const { t: translate } = useTranslation("common"); + + if (filterCount === 0) { + return undefined; + } + + return ( + <Button onClick={onClearFilters} size="sm" variant="outline"> + <LuX /> + {translate("table.filterReset", { count: filterCount })} Review Comment: I think its ok if we just do a simple Remove Filter, Remove Filters instead of needed a custom function to count the total number ########## airflow-core/src/airflow/ui/src/pages/Events/EventsFilters.tsx: ########## @@ -0,0 +1,249 @@ +/*! + * 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, Input, VStack, Text } from "@chakra-ui/react"; +import { useCallback, useState, useEffect } from "react"; +import { useTranslation } from "react-i18next"; +import { useSearchParams } from "react-router-dom"; +import { useDebouncedCallback } from "use-debounce"; + +import { useTableURLState } from "src/components/DataTable/useTableUrlState"; +import { DateTimeInput } from "src/components/DateTimeInput"; +import { SearchParamsKeys } from "src/constants/searchParams"; + +import { ResetButton } from "./ResetButton"; +import { getFilterCount } from "./filterUtils"; + +const debounceDelay = 300; // Debounce delay for filter inputs + +const { + AFTER: AFTER_PARAM, + BEFORE: BEFORE_PARAM, + DAG_ID: DAG_ID_PARAM, + EVENT_TYPE: EVENT_TYPE_PARAM, + MAP_INDEX: MAP_INDEX_PARAM, + RUN_ID: RUN_ID_PARAM, + TASK_ID: TASK_ID_PARAM, + TRY_NUMBER: TRY_NUMBER_PARAM, + USER: USER_PARAM, +} = SearchParamsKeys; + +type EventsFiltersProps = { + readonly onClearFilters: () => void; + readonly urlDagId?: string; + readonly urlRunId?: string; + readonly urlTaskId?: string; +}; + +export const EventsFilters = ({ onClearFilters, urlDagId, urlRunId, urlTaskId }: EventsFiltersProps) => { + const { t: translate } = useTranslation(["browse", "common", "components"]); + const [searchParams, setSearchParams] = useSearchParams(); + const { setTableURLState, tableURLState } = useTableURLState(); + + const { pagination, sorting } = tableURLState; + + const resetPagination = useCallback(() => { + setTableURLState({ + pagination: { ...pagination, pageIndex: 0 }, + sorting, + }); + }, [pagination, setTableURLState, sorting]); + + const afterFilter = searchParams.get(AFTER_PARAM); + const beforeFilter = searchParams.get(BEFORE_PARAM); + const dagIdFilter = searchParams.get(DAG_ID_PARAM); + const eventTypeFilter = searchParams.get(EVENT_TYPE_PARAM); + const mapIndexFilter = searchParams.get(MAP_INDEX_PARAM); + const runIdFilter = searchParams.get(RUN_ID_PARAM); + const taskIdFilter = searchParams.get(TASK_ID_PARAM); + const tryNumberFilter = searchParams.get(TRY_NUMBER_PARAM); + const userFilter = searchParams.get(USER_PARAM); + + // Local state - for immediate UI feedback + const [localAfterFilter, setLocalAfterFilter] = useState(afterFilter ?? ""); + const [localBeforeFilter, setLocalBeforeFilter] = useState(beforeFilter ?? ""); + const [localDagIdFilter, setLocalDagIdFilter] = useState(dagIdFilter ?? ""); + const [localEventTypeFilter, setLocalEventTypeFilter] = useState(eventTypeFilter ?? ""); + const [localMapIndexFilter, setLocalMapIndexFilter] = useState(mapIndexFilter ?? ""); + const [localRunIdFilter, setLocalRunIdFilter] = useState(runIdFilter ?? ""); + const [localTaskIdFilter, setLocalTaskIdFilter] = useState(taskIdFilter ?? ""); + const [localTryNumberFilter, setLocalTryNumberFilter] = useState(tryNumberFilter ?? ""); + const [localUserFilter, setLocalUserFilter] = useState(userFilter ?? ""); + + // Sync local state with URL changes (e.g., from clear filters) + useEffect(() => setLocalAfterFilter(afterFilter ?? ""), [afterFilter]); + useEffect(() => setLocalBeforeFilter(beforeFilter ?? ""), [beforeFilter]); + useEffect(() => setLocalDagIdFilter(dagIdFilter ?? ""), [dagIdFilter]); + useEffect(() => setLocalEventTypeFilter(eventTypeFilter ?? ""), [eventTypeFilter]); + useEffect(() => setLocalMapIndexFilter(mapIndexFilter ?? ""), [mapIndexFilter]); + useEffect(() => setLocalRunIdFilter(runIdFilter ?? ""), [runIdFilter]); + useEffect(() => setLocalTaskIdFilter(taskIdFilter ?? ""), [taskIdFilter]); + useEffect(() => setLocalTryNumberFilter(tryNumberFilter ?? ""), [tryNumberFilter]); + useEffect(() => setLocalUserFilter(userFilter ?? ""), [userFilter]); Review Comment: +1 -- 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]
