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


##########
airflow-core/src/airflow/ui/src/queries/useHitlDetails.ts:
##########
@@ -0,0 +1,73 @@
+/*!
+ * 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 { useTaskInstanceServiceGetHitlDetails, useTaskServiceGetTasks } from 
"openapi/queries";
+
+type HITLDetailsParams = {
+  dagId?: string;
+  dagRunId?: string;
+  responseReceived?: boolean;
+  state?: Array<string>;
+  taskId?: string;
+  taskIdPattern?: string;
+};
+
+type HITLDetailsOptions = {
+  refetchInterval?: number | false;
+};
+
+export const useHitlDetails = (params: HITLDetailsParams, options: 
HITLDetailsOptions = {}) => {
+  const { dagId, dagRunId, responseReceived, state, taskId, taskIdPattern } = 
params;
+  const { refetchInterval } = options;
+
+  // If there is a dagId, let's see if any tasks have HITL operators
+  const { data: tasksData } = useTaskServiceGetTasks({ dagId: dagId ?? "~" }, 
undefined, {
+    enabled: Boolean(dagId),
+  });
+
+  const hasHitlOperators = Boolean(
+    tasksData?.tasks.some((task) => {
+      const operatorName = task.operator_name;
+
+      // TODO: do this in the backend
+      return (
+        operatorName === "HITLOperator" ||
+        operatorName === "ApprovalOperator" ||
+        operatorName === "HITLEntryOperator" ||
+        operatorName === "HITLBranchOperator"
+      );

Review Comment:
   Do we want to merge this if this is incomplete for now? (Or should we tackle 
it from the backend instead, wdyt?)
   
   I'm afraid that this could remain like this for a while, and end up being 
wrong if people implement custom operators and such.
   
   Maybe we can just fetch the HITLs and disable the query if it returns empty 
data, so we stop refecthing multiple times for no reasons.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to