pierrejeambrun commented on code in PR #54049:
URL: https://github.com/apache/airflow/pull/54049#discussion_r2266307744


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -127,8 +139,16 @@ def get_xcom_entries(
     offset: QueryOffset,
     readable_xcom_filter: ReadableXComFilterDep,
     session: SessionDep,
-    xcom_key: Annotated[str | None, Query()] = None,
-    map_index: Annotated[int | None, Query(ge=-1)] = None,

Review Comment:
   We should keep both on the backend, that's a breaking change. Leave the 
exact search on `xcom_key` and do a search on `xcom_key_pattern`.



##########
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:
   ```suggestion
             {type === "search" ? "\u00A0" : 
translate(`common:filters.${translationKey}`)}
   ```
   
   Can you explain `\u00A0`?



##########
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:
   @jscheffl is right, in the detail page we need to hide filters for 
parameters that are already set.
   
   
   For `task_id` and `dag_run_id` if those are set as path parameter (not query 
parameter), then use those values and hide the `task_id` and `dag_run_id` 
searches.
   
   (Same for dag_id, careful because this one is a little different, because in 
the url you have `dag_id` and the filter operates on `dag_display_name`, so 
you'll probably have to swap them around depending on the use context)



##########
airflow-core/src/airflow/ui/src/pages/XCom/XCom.tsx:
##########
@@ -103,25 +113,55 @@ export const XCom = () => {
   const { t: translate } = useTranslation(["browse", "common"]);
   const { setTableURLState, tableURLState } = useTableURLState();
   const { pagination } = tableURLState;
+  const [searchParams] = useSearchParams();
 
-  const { data, error, isFetching, isLoading } = useXcomServiceGetXcomEntries(
-    {
-      dagId,
-      dagRunId: runId,
-      limit: pagination.pageSize,
-      mapIndex: mapIndex === "-1" ? undefined : parseInt(mapIndex, 10),
-      offset: pagination.pageIndex * pagination.pageSize,
-      taskId,
-    },
-    undefined,
-    { enabled: !isNaN(pagination.pageSize) },
-  );
+  const filteredKey = searchParams.get(KEY_PATTERN_PARAM);
+  const filteredDagDisplayName = 
searchParams.get(DAG_DISPLAY_NAME_PATTERN_PARAM);
+  const filteredMapIndex = searchParams.get(MAP_INDEX_PARAM);
+  const filteredRunId = searchParams.get(RUN_ID_PATTERN_PARAM);
+  const filteredTaskId = searchParams.get(TASK_ID_PATTERN_PARAM);
+
+  const { LOGICAL_DATE_GTE, LOGICAL_DATE_LTE, RUN_AFTER_GTE, RUN_AFTER_LTE } = 
SearchParamsKeys;
+
+  const logicalDateGte = searchParams.get(LOGICAL_DATE_GTE);
+  const logicalDateLte = searchParams.get(LOGICAL_DATE_LTE);
+  const runAfterGte = searchParams.get(RUN_AFTER_GTE);
+  const runAfterLte = searchParams.get(RUN_AFTER_LTE);
+
+  const apiParams = {
+    dagDisplayNamePattern: filteredDagDisplayName ?? undefined,
+    dagId,
+    dagRunId: runId,
+    limit: pagination.pageSize,
+    logicalDateGte: logicalDateGte ?? undefined,
+    logicalDateLte: logicalDateLte ?? undefined,
+    mapIndex:
+      filteredMapIndex !== null && filteredMapIndex !== ""
+        ? parseInt(filteredMapIndex, 10)
+        : mapIndex === "-1"
+          ? undefined
+          : parseInt(mapIndex, 10),
+    offset: pagination.pageIndex * pagination.pageSize,
+    runAfterGte: runAfterGte ?? undefined,
+    runAfterLte: runAfterLte ?? undefined,
+    runIdPattern: filteredRunId ?? undefined,
+    taskId,
+    taskIdPattern: filteredTaskId ?? undefined,
+    xcomKeyPattern: filteredKey ?? undefined,
+  };
+
+  const { data, error, isFetching, isLoading } = 
useXcomServiceGetXcomEntries(apiParams, undefined, {
+    enabled: !isNaN(pagination.pageSize),

Review Comment:
   ```suggestion
   ```
   
   Why is that necessary?



##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/xcom.py:
##########
@@ -127,8 +139,16 @@ def get_xcom_entries(
     offset: QueryOffset,
     readable_xcom_filter: ReadableXComFilterDep,
     session: SessionDep,
-    xcom_key: Annotated[str | None, Query()] = None,
-    map_index: Annotated[int | None, Query(ge=-1)] = None,
+    xcom_key_pattern: QueryXComKeyPatternSearch,
+    dag_display_name_pattern: QueryXComDagDisplayNamePatternSearch,
+    run_id_pattern: QueryXComRunIdPatternSearch,
+    task_id_pattern: QueryXComTaskIdPatternSearch,
+    map_index: Annotated[
+        FilterParam[int | None],
+        Depends(filter_param_factory(XComModel.map_index, int | None, 
filter_name="map_index")),

Review Comment:
   Nice.



##########
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:
   It's hard to render filter in a generic way like this because we are most 
likely not specifying the proper input type.
   
   For instance map_index should be a number, not a free `str` text.



-- 
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]

Reply via email to