bbovenzi commented on code in PR #54210:
URL: https://github.com/apache/airflow/pull/54210#discussion_r2282745878
##########
airflow-core/src/airflow/ui/src/pages/Events/Events.tsx:
##########
@@ -141,31 +147,109 @@ const eventsColumn = (
},
];
+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,
+}: SearchParamsKeysType = SearchParamsKeys;
+
export const Events = () => {
const { t: translate } = useTranslation("browse");
const { dagId, runId, taskId } = useParams();
+ const [searchParams] = useSearchParams();
const { setTableURLState, tableURLState } = useTableURLState();
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const { onClose, onOpen, open } = useDisclosure();
+ 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);
+
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["-when"];
+ // Convert string filters to appropriate types for API
+ const mapIndexNumber = mapIndexFilter === null ? undefined :
parseInt(mapIndexFilter, 10);
+ const tryNumberNumber = tryNumberFilter === null ? undefined :
parseInt(tryNumberFilter, 10);
+ // Handle date conversion - ensure valid ISO strings
+ const afterDate = afterFilter !== null && !isNaN(Date.parse(afterFilter)) ?
afterFilter : undefined;
+ const beforeDate = beforeFilter !== null && !isNaN(Date.parse(beforeFilter))
? beforeFilter : undefined;
Review Comment:
Nit. We can just use `dayjs(afterFilter).isValid()`
##########
airflow-core/src/airflow/ui/public/i18n/locales/en/browse.json:
##########
@@ -10,6 +10,11 @@
"user": "User",
"when": "When"
},
+ "filters": {
+ "endDateTime": "End date and time",
+ "eventType": "Event Type",
+ "startDateTime": "Start date and time"
Review Comment:
Let's just reuse `startDate` and `endDate` no need to specify "time" since
that's already included in every other date we have in the UI
##########
airflow-core/src/airflow/ui/src/pages/Events/Events.tsx:
##########
@@ -141,31 +147,109 @@ const eventsColumn = (
},
];
+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,
+}: SearchParamsKeysType = SearchParamsKeys;
+
export const Events = () => {
const { t: translate } = useTranslation("browse");
const { dagId, runId, taskId } = useParams();
+ const [searchParams] = useSearchParams();
const { setTableURLState, tableURLState } = useTableURLState();
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const { onClose, onOpen, open } = useDisclosure();
+ 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);
+
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["-when"];
+ // Convert string filters to appropriate types for API
+ const mapIndexNumber = mapIndexFilter === null ? undefined :
parseInt(mapIndexFilter, 10);
+ const tryNumberNumber = tryNumberFilter === null ? undefined :
parseInt(tryNumberFilter, 10);
+ // Handle date conversion - ensure valid ISO strings
+ const afterDate = afterFilter !== null && !isNaN(Date.parse(afterFilter)) ?
afterFilter : undefined;
+ const beforeDate = beforeFilter !== null && !isNaN(Date.parse(beforeFilter))
? beforeFilter : undefined;
+ const hasTextFilters = Boolean(dagIdFilter ?? eventTypeFilter ?? userFilter
?? runIdFilter ?? taskIdFilter);
const { data, error, isFetching, isLoading } =
useEventLogServiceGetEventLogs(
{
- dagId,
- limit: pagination.pageSize,
+ after: afterDate,
+ before: beforeDate,
+ // URL params take precedence for context-specific views (exact match
needed)
+ dagId: dagId ?? undefined, // Remove dagIdFilter to allow partial search
+ event: undefined, // Remove eventTypeFilter to allow partial search
+ limit: hasTextFilters ? pagination.pageSize * 5 : pagination.pageSize,
// Load more data for filtering
+ mapIndex: mapIndexNumber,
offset: pagination.pageIndex * pagination.pageSize,
orderBy,
- runId,
- taskId,
+ owner: undefined, // Remove userFilter to allow partial search
+ runId: runId ?? undefined, // Remove runIdFilter to allow partial search
+ taskId: taskId ?? undefined, // Remove taskIdFilter to allow partial
search
+ tryNumber: tryNumberNumber,
},
undefined,
{ enabled: !isNaN(pagination.pageSize) },
);
+ const filteredData = React.useMemo(() => {
+ if (!data?.event_logs || !hasTextFilters) {
+ return data;
+ }
+
+ const filtered = data.event_logs.filter((log) => {
+ if (dagIdFilter !== null &&
!log.dag_id?.toLowerCase().includes(dagIdFilter.toLowerCase())) {
+ return false;
+ }
+ if (eventTypeFilter !== null &&
!log.event.toLowerCase().includes(eventTypeFilter.toLowerCase())) {
+ return false;
+ }
+ if (userFilter !== null &&
!log.owner?.toLowerCase().includes(userFilter.toLowerCase())) {
+ return false;
+ }
+ if (runIdFilter !== null &&
!log.run_id?.toLowerCase().includes(runIdFilter.toLowerCase())) {
+ return false;
+ }
+ if (taskIdFilter !== null &&
!log.task_id?.toLowerCase().includes(taskIdFilter.toLowerCase())) {
+ return false;
+ }
+
+ return true;
+ });
+
+ return {
+ ...data,
+ event_logs: filtered.slice(0, pagination.pageSize), // Apply pagination
to filtered results
+ total_entries: filtered.length,
Review Comment:
Why are we applying pagination here? `useEventLogServiceGetEventLogs` should
already handle that automatically
##########
airflow-core/src/airflow/ui/src/pages/Events/EventsFilters.tsx:
##########
@@ -0,0 +1,254 @@
+/*!
+ * 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, VStack, Text } from "@chakra-ui/react";
+import { useCallback } from "react";
+import { useTranslation } from "react-i18next";
+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 { ResetButton } from "src/components/ui";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+import { getFilterCount } from "./filterUtils";
+
+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 urlDagId?: string;
+ readonly urlRunId?: string;
+ readonly urlTaskId?: string;
+};
+
+export const EventsFilters = ({ 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);
+
+ const updateSearchParams = useCallback(
+ (paramName: string, value: string) => {
+ if (value) {
+ searchParams.set(paramName, value);
+ } else {
+ searchParams.delete(paramName);
+ }
+ resetPagination();
+ setSearchParams(searchParams);
+ },
+ [resetPagination, searchParams, setSearchParams],
+ );
+
+ const handleClearFilters = useCallback(() => {
+ // Clear URL params
+ searchParams.delete(AFTER_PARAM);
+ searchParams.delete(BEFORE_PARAM);
+ searchParams.delete(DAG_ID_PARAM);
+ searchParams.delete(EVENT_TYPE_PARAM);
+ searchParams.delete(MAP_INDEX_PARAM);
+ searchParams.delete(RUN_ID_PARAM);
+ searchParams.delete(TASK_ID_PARAM);
+ searchParams.delete(TRY_NUMBER_PARAM);
+ searchParams.delete(USER_PARAM);
+
+ resetPagination();
+ setSearchParams(searchParams);
+ }, [resetPagination, searchParams, setSearchParams]);
Review Comment:
Are there any search params that we are keeping? Otherwise we can just do
`setSearchParams(new URLSearchParams())` to clear all of them
##########
airflow-core/src/airflow/ui/src/pages/Events/EventsFilters.tsx:
##########
@@ -0,0 +1,254 @@
+/*!
+ * 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, VStack, Text } from "@chakra-ui/react";
+import { useCallback } from "react";
+import { useTranslation } from "react-i18next";
+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 { ResetButton } from "src/components/ui";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+import { getFilterCount } from "./filterUtils";
+
+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 urlDagId?: string;
+ readonly urlRunId?: string;
+ readonly urlTaskId?: string;
+};
+
+export const EventsFilters = ({ 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);
+
+ const updateSearchParams = useCallback(
+ (paramName: string, value: string) => {
+ if (value) {
+ searchParams.set(paramName, value);
+ } else {
+ searchParams.delete(paramName);
+ }
+ resetPagination();
+ setSearchParams(searchParams);
+ },
+ [resetPagination, searchParams, setSearchParams],
+ );
+
+ const handleClearFilters = useCallback(() => {
+ // Clear URL params
+ searchParams.delete(AFTER_PARAM);
+ searchParams.delete(BEFORE_PARAM);
+ searchParams.delete(DAG_ID_PARAM);
+ searchParams.delete(EVENT_TYPE_PARAM);
+ searchParams.delete(MAP_INDEX_PARAM);
+ searchParams.delete(RUN_ID_PARAM);
+ searchParams.delete(TASK_ID_PARAM);
+ searchParams.delete(TRY_NUMBER_PARAM);
+ searchParams.delete(USER_PARAM);
+
+ resetPagination();
+ setSearchParams(searchParams);
+ }, [resetPagination, searchParams, setSearchParams]);
+
+ const handleSearchChange = useCallback(
+ (paramName: string) => (value: string) => {
+ updateSearchParams(paramName, value);
+ },
+ [updateSearchParams],
+ );
+
+ const handleDateTimeChange = useCallback(
+ (paramName: string) => (event: React.ChangeEvent<HTMLInputElement>) => {
+ const { value } = event.target;
+
+ updateSearchParams(paramName, value);
+ },
+ [updateSearchParams],
+ );
+
+ const filterCount = getFilterCount({
+ after: afterFilter,
+ before: beforeFilter,
+ dagId: dagIdFilter,
+ eventType: eventTypeFilter,
+ mapIndex: mapIndexFilter,
+ runId: runIdFilter,
+ taskId: taskIdFilter,
+ tryNumber: tryNumberFilter,
+ user: userFilter,
+ });
+
+ return (
+ <HStack justifyContent="space-between">
+ <HStack alignItems="end" gap={4}>
+ {/* Timestamp Range Filters */}
+ <VStack alignItems="flex-start" gap={1}>
+ <Text fontSize="xs" fontWeight="medium">
+ {translate("components:backfill.dateRangeFrom")}
+ </Text>
+ <DateTimeInput
+ onChange={handleDateTimeChange(AFTER_PARAM)}
+ placeholder={translate("auditLog.filters.startDateTime")}
+ size="sm"
+ value={afterFilter ?? ""}
+ />
+ </VStack>
+ <VStack alignItems="flex-start" gap={1}>
+ <Text fontSize="xs" fontWeight="medium">
+ {translate("components:backfill.dateRangeTo")}
+ </Text>
+ <DateTimeInput
+ onChange={handleDateTimeChange(BEFORE_PARAM)}
+ placeholder={translate("auditLog.filters.endDateTime")}
+ size="sm"
+ value={beforeFilter ?? ""}
+ />
+ </VStack>
+
+ {/* Event Type Filter */}
+ <Box>
+ <SearchBar
+ buttonProps={{ disabled: true }}
+ defaultValue={eventTypeFilter ?? ""}
+ hideAdvanced={true}
+ hotkeyDisabled={true}
+ onChange={handleSearchChange(EVENT_TYPE_PARAM)}
+ placeHolder={translate("auditLog.filters.eventType")}
+ />
+ </Box>
+
+ {/* User Filter */}
+ <Box>
+ <SearchBar
+ buttonProps={{ disabled: true }}
+ defaultValue={userFilter ?? ""}
+ hideAdvanced={true}
+ hotkeyDisabled={true}
+ onChange={handleSearchChange(USER_PARAM)}
+ placeHolder={translate("common:user")}
+ />
+ </Box>
+
+ {/* DAG ID Filter - Hide if URL already has dagId */}
+ {urlDagId === undefined && (
+ <Box>
+ <SearchBar
+ buttonProps={{ disabled: true }}
+ defaultValue={dagIdFilter ?? ""}
+ hideAdvanced={true}
+ hotkeyDisabled={true}
+ onChange={handleSearchChange(DAG_ID_PARAM)}
+ placeHolder={translate("common:dagId")}
+ />
+ </Box>
+ )}
+
+ {/* Task ID Filter - Hide if URL already has taskId */}
+ {urlTaskId === undefined && (
+ <Box>
+ <SearchBar
+ buttonProps={{ disabled: true }}
+ defaultValue={taskIdFilter ?? ""}
+ hideAdvanced={true}
+ hotkeyDisabled={true}
+ onChange={handleSearchChange(TASK_ID_PARAM)}
+ placeHolder={translate("common:taskId")}
+ />
+ </Box>
+ )}
+
+ {/* Run ID Filter - Hide if URL already has runId */}
+ {urlRunId === undefined && (
+ <Box>
+ <SearchBar
+ buttonProps={{ disabled: true }}
+ defaultValue={runIdFilter ?? ""}
+ hideAdvanced={true}
+ hotkeyDisabled={true}
+ onChange={handleSearchChange(RUN_ID_PARAM)}
+ placeHolder={translate("common:runId")}
+ />
+ </Box>
+ )}
+
+ {/* Map Index Filter */}
+ <Box>
+ <SearchBar
+ buttonProps={{ disabled: true }}
+ defaultValue={mapIndexFilter ?? ""}
+ hideAdvanced={true}
+ hotkeyDisabled={true}
Review Comment:
Not for this PR but I wonder if we should change these defaults
##########
airflow-core/src/airflow/ui/src/pages/Events/EventsFilters.tsx:
##########
@@ -0,0 +1,254 @@
+/*!
+ * 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, VStack, Text } from "@chakra-ui/react";
+import { useCallback } from "react";
+import { useTranslation } from "react-i18next";
+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 { ResetButton } from "src/components/ui";
+import { SearchParamsKeys } from "src/constants/searchParams";
+
+import { getFilterCount } from "./filterUtils";
+
+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 urlDagId?: string;
+ readonly urlRunId?: string;
+ readonly urlTaskId?: string;
+};
+
+export const EventsFilters = ({ 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);
+
+ const updateSearchParams = useCallback(
+ (paramName: string, value: string) => {
+ if (value) {
+ searchParams.set(paramName, value);
+ } else {
+ searchParams.delete(paramName);
+ }
+ resetPagination();
+ setSearchParams(searchParams);
+ },
+ [resetPagination, searchParams, setSearchParams],
+ );
+
+ const handleClearFilters = useCallback(() => {
+ // Clear URL params
+ searchParams.delete(AFTER_PARAM);
+ searchParams.delete(BEFORE_PARAM);
+ searchParams.delete(DAG_ID_PARAM);
+ searchParams.delete(EVENT_TYPE_PARAM);
+ searchParams.delete(MAP_INDEX_PARAM);
+ searchParams.delete(RUN_ID_PARAM);
+ searchParams.delete(TASK_ID_PARAM);
+ searchParams.delete(TRY_NUMBER_PARAM);
+ searchParams.delete(USER_PARAM);
+
+ resetPagination();
+ setSearchParams(searchParams);
+ }, [resetPagination, searchParams, setSearchParams]);
+
+ const handleSearchChange = useCallback(
+ (paramName: string) => (value: string) => {
+ updateSearchParams(paramName, value);
+ },
+ [updateSearchParams],
+ );
+
+ const handleDateTimeChange = useCallback(
+ (paramName: string) => (event: React.ChangeEvent<HTMLInputElement>) => {
+ const { value } = event.target;
+
+ updateSearchParams(paramName, value);
+ },
+ [updateSearchParams],
+ );
+
+ const filterCount = getFilterCount({
Review Comment:
I think we can just use `searchParams.size`
##########
airflow-core/src/airflow/ui/src/pages/Events/Events.tsx:
##########
@@ -141,31 +147,109 @@ const eventsColumn = (
},
];
+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,
+}: SearchParamsKeysType = SearchParamsKeys;
+
export const Events = () => {
const { t: translate } = useTranslation("browse");
const { dagId, runId, taskId } = useParams();
+ const [searchParams] = useSearchParams();
const { setTableURLState, tableURLState } = useTableURLState();
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const { onClose, onOpen, open } = useDisclosure();
+ 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);
+
const orderBy = sort ? [`${sort.desc ? "-" : ""}${sort.id}`] : ["-when"];
+ // Convert string filters to appropriate types for API
+ const mapIndexNumber = mapIndexFilter === null ? undefined :
parseInt(mapIndexFilter, 10);
+ const tryNumberNumber = tryNumberFilter === null ? undefined :
parseInt(tryNumberFilter, 10);
+ // Handle date conversion - ensure valid ISO strings
+ const afterDate = afterFilter !== null && !isNaN(Date.parse(afterFilter)) ?
afterFilter : undefined;
+ const beforeDate = beforeFilter !== null && !isNaN(Date.parse(beforeFilter))
? beforeFilter : undefined;
+ const hasTextFilters = Boolean(dagIdFilter ?? eventTypeFilter ?? userFilter
?? runIdFilter ?? taskIdFilter);
const { data, error, isFetching, isLoading } =
useEventLogServiceGetEventLogs(
{
- dagId,
- limit: pagination.pageSize,
+ after: afterDate,
+ before: beforeDate,
+ // URL params take precedence for context-specific views (exact match
needed)
+ dagId: dagId ?? undefined, // Remove dagIdFilter to allow partial search
+ event: undefined, // Remove eventTypeFilter to allow partial search
+ limit: hasTextFilters ? pagination.pageSize * 5 : pagination.pageSize,
// Load more data for filtering
+ mapIndex: mapIndexNumber,
offset: pagination.pageIndex * pagination.pageSize,
orderBy,
- runId,
- taskId,
+ owner: undefined, // Remove userFilter to allow partial search
+ runId: runId ?? undefined, // Remove runIdFilter to allow partial search
+ taskId: taskId ?? undefined, // Remove taskIdFilter to allow partial
search
+ tryNumber: tryNumberNumber,
},
undefined,
{ enabled: !isNaN(pagination.pageSize) },
);
+ const filteredData = React.useMemo(() => {
+ if (!data?.event_logs || !hasTextFilters) {
+ return data;
+ }
+
+ const filtered = data.event_logs.filter((log) => {
+ if (dagIdFilter !== null &&
!log.dag_id?.toLowerCase().includes(dagIdFilter.toLowerCase())) {
+ return false;
+ }
+ if (eventTypeFilter !== null &&
!log.event.toLowerCase().includes(eventTypeFilter.toLowerCase())) {
+ return false;
+ }
+ if (userFilter !== null &&
!log.owner?.toLowerCase().includes(userFilter.toLowerCase())) {
+ return false;
+ }
+ if (runIdFilter !== null &&
!log.run_id?.toLowerCase().includes(runIdFilter.toLowerCase())) {
+ return false;
+ }
+ if (taskIdFilter !== null &&
!log.task_id?.toLowerCase().includes(taskIdFilter.toLowerCase())) {
+ return false;
+ }
+
+ return true;
+ });
+
+ return {
+ ...data,
+ event_logs: filtered.slice(0, pagination.pageSize), // Apply pagination
to filtered results
+ total_entries: filtered.length,
Review Comment:
Actually, why do we need `filrteredData` at all? Everythign should be
filtered on the backend so the `data` above should already be good.
--
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]