dheerajturaga commented on code in PR #69148:
URL: https://github.com/apache/airflow/pull/69148#discussion_r3798992657


##########
airflow-core/docs/administration-and-deployment/plugins.rst:
##########
@@ -301,6 +313,59 @@ definitions in Airflow.
 
 .. seealso:: :doc:`/howto/define-extra-link`
 
+Scoping a view to specific Dags and tasks
+-----------------------------------------
+
+By default an external view or React app is shown on every page matching its 
``destination``.
+The optional ``applies_to`` block narrows that down, so a tab is only offered 
where it is
+relevant instead of appearing on every Dag:
+
+.. code-block:: python
+
+    "applies_to": {
+        "dag_tags": ["ml"],  # Dag carries any of these tags
+        "dag_ids": ["train_pipeline"],  # exact dag_id
+        "task_ids": ["train_model"],  # exact task_id
+        "operators": ["KubernetesPodOperator"],  # the task's operator
+    }
+
+All four keys are optional. ``operators`` matches either the operator class 
name or its
+display name (``custom_operator_name``).

Review Comment:
   Addressed. The schema now has separate `operators` and `operator_names` 
criteria. `operators` matches the class name, while `operator_names` matches 
the UI/display name (`custom_operator_name`). Tests cover both fields, 
including decorator-based tasks.
   
   ---
   Drafted-by: Codex (GPT-5) (no human review before posting)



##########
airflow-core/src/airflow/ui/src/hooks/usePluginAppliesToContext.ts:
##########
@@ -0,0 +1,63 @@
+/*!
+ * 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 { useParams } from "react-router-dom";
+
+import {
+  useDagServiceGetDag,
+  useTaskInstanceServiceGetMappedTaskInstance,
+  useTaskServiceGetTask,
+} from "openapi/queries";
+import type { AppliesToContext } from "src/utils/pluginAppliesTo";
+
+/**
+ * Resolve the records the current route provides, for evaluating plugin 
`applies_to`.
+ *
+ * Each query is gated on the route params it needs, so it stays disabled 
where those
+ * params are absent and is a cache hit where the details page already fetched 
it — no
+ * extra requests. Task groups are skipped for the task query, since `groupId` 
is not a
+ * task_id and would 404.
+ */
+export const usePluginAppliesToContext = (): AppliesToContext => {
+  const { dagId = "", groupId, mapIndex = "-1", runId = "", taskId = "" } = 
useParams();
+
+  const { data: dag, isLoading: isDagLoading } = useDagServiceGetDag({ dagId 
}, undefined, {
+    enabled: Boolean(dagId),
+  });
+
+  const { data: task, isLoading: isTaskLoading } = useTaskServiceGetTask({ 
dagId, taskId }, undefined, {
+    enabled: Boolean(dagId) && Boolean(taskId) && groupId === undefined,
+  });
+
+  const { data: taskInstance, isLoading: isTaskInstanceLoading } =
+    useTaskInstanceServiceGetMappedTaskInstance(
+      { dagId, dagRunId: runId, mapIndex: parseInt(mapIndex, 10), taskId },
+      undefined,
+      { enabled: Boolean(dagId) && Boolean(runId) && Boolean(taskId) && 
groupId === undefined },
+    );

Review Comment:
   Addressed using the generated query-key factories. These hooks already share 
the generated `Use*KeyFn` implementations when no custom query key is supplied, 
so `usePluginAppliesToContext` deliberately passes `undefined` instead of 
introducing another constant. A regression test now verifies that no custom key 
is passed and that each hook parameter set produces the same generated key as 
the surrounding Dag, task, or task-instance page. Parameter drift that would 
split the cache will therefore fail the test.
   
   ---
   Drafted-by: Codex (GPT-5) (no human review before posting)



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