bbovenzi commented on code in PR #54722:
URL: https://github.com/apache/airflow/pull/54722#discussion_r2301537660


##########
airflow-core/src/airflow/ui/src/components/TaskFilter/TaskInstance/TaskFilterTaskInstanceButton.tsx:
##########
@@ -0,0 +1,78 @@
+/*!
+ * 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 } from "@chakra-ui/react";
+import { MdFilterList } from "react-icons/md";
+import { useLocalStorage } from "usehooks-ts";
+
+import type { TaskInstanceResponse } from "openapi/requests";
+import { Menu } from "src/components/ui";
+import ActionButton from "src/components/ui/ActionButton";
+
+type Props = {
+  readonly taskInstance: TaskInstanceResponse;
+  readonly withText?: boolean;
+};
+
+const filterOptions = [
+  { buttonLabel: "Filter Dag by task", label: "All", value: "all" },
+  { buttonLabel: "Only upstream", label: "Only upstream", value: "upstream" },
+  { buttonLabel: "Only downstream", label: "Only downstream", value: 
"downstream" },
+  { buttonLabel: "Both upstream & downstream", label: "Both upstream & 
downstream", value: "both" },

Review Comment:
   We will need to move these to the translation json files. We might be able 
to reuse some of the task clear action text.



##########
airflow-core/src/airflow/ui/src/components/TaskFilter/TaskInstance/TaskFilterTaskInstanceButton.tsx:
##########
@@ -0,0 +1,78 @@
+/*!
+ * 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 } from "@chakra-ui/react";
+import { MdFilterList } from "react-icons/md";
+import { useLocalStorage } from "usehooks-ts";
+
+import type { TaskInstanceResponse } from "openapi/requests";
+import { Menu } from "src/components/ui";
+import ActionButton from "src/components/ui/ActionButton";
+
+type Props = {
+  readonly taskInstance: TaskInstanceResponse;
+  readonly withText?: boolean;
+};
+
+const filterOptions = [
+  { buttonLabel: "Filter Dag by task", label: "All", value: "all" },
+  { buttonLabel: "Only upstream", label: "Only upstream", value: "upstream" },
+  { buttonLabel: "Only downstream", label: "Only downstream", value: 
"downstream" },
+  { buttonLabel: "Both upstream & downstream", label: "Both upstream & 
downstream", value: "both" },
+];
+
+const TaskFilterTaskInstanceButton = ({ taskInstance, withText = true }: 
Props) => {
+  const dagId = taskInstance.dag_id;
+  const [selected, setSelected] = 
useLocalStorage<string>(`upstreamDownstreamFilter-${dagId}`, "all");
+
+  const handleSelect = (value: string) => {
+    setSelected(value);
+  };
+
+  return (
+    <Box>
+      <Menu.Root positioning={{ gutter: 0, placement: "bottom" }}>
+        <Menu.Trigger asChild>
+          <ActionButton
+            actionName={`Filter: ${filterOptions.find((opt) => opt.value === 
selected)?.buttonLabel}`}
+            flexDirection="row-reverse"
+            icon={<MdFilterList />}
+            text={filterOptions.find((opt) => opt.value === 
selected)?.buttonLabel ?? ""}
+            withText={withText}
+          />
+        </Menu.Trigger>
+
+        <Menu.Content>
+          {filterOptions.map((option) => (
+            <Menu.Item
+              asChild
+              disabled={selected === option.value}
+              key={option.value}
+              onClick={() => handleSelect(option.value)}
+              value={option.value}
+            >
+              <div className="px-2 py-1 cursor-pointer">{option.label}</div>

Review Comment:
   We should use a <Text> or Button or a chakra component here instead



##########
airflow-core/src/airflow/ui/src/components/TaskFilter/TaskInstance/TaskFilterTaskInstanceButton.tsx:
##########
@@ -0,0 +1,78 @@
+/*!
+ * 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 } from "@chakra-ui/react";
+import { MdFilterList } from "react-icons/md";
+import { useLocalStorage } from "usehooks-ts";
+
+import type { TaskInstanceResponse } from "openapi/requests";
+import { Menu } from "src/components/ui";
+import ActionButton from "src/components/ui/ActionButton";
+
+type Props = {
+  readonly taskInstance: TaskInstanceResponse;
+  readonly withText?: boolean;
+};
+
+const filterOptions = [
+  { buttonLabel: "Filter Dag by task", label: "All", value: "all" },
+  { buttonLabel: "Only upstream", label: "Only upstream", value: "upstream" },
+  { buttonLabel: "Only downstream", label: "Only downstream", value: 
"downstream" },
+  { buttonLabel: "Both upstream & downstream", label: "Both upstream & 
downstream", value: "both" },
+];
+
+const TaskFilterTaskInstanceButton = ({ taskInstance, withText = true }: 
Props) => {
+  const dagId = taskInstance.dag_id;
+  const [selected, setSelected] = 
useLocalStorage<string>(`upstreamDownstreamFilter-${dagId}`, "all");

Review Comment:
   A query param is a better place to keep the state instead of localStorage



##########
airflow-core/src/airflow/ui/src/components/TaskFilter/TaskInstance/TaskFilterTaskInstanceButton.tsx:
##########
@@ -0,0 +1,78 @@
+/*!
+ * 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 } from "@chakra-ui/react";
+import { MdFilterList } from "react-icons/md";
+import { useLocalStorage } from "usehooks-ts";
+
+import type { TaskInstanceResponse } from "openapi/requests";
+import { Menu } from "src/components/ui";
+import ActionButton from "src/components/ui/ActionButton";
+
+type Props = {
+  readonly taskInstance: TaskInstanceResponse;
+  readonly withText?: boolean;
+};
+
+const filterOptions = [
+  { buttonLabel: "Filter Dag by task", label: "All", value: "all" },
+  { buttonLabel: "Only upstream", label: "Only upstream", value: "upstream" },
+  { buttonLabel: "Only downstream", label: "Only downstream", value: 
"downstream" },
+  { buttonLabel: "Both upstream & downstream", label: "Both upstream & 
downstream", value: "both" },
+];
+
+const TaskFilterTaskInstanceButton = ({ taskInstance, withText = true }: 
Props) => {
+  const dagId = taskInstance.dag_id;
+  const [selected, setSelected] = 
useLocalStorage<string>(`upstreamDownstreamFilter-${dagId}`, "all");
+
+  const handleSelect = (value: string) => {
+    setSelected(value);
+  };
+
+  return (
+    <Box>
+      <Menu.Root positioning={{ gutter: 0, placement: "bottom" }}>
+        <Menu.Trigger asChild>
+          <ActionButton
+            actionName={`Filter: ${filterOptions.find((opt) => opt.value === 
selected)?.buttonLabel}`}

Review Comment:
   Translation here too



##########
airflow-core/src/airflow/ui/src/components/TaskFilter/TaskInstance/TaskFilterTaskInstanceButton.tsx:
##########


Review Comment:
   We can rename this to FilterTaskButton and it doesn't need to be in it's own 
folder with an index file



##########
airflow-core/src/airflow/ui/src/layouts/Details/Graph/utils.ts:
##########
@@ -0,0 +1,108 @@
+/*!
+ * 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 { Edge } from "@xyflow/react";
+
+type FilterType = "all" | "both" | "downstream" | "upstream";
+
+type GraphParams<T extends { id: string }> = {
+  edges: Array<Edge>;
+  filter: FilterType;
+  nodes: Array<T>;
+  taskId?: string;
+};
+
+export const filterGraph = <T extends { id: string }>({

Review Comment:
   We already have `includeDownstream, includeUpstream, root` in 
`useStructureServiceStructureData` let's use those instead of filtering 
everything on the frontend



##########
airflow-core/src/airflow/ui/src/components/TaskFilter/index.tsx:
##########
@@ -0,0 +1,20 @@
+/*!
+ * 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.
+ */
+
+export { default as TaskFilterTaskInstanceButton } from "./TaskInstance";

Review Comment:
   Again, if there's only one file within these two folders then the folders 
and index files are extraneous.



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