@@ -24,46 +24,50 @@ import type { ReactAppResponse } from "openapi/requests/types.gen";
2424
2525import { ErrorPage } from "./Error" ;
2626
27- type PluginComponentType = FC < {
27+ export type PluginProps = {
2828 dagId ?: string ;
2929 mapIndex ?: string ;
3030 runId ?: string ;
3131 taskId ?: string ;
32- } > ;
32+ } ;
3333
34- export const ReactPlugin = ( { reactApp } : { readonly reactApp : ReactAppResponse } ) => {
35- const { dagId, mapIndex, runId, taskId } = useParams ( ) ;
34+ type PluginComponentType = FC < PluginProps > ;
3635
37- const Plugin = lazy ( ( ) =>
38- // We are assuming the plugin manager is trusted and the bundle_url is safe
39- import ( /* @vite -ignore */ reactApp . bundle_url )
40- . then ( ( ) => {
41- // Store components in globalThis[reactApp.name] to avoid conflicts with the shared globalThis.AirflowPlugin
42- // global variable.
43- let pluginComponent = ( globalThis as Record < string , unknown > ) [ reactApp . name ] as
44- | PluginComponentType
45- | undefined ;
36+ const loadPlugin = ( reactApp : ReactAppResponse ) : Promise < { default : PluginComponentType } > =>
37+ // We are assuming the plugin manager is trusted and the bundle_url is safe
38+ import ( /* @vite -ignore */ reactApp . bundle_url )
39+ . then ( ( ) => {
40+ // Store components in globalThis[reactApp.name] to avoid conflicts with the shared globalThis.AirflowPlugin
41+ // global variable.
42+ let pluginComponent = ( globalThis as Record < string , unknown > ) [ reactApp . name ] as
43+ | PluginComponentType
44+ | undefined ;
4645
47- if ( pluginComponent === undefined ) {
48- pluginComponent = ( globalThis as Record < string , unknown > ) . AirflowPlugin as PluginComponentType ;
46+ if ( pluginComponent === undefined ) {
47+ pluginComponent = ( globalThis as Record < string , unknown > ) . AirflowPlugin as PluginComponentType ;
4948
50- ( globalThis as Record < string , unknown > ) [ reactApp . name ] = pluginComponent ;
51- }
49+ ( globalThis as Record < string , unknown > ) [ reactApp . name ] = pluginComponent ;
50+ }
5251
53- if ( typeof pluginComponent !== "function" ) {
54- throw new TypeError ( `Expected function, got ${ typeof pluginComponent } for plugin ${ reactApp . name } ` ) ;
55- }
52+ if ( typeof pluginComponent !== "function" ) {
53+ throw new TypeError ( `Expected function, got ${ typeof pluginComponent } for plugin ${ reactApp . name } ` ) ;
54+ }
5655
57- return { default : pluginComponent } ;
58- } )
59- . catch ( ( error : unknown ) => {
60- console . error ( "Component Failed Loading:" , error ) ;
56+ return { default : pluginComponent } ;
57+ } )
58+ . catch ( ( error : unknown ) => {
59+ // eslint-disable-next-line no-console
60+ console . error ( "Component failed to load:" , error ) ;
6161
62- return {
63- default : ErrorPage ,
64- } ;
65- } ) ,
66- ) ;
62+ return {
63+ default : ErrorPage ,
64+ } ;
65+ } ) ;
66+
67+ export const ReactPlugin = ( { reactApp } : { readonly reactApp : ReactAppResponse } ) => {
68+ const { dagId, mapIndex, runId, taskId } = useParams ( ) ;
69+
70+ const Plugin = lazy ( ( ) => loadPlugin ( reactApp ) ) ;
6771
6872 return (
6973 < Suspense fallback = { < Spinner /> } >
0 commit comments