diff --git a/graph/client/src/app/ui-components/error-boundary.tsx b/graph/client/src/app/ui-components/error-boundary.tsx index e4993ca9a47e8..1c9522cc31585 100644 --- a/graph/client/src/app/ui-components/error-boundary.tsx +++ b/graph/client/src/app/ui-components/error-boundary.tsx @@ -5,12 +5,12 @@ import { useEnvironmentConfig, usePoll, } from '@nx/graph/shared'; -import { ErrorRenderer } from '@nx/graph/ui-components'; import { isRouteErrorResponse, useParams, useRouteError, } from 'react-router-dom'; +import { ErrorPage } from './error-page'; export function ErrorBoundary() { let error = useRouteError(); @@ -63,38 +63,11 @@ export function ErrorBoundary() { return (
{environment !== 'nx-console' && } -
-

Error

-
- -
- {hasErrorData && ( -
-

- Nx encountered the following issues while processing the project - graph:{' '} -

-
- -
-
- )} -
-
- ); -} - -function ErrorWithStack({ - message, - stack, -}: { - message: string | JSX.Element; - stack?: string; -}) { - return ( -
-

{message}

- {stack &&

Error message: {stack}

} +
); } diff --git a/graph/client/src/app/ui-components/error-page.tsx b/graph/client/src/app/ui-components/error-page.tsx new file mode 100644 index 0000000000000..c7a2537cb6327 --- /dev/null +++ b/graph/client/src/app/ui-components/error-page.tsx @@ -0,0 +1,48 @@ +/* eslint-disable @nx/enforce-module-boundaries */ +// nx-ignore-next-line +import { ErrorRenderer } from '@nx/graph/ui-components'; +import { GraphError } from 'nx/src/command-line/graph/graph'; +/* eslint-enable @nx/enforce-module-boundaries */ + +export type ErrorPageProps = { + message: string | JSX.Element; + stack?: string; + errors: GraphError[]; +}; + +export function ErrorPage({ message, stack, errors }: ErrorPageProps) { + return ( +
+

Error

+
+ +
+ {errors && ( +
+

+ Nx encountered the following issues while processing the project + graph:{' '} +

+
+ +
+
+ )} +
+ ); +} + +function ErrorWithStack({ + message, + stack, +}: { + message: string | JSX.Element; + stack?: string; +}) { + return ( +
+

{message}

+ {stack &&

Error message: {stack}

} +
+ ); +} diff --git a/graph/client/src/globals.d.ts b/graph/client/src/globals.d.ts index 844bea3c3d1b3..d6543e51810a3 100644 --- a/graph/client/src/globals.d.ts +++ b/graph/client/src/globals.d.ts @@ -20,6 +20,11 @@ export declare global { appConfig: AppConfig; useXstateInspect: boolean; externalApi?: ExternalApi; + + // using bundled graph components directly from outside the graph app + __NX_RENDER_GRAPH__?: boolean; + renderPDV?: (data: any) => void; + renderError?: (data: any) => void; } } declare module 'cytoscape' { diff --git a/graph/client/src/main.tsx b/graph/client/src/main.tsx index 7ad6c5b98f45e..82e3fcddf2102 100644 --- a/graph/client/src/main.tsx +++ b/graph/client/src/main.tsx @@ -9,30 +9,58 @@ import { inspect } from '@xstate/inspect'; import { App } from './app/app'; import { ExternalApiImpl } from './app/external-api-impl'; import { render } from 'preact'; +import { ErrorToastUI, ExpandedTargetsProvider } from '@nx/graph/shared'; +import { ProjectDetails } from '@nx/graph-internal/ui-project-details'; +import { ErrorPage } from './app/ui-components/error-page'; -if (window.useXstateInspect === true) { - inspect({ - url: 'https://stately.ai/viz?inspect', - iframe: false, // open in new window - }); -} - -window.externalApi = new ExternalApiImpl(); -const container = document.getElementById('app'); +if (window.__NX_RENDER_GRAPH__ === false) { + window.renderPDV = (data: any) => { + const container = document.getElementById('app'); + render( + + + + + + , + container + ); + }; -if (!window.appConfig) { - render( -

- No environment could be found. Please run{' '} -

npx nx run graph-client:generate-dev-environment-js
. -

, - container - ); + window.renderError = (data: any) => { + const container = document.getElementById('app'); + render( + + + , + container + ); + }; } else { - render( - - - , - container - ); + if (window.useXstateInspect === true) { + inspect({ + url: 'https://stately.ai/viz?inspect', + iframe: false, // open in new window + }); + } + + window.externalApi = new ExternalApiImpl(); + const container = document.getElementById('app'); + + if (!window.appConfig) { + render( +

+ No environment could be found. Please run{' '} +

npx nx run graph-client:generate-dev-environment-js
. +

, + container + ); + } else { + render( + + + , + container + ); + } }