-
Notifications
You must be signed in to change notification settings - Fork 17.5k
UI: Pass Dag, DagRun, TaskInstance, and Asset objects to React app plugins #70149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bbovenzi
merged 1 commit into
apache:main
from
dheerajturaga:pass-context-objects-to-react-plugins
Jul 22, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
airflow-core/src/airflow/ui/src/pages/ReactPlugin.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| /*! | ||
| * 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 "@testing-library/jest-dom"; | ||
| import { render } from "@testing-library/react"; | ||
| import type * as ReactRouterDom from "react-router-dom"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import type { | ||
| AssetResponse, | ||
| DAGDetailsResponse, | ||
| DAGRunResponse, | ||
| ReactAppResponse, | ||
| TaskInstanceResponse, | ||
| } from "openapi/requests/types.gen"; | ||
| import { Wrapper } from "src/utils/Wrapper"; | ||
|
|
||
| import { ReactPlugin, type PluginProps } from "./ReactPlugin"; | ||
|
|
||
| const mockAsset = { id: 1, name: "my_asset", uri: "s3://bucket/key" } as AssetResponse; | ||
| const mockDag = { dag_display_name: "My Dag", dag_id: "my_dag" } as DAGDetailsResponse; | ||
| const mockDagRun = { dag_id: "my_dag", dag_run_id: "run_1", state: "success" } as DAGRunResponse; | ||
| const mockTaskInstance = { dag_id: "my_dag", task_id: "my_task" } as TaskInstanceResponse; | ||
|
|
||
| let mockParams: Record<string, string> = {}; | ||
|
|
||
| vi.mock("react-router-dom", async (importOriginal) => ({ | ||
| ...(await importOriginal<typeof ReactRouterDom>()), | ||
| useParams: () => mockParams, | ||
| })); | ||
|
|
||
| type QueryOptions = { enabled?: boolean }; | ||
|
|
||
| // Each mocked hook mirrors the real gating: it returns its record only when the caller enables | ||
| // the query (i.e. the route params it depends on are present), and undefined otherwise. | ||
| vi.mock("openapi/queries", () => ({ | ||
| useAssetServiceGetAsset: (_params: unknown, _key: unknown, options?: QueryOptions) => ({ | ||
| data: options?.enabled ? mockAsset : undefined, | ||
| }), | ||
| useDagRunServiceGetDagRun: (_params: unknown, _key: unknown, options?: QueryOptions) => ({ | ||
| data: options?.enabled ? mockDagRun : undefined, | ||
| }), | ||
| useDagServiceGetDagDetails: (_params: unknown, _key: unknown, options?: QueryOptions) => ({ | ||
| data: options?.enabled ? mockDag : undefined, | ||
| }), | ||
| useTaskInstanceServiceGetMappedTaskInstance: (_params: unknown, _key: unknown, options?: QueryOptions) => ({ | ||
| data: options?.enabled ? mockTaskInstance : undefined, | ||
| }), | ||
| })); | ||
|
|
||
| const reactApp = { | ||
| bundle_url: "http://localhost/plugin.js", | ||
| destination: "dag", | ||
| name: "TestPlugin", | ||
| } as ReactAppResponse; | ||
|
|
||
| let capturedProps: PluginProps | undefined; | ||
|
|
||
| const renderPlugin = () => { | ||
| capturedProps = undefined; | ||
| // Pre-register the component so ReactPlugin renders it directly instead of lazy-loading a bundle. | ||
| (globalThis as Record<string, unknown>)[reactApp.name] = (props: PluginProps) => { | ||
| capturedProps = props; | ||
|
|
||
| return null; | ||
| }; | ||
|
|
||
| render(<ReactPlugin reactApp={reactApp} />, { wrapper: Wrapper }); | ||
| }; | ||
|
|
||
| describe("ReactPlugin context props", () => { | ||
| beforeEach(() => { | ||
| mockParams = {}; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| (globalThis as Record<string, unknown>)[reactApp.name] = undefined; | ||
| }); | ||
|
|
||
| it("passes no context objects when the route has no params (base/dashboard mounts)", () => { | ||
| renderPlugin(); | ||
|
|
||
| expect(capturedProps?.dag).toBeUndefined(); | ||
| expect(capturedProps?.dagRun).toBeUndefined(); | ||
| expect(capturedProps?.taskInstance).toBeUndefined(); | ||
| expect(capturedProps?.asset).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("passes the cached Dag object when dagId is in the route", () => { | ||
| mockParams = { dagId: "my_dag" }; | ||
|
|
||
| renderPlugin(); | ||
|
|
||
| expect(capturedProps?.dagId).toBe("my_dag"); | ||
| expect(capturedProps?.dag).toStrictEqual(mockDag); | ||
| expect(capturedProps?.dagRun).toBeUndefined(); | ||
| expect(capturedProps?.taskInstance).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("passes the cached DagRun object when dagId and runId are in the route", () => { | ||
| mockParams = { dagId: "my_dag", runId: "run_1" }; | ||
|
|
||
| renderPlugin(); | ||
|
|
||
| expect(capturedProps?.dag).toStrictEqual(mockDag); | ||
| expect(capturedProps?.dagRun).toStrictEqual(mockDagRun); | ||
| expect(capturedProps?.taskInstance).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("passes the cached TaskInstance object when dagId, runId and taskId are in the route", () => { | ||
| mockParams = { dagId: "my_dag", runId: "run_1", taskId: "my_task" }; | ||
|
|
||
| renderPlugin(); | ||
|
|
||
| expect(capturedProps?.dag).toStrictEqual(mockDag); | ||
| expect(capturedProps?.dagRun).toStrictEqual(mockDagRun); | ||
| expect(capturedProps?.taskInstance).toStrictEqual(mockTaskInstance); | ||
| }); | ||
|
|
||
| it("passes the cached Asset object and its uri when assetId is in the route", () => { | ||
| mockParams = { assetId: "1" }; | ||
|
|
||
| renderPlugin(); | ||
|
|
||
| expect(capturedProps?.assetId).toBe("1"); | ||
| expect(capturedProps?.asset).toStrictEqual(mockAsset); | ||
| expect(capturedProps?.assetUri).toBe(mockAsset.uri); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.