@backstage/frontend-plugin-api 0.13.2-next.0 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @backstage/frontend-plugin-api
2
2
 
3
+ ## 0.13.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 75683ed: Added a new `errorPresentation` prop to `ExtensionBoundary` to control how errors are presented to the user. The default is `'error-display'`, which is the current behavior of showing the error in the `ErrorDisplay` component. The new option is `'error-api'`, posts errors to the `ErrorApi` and does not allow retries.
8
+
9
+ The `AppRootElementBlueprint` now wraps its element in an `ErrorBoundary` using the new `'error-api'` presentation mode.
10
+
11
+ - 0bc1ce9: Fixed a versioning conflict that could result in a `.withContext` is not a function error.
12
+ - f3f84f1: Made the return type of `.withOverrides` to be simplified.
13
+ - 97cd16f: Reversed the relationship between the old `@backstage/core-plugin-api` and the new `@backstage/frontend-plugin-api`. Previously, the a lot of API definitions and utilities where defined in the old and re-exported from the old, but this change flips that around so that they now reside in the new package and are re-exported from the old. The external API of both packages remain the same, but this is a step towards being able to add further compatibility with the new frontend system built into the old.
14
+ - 9b8bde4: Removed unnecessary dependencies on `@backstage/core-components`, `@backstage/config`, `@material-ui/core`, and `lodash`.
15
+
16
+ ## 0.13.2-next.1
17
+
18
+ ### Patch Changes
19
+
20
+ - 75683ed: Added a new `errorPresentation` prop to `ExtensionBoundary` to control how errors are presented to the user. The default is `'error-display'`, which is the current behavior of showing the error in the `ErrorDisplay` component. The new option is `'error-api'`, posts errors to the `ErrorApi` and does not allow retries.
21
+
22
+ The `AppRootElementBlueprint` now wraps its element in an `ErrorBoundary` using the new `'error-api'` presentation mode.
23
+
24
+ - f3f84f1: Made the return type of `.withOverrides` to be simplified.
25
+ - Updated dependencies
26
+ - @backstage/core-components@0.18.4-next.2
27
+ - @backstage/config@1.3.6
28
+ - @backstage/errors@1.2.7
29
+ - @backstage/types@1.2.2
30
+ - @backstage/version-bridge@1.0.11
31
+
3
32
  ## 0.13.2-next.0
4
33
 
5
34
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigApi.esm.js","sources":["../../../src/apis/definitions/ConfigApi.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ApiRef, createApiRef } from '../system';\nimport { Config } from '@backstage/config';\n\n/**\n * The Config API is used to provide a mechanism to access the\n * runtime configuration of the system.\n *\n * @public\n */\nexport type ConfigApi = Config;\n\n/**\n * The {@link ApiRef} of {@link ConfigApi}.\n *\n * @public\n */\nexport const configApiRef: ApiRef<ConfigApi> = createApiRef({\n id: 'core.config',\n});\n"],"names":[],"mappings":";;;;;AA+BO,MAAM,eAAkC,YAAA,CAAa;AAAA,EAC1D,EAAA,EAAI;AACN,CAAC;;;;"}
1
+ {"version":3,"file":"ConfigApi.esm.js","sources":["../../../src/apis/definitions/ConfigApi.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ApiRef, createApiRef } from '../system';\nimport type { Config } from '@backstage/config';\n\n/**\n * The Config API is used to provide a mechanism to access the\n * runtime configuration of the system.\n *\n * @public\n */\nexport type ConfigApi = Config;\n\n/**\n * The {@link ApiRef} of {@link ConfigApi}.\n *\n * @public\n */\nexport const configApiRef: ApiRef<ConfigApi> = createApiRef({\n id: 'core.config',\n});\n"],"names":[],"mappings":";;;;;AA+BO,MAAM,eAAkC,YAAA,CAAa;AAAA,EAC1D,EAAA,EAAI;AACN,CAAC;;;;"}
@@ -1,3 +1,5 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { ExtensionBoundary } from '@backstage/frontend-plugin-api';
1
3
  import { coreExtensionData } from '../wiring/coreExtensionData.esm.js';
2
4
  import 'zod';
3
5
  import 'zod-to-json-schema';
@@ -7,8 +9,10 @@ const AppRootElementBlueprint = createExtensionBlueprint({
7
9
  kind: "app-root-element",
8
10
  attachTo: { id: "app/root", input: "elements" },
9
11
  output: [coreExtensionData.reactElement],
10
- *factory(params) {
11
- yield coreExtensionData.reactElement(params.element);
12
+ *factory(params, { node }) {
13
+ yield coreExtensionData.reactElement(
14
+ /* @__PURE__ */ jsx(ExtensionBoundary, { node, errorPresentation: "error-api", children: params.element })
15
+ );
12
16
  }
13
17
  });
14
18
 
@@ -1 +1 @@
1
- {"version":3,"file":"AppRootElementBlueprint.esm.js","sources":["../../src/blueprints/AppRootElementBlueprint.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { coreExtensionData, createExtensionBlueprint } from '../wiring';\n\n/**\n * Creates extensions that render a React element at the app root, outside of\n * the app layout. This is useful for example for shared popups and similar.\n *\n * @public\n */\nexport const AppRootElementBlueprint = createExtensionBlueprint({\n kind: 'app-root-element',\n attachTo: { id: 'app/root', input: 'elements' },\n output: [coreExtensionData.reactElement],\n *factory(params: { element: JSX.Element }) {\n yield coreExtensionData.reactElement(params.element);\n },\n});\n"],"names":[],"mappings":";;;;;AAwBO,MAAM,0BAA0B,wBAAA,CAAyB;AAAA,EAC9D,IAAA,EAAM,kBAAA;AAAA,EACN,QAAA,EAAU,EAAE,EAAA,EAAI,UAAA,EAAY,OAAO,UAAA,EAAW;AAAA,EAC9C,MAAA,EAAQ,CAAC,iBAAA,CAAkB,YAAY,CAAA;AAAA,EACvC,CAAC,QAAQ,MAAA,EAAkC;AACzC,IAAA,MAAM,iBAAA,CAAkB,YAAA,CAAa,MAAA,CAAO,OAAO,CAAA;AAAA,EACrD;AACF,CAAC;;;;"}
1
+ {"version":3,"file":"AppRootElementBlueprint.esm.js","sources":["../../src/blueprints/AppRootElementBlueprint.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ExtensionBoundary } from '@backstage/frontend-plugin-api';\nimport { coreExtensionData, createExtensionBlueprint } from '../wiring';\n\n/**\n * Creates extensions that render a React element at the app root, outside of\n * the app layout. This is useful for example for shared popups and similar.\n *\n * @public\n */\nexport const AppRootElementBlueprint = createExtensionBlueprint({\n kind: 'app-root-element',\n attachTo: { id: 'app/root', input: 'elements' },\n output: [coreExtensionData.reactElement],\n *factory(params: { element: JSX.Element }, { node }) {\n yield coreExtensionData.reactElement(\n <ExtensionBoundary node={node} errorPresentation=\"error-api\">\n {params.element}\n </ExtensionBoundary>,\n );\n },\n});\n"],"names":[],"mappings":";;;;;;;AAyBO,MAAM,0BAA0B,wBAAA,CAAyB;AAAA,EAC9D,IAAA,EAAM,kBAAA;AAAA,EACN,QAAA,EAAU,EAAE,EAAA,EAAI,UAAA,EAAY,OAAO,UAAA,EAAW;AAAA,EAC9C,MAAA,EAAQ,CAAC,iBAAA,CAAkB,YAAY,CAAA;AAAA,EACvC,CAAC,OAAA,CAAQ,MAAA,EAAkC,EAAE,MAAK,EAAG;AACnD,IAAA,MAAM,iBAAA,CAAkB,YAAA;AAAA,0BACrB,iBAAA,EAAA,EAAkB,IAAA,EAAY,iBAAA,EAAkB,WAAA,EAC9C,iBAAO,OAAA,EACV;AAAA,KACF;AAAA,EACF;AACF,CAAC;;;;"}
@@ -0,0 +1,24 @@
1
+ import { Component } from 'react';
2
+ import { ForwardedError } from '@backstage/errors';
3
+
4
+ class ErrorApiBoundary extends Component {
5
+ static getDerivedStateFromError(error) {
6
+ return { error };
7
+ }
8
+ state = { error: void 0 };
9
+ componentDidCatch(error, _errorInfo) {
10
+ const { node, errorApi } = this.props;
11
+ errorApi?.post(
12
+ new ForwardedError(`Error in extension '${node.spec.id}'`, error)
13
+ );
14
+ }
15
+ render() {
16
+ if (this.state.error) {
17
+ return null;
18
+ }
19
+ return this.props.children;
20
+ }
21
+ }
22
+
23
+ export { ErrorApiBoundary };
24
+ //# sourceMappingURL=ErrorApiBoundary.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorApiBoundary.esm.js","sources":["../../src/components/ErrorApiBoundary.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Component, ErrorInfo, ReactNode } from 'react';\nimport { AppNode, ErrorApi } from '../apis';\nimport { ForwardedError } from '@backstage/errors';\n\n/** @internal */\nexport class ErrorApiBoundary extends Component<\n {\n children: ReactNode;\n node: AppNode;\n errorApi?: ErrorApi;\n },\n { error?: Error }\n> {\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n state = { error: undefined };\n\n componentDidCatch(error: Error, _errorInfo: ErrorInfo) {\n const { node, errorApi } = this.props;\n errorApi?.post(\n new ForwardedError(`Error in extension '${node.spec.id}'`, error),\n );\n }\n\n render() {\n if (this.state.error) {\n return null;\n }\n\n return this.props.children;\n }\n}\n"],"names":[],"mappings":";;;AAqBO,MAAM,yBAAyB,SAAA,CAOpC;AAAA,EACA,OAAO,yBAAyB,KAAA,EAAc;AAC5C,IAAA,OAAO,EAAE,KAAA,EAAM;AAAA,EACjB;AAAA,EAEA,KAAA,GAAQ,EAAE,KAAA,EAAO,MAAA,EAAU;AAAA,EAE3B,iBAAA,CAAkB,OAAc,UAAA,EAAuB;AACrD,IAAA,MAAM,EAAE,IAAA,EAAM,QAAA,EAAS,GAAI,IAAA,CAAK,KAAA;AAChC,IAAA,QAAA,EAAU,IAAA;AAAA,MACR,IAAI,cAAA,CAAe,CAAA,oBAAA,EAAuB,KAAK,IAAA,CAAK,EAAE,KAAK,KAAK;AAAA,KAClE;AAAA,EACF;AAAA,EAEA,MAAA,GAAS;AACP,IAAA,IAAI,IAAA,CAAK,MAAM,KAAA,EAAO;AACpB,MAAA,OAAO,IAAA;AAAA,IACT;AAEA,IAAA,OAAO,KAAK,KAAA,CAAM,QAAA;AAAA,EACpB;AACF;;;;"}
@@ -2,7 +2,7 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import { Component } from 'react';
3
3
  import { ErrorDisplay } from './DefaultSwappableComponents.esm.js';
4
4
 
5
- class ErrorBoundary extends Component {
5
+ class ErrorDisplayBoundary extends Component {
6
6
  static getDerivedStateFromError(error) {
7
7
  return { error };
8
8
  }
@@ -27,5 +27,5 @@ class ErrorBoundary extends Component {
27
27
  }
28
28
  }
29
29
 
30
- export { ErrorBoundary };
31
- //# sourceMappingURL=ErrorBoundary.esm.js.map
30
+ export { ErrorDisplayBoundary };
31
+ //# sourceMappingURL=ErrorDisplayBoundary.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorDisplayBoundary.esm.js","sources":["../../src/components/ErrorDisplayBoundary.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Component, ReactNode } from 'react';\nimport { FrontendPlugin } from '../wiring';\nimport { ErrorDisplay } from './DefaultSwappableComponents';\n\n/** @internal */\nexport class ErrorDisplayBoundary extends Component<\n {\n children: ReactNode;\n plugin: FrontendPlugin;\n },\n { error?: Error }\n> {\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n state = { error: undefined };\n\n handleErrorReset = () => {\n this.setState({ error: undefined });\n };\n\n render() {\n const { error } = this.state;\n const { plugin, children } = this.props;\n\n if (error) {\n return (\n <ErrorDisplay\n // todo: do we want to just use useAppNode hook in the ErrorDisplay instead?\n plugin={plugin}\n error={error}\n // todo: probably change this to onResetError\n resetError={this.handleErrorReset}\n />\n );\n }\n\n return children;\n }\n}\n"],"names":[],"mappings":";;;;AAqBO,MAAM,6BAA6B,SAAA,CAMxC;AAAA,EACA,OAAO,yBAAyB,KAAA,EAAc;AAC5C,IAAA,OAAO,EAAE,KAAA,EAAM;AAAA,EACjB;AAAA,EAEA,KAAA,GAAQ,EAAE,KAAA,EAAO,MAAA,EAAU;AAAA,EAE3B,mBAAmB,MAAM;AACvB,IAAA,IAAA,CAAK,QAAA,CAAS,EAAE,KAAA,EAAO,MAAA,EAAW,CAAA;AAAA,EACpC,CAAA;AAAA,EAEA,MAAA,GAAS;AACP,IAAA,MAAM,EAAE,KAAA,EAAM,GAAI,IAAA,CAAK,KAAA;AACvB,IAAA,MAAM,EAAE,MAAA,EAAQ,QAAA,EAAS,GAAI,IAAA,CAAK,KAAA;AAElC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,uBACE,GAAA;AAAA,QAAC,YAAA;AAAA,QAAA;AAAA,UAEC,MAAA;AAAA,UACA,KAAA;AAAA,UAEA,YAAY,IAAA,CAAK;AAAA;AAAA,OACnB;AAAA,IAEJ;AAEA,IAAA,OAAO,QAAA;AAAA,EACT;AACF;;;;"}
@@ -2,8 +2,29 @@ import { jsx, Fragment } from 'react/jsx-runtime';
2
2
  import { lazy, Suspense, useEffect } from 'react';
3
3
  import { AnalyticsContext } from '../analytics/AnalyticsContext.esm.js';
4
4
  import { useAnalytics } from '../analytics/useAnalytics.esm.js';
5
- import { ErrorBoundary } from './ErrorBoundary.esm.js';
5
+ import { ErrorDisplayBoundary } from './ErrorDisplayBoundary.esm.js';
6
+ import { ErrorApiBoundary } from './ErrorApiBoundary.esm.js';
6
7
  import { routableExtensionRenderedEvent } from '../core-plugin-api/src/analytics/Tracker.esm.js';
8
+ import '../apis/definitions/AppTreeApi.esm.js';
9
+ import '../apis/definitions/auth.esm.js';
10
+ import '../apis/definitions/AlertApi.esm.js';
11
+ import '../apis/definitions/AppLanguageApi.esm.js';
12
+ import '../apis/definitions/AppThemeApi.esm.js';
13
+ import '../apis/definitions/SwappableComponentsApi.esm.js';
14
+ import '../apis/definitions/ConfigApi.esm.js';
15
+ import '../apis/definitions/DiscoveryApi.esm.js';
16
+ import { errorApiRef } from '../apis/definitions/ErrorApi.esm.js';
17
+ import '../apis/definitions/FeatureFlagsApi.esm.js';
18
+ import '../apis/definitions/FetchApi.esm.js';
19
+ import '../apis/definitions/IconsApi.esm.js';
20
+ import '../apis/definitions/IdentityApi.esm.js';
21
+ import '../apis/definitions/DialogApi.esm.js';
22
+ import '../apis/definitions/OAuthRequestApi.esm.js';
23
+ import '../apis/definitions/RouteResolutionApi.esm.js';
24
+ import '../apis/definitions/StorageApi.esm.js';
25
+ import '../apis/definitions/AnalyticsApi.esm.js';
26
+ import '../apis/definitions/TranslationApi.esm.js';
27
+ import { useApi } from '../apis/system/useApi.esm.js';
7
28
  import { coreExtensionData } from '../wiring/coreExtensionData.esm.js';
8
29
  import 'zod';
9
30
  import 'zod-to-json-schema';
@@ -11,6 +32,13 @@ import '../wiring/createExtensionBlueprint.esm.js';
11
32
  import { AppNodeProvider } from './AppNodeProvider.esm.js';
12
33
  import { Progress } from './DefaultSwappableComponents.esm.js';
13
34
 
35
+ function useOptionalErrorApi() {
36
+ try {
37
+ return useApi(errorApiRef);
38
+ } catch {
39
+ return void 0;
40
+ }
41
+ }
14
42
  const RouteTracker = (props) => {
15
43
  const { enabled, children } = props;
16
44
  const analytics = useAnalytics();
@@ -23,15 +51,22 @@ const RouteTracker = (props) => {
23
51
  };
24
52
  function ExtensionBoundary(props) {
25
53
  const { node, children } = props;
54
+ const errorApi = useOptionalErrorApi();
26
55
  const hasRoutePathOutput = Boolean(
27
56
  node.instance?.getData(coreExtensionData.routePath)
28
57
  );
29
58
  const plugin = node.spec.plugin;
30
59
  const attributes = {
31
60
  extensionId: node.spec.id,
32
- pluginId: node.spec.plugin?.id ?? "app"
61
+ pluginId: plugin.id ?? "app"
33
62
  };
34
- return /* @__PURE__ */ jsx(AppNodeProvider, { node, children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(Progress, {}), children: /* @__PURE__ */ jsx(ErrorBoundary, { plugin, children: /* @__PURE__ */ jsx(AnalyticsContext, { attributes, children: /* @__PURE__ */ jsx(RouteTracker, { enabled: hasRoutePathOutput, children }) }) }) }) });
63
+ let content = /* @__PURE__ */ jsx(AnalyticsContext, { attributes, children: /* @__PURE__ */ jsx(RouteTracker, { enabled: hasRoutePathOutput, children }) });
64
+ if (props.errorPresentation === "error-api") {
65
+ content = /* @__PURE__ */ jsx(ErrorApiBoundary, { node, errorApi, children: content });
66
+ } else {
67
+ content = /* @__PURE__ */ jsx(ErrorDisplayBoundary, { plugin, children: content });
68
+ }
69
+ return /* @__PURE__ */ jsx(AppNodeProvider, { node, children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(Progress, {}), children: content }) });
35
70
  }
36
71
  ((ExtensionBoundary2) => {
37
72
  function lazy$1(appNode, loader) {
@@ -1 +1 @@
1
- {"version":3,"file":"ExtensionBoundary.esm.js","sources":["../../src/components/ExtensionBoundary.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n PropsWithChildren,\n ReactNode,\n Suspense,\n useEffect,\n lazy as reactLazy,\n} from 'react';\nimport { AnalyticsContext, useAnalytics } from '../analytics';\nimport { ErrorBoundary } from './ErrorBoundary';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { routableExtensionRenderedEvent } from '../../../core-plugin-api/src/analytics/Tracker';\nimport { AppNode } from '../apis';\nimport { coreExtensionData } from '../wiring';\nimport { AppNodeProvider } from './AppNodeProvider';\nimport { Progress } from './DefaultSwappableComponents';\n\ntype RouteTrackerProps = PropsWithChildren<{\n enabled?: boolean;\n}>;\n\nconst RouteTracker = (props: RouteTrackerProps) => {\n const { enabled, children } = props;\n const analytics = useAnalytics();\n\n // This event, never exposed to end-users of the analytics API,\n // helps inform which extension metadata gets associated with a\n // navigation event when the route navigated to is a gathered\n // mountpoint.\n useEffect(() => {\n if (enabled) {\n analytics.captureEvent(routableExtensionRenderedEvent, '');\n }\n }, [analytics, enabled]);\n\n return <>{children}</>;\n};\n\n/** @public */\nexport interface ExtensionBoundaryProps {\n node: AppNode;\n children: ReactNode;\n}\n\n/** @public */\nexport function ExtensionBoundary(props: ExtensionBoundaryProps) {\n const { node, children } = props;\n\n const hasRoutePathOutput = Boolean(\n node.instance?.getData(coreExtensionData.routePath),\n );\n\n const plugin = node.spec.plugin;\n\n // Skipping \"routeRef\" attribute in the new system, the extension \"id\" should provide more insight\n const attributes = {\n extensionId: node.spec.id,\n pluginId: node.spec.plugin?.id ?? 'app',\n };\n\n return (\n <AppNodeProvider node={node}>\n <Suspense fallback={<Progress />}>\n <ErrorBoundary plugin={plugin}>\n <AnalyticsContext attributes={attributes}>\n <RouteTracker enabled={hasRoutePathOutput}>{children}</RouteTracker>\n </AnalyticsContext>\n </ErrorBoundary>\n </Suspense>\n </AppNodeProvider>\n );\n}\n\n/** @public */\nexport namespace ExtensionBoundary {\n export function lazy(\n appNode: AppNode,\n loader: () => Promise<JSX.Element>,\n ): JSX.Element {\n const ExtensionComponent = reactLazy(() =>\n loader().then(element => ({ default: () => element })),\n );\n return (\n <ExtensionBoundary node={appNode}>\n <ExtensionComponent />\n </ExtensionBoundary>\n );\n }\n\n export function lazyComponent<TProps extends {}>(\n appNode: AppNode,\n loader: () => Promise<(props: TProps) => JSX.Element>,\n ): (props: TProps) => JSX.Element {\n const ExtensionComponent = reactLazy(() =>\n loader().then(Component => ({ default: Component })),\n ) as unknown as React.ComponentType<TProps>;\n\n return (props: TProps) => (\n <ExtensionBoundary node={appNode}>\n <ExtensionComponent {...props} />\n </ExtensionBoundary>\n );\n }\n}\n"],"names":["ExtensionBoundary","lazy","reactLazy"],"mappings":";;;;;;;;;;;;;AAoCA,MAAM,YAAA,GAAe,CAAC,KAAA,KAA6B;AACjD,E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,kBAAA,GAAqBC,IAAA;AAAA,MAAU,MACnC,QAAO,CAAE,IAAA,CAAK,cAAY,EAAE,OAAA,EAAS,MAAM,OAAA,EAAQ,CAAE;AAAA,KACvD;AACA,IAAA,2BACGF,kBAAAA,EAAA,EAAkB,MAAM,OAAA,EACvB,QAAA,kBAAA,GAAA,CAAC,sBAAmB,CAAA,EACtB,CAAA;AAAA,EAEJ;AAZO,EAAAA,kBAAAA,CAAS,IAAA,GAAAC,MAAA;AAcT,EAAA,SAAS,aAAA,CACd,SACA,MAAA,EACgC;AAChC,IAAA,MAAM,kBAAA,GAAqBC,IAAA;AAAA,MAAU,MACnC,QAAO,CAAE,IAAA,CAAK,gBAAc,EAAE,OAAA,EAAS,WAAU,CAAE;AAAA,KACrD;AAEA,IAAA,OAAO,CAAC,KAAA,qBACN,GAAA,CAACF,kBAAAA,EAAA,EAAkB,IAAA,EAAM,OAAA,EACvB,QAAA,kBAAA,GAAA,CAAC,kBAAA,EAAA,EAAoB,GAAG,KAAA,EAAO,CAAA,EACjC,CAAA;AAAA,EAEJ;AAbO,EAAAA,kBAAAA,CAAS,aAAA,GAAA,aAAA;AAAA,CAAA,EAfD,iBAAA,KAAA,iBAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"ExtensionBoundary.esm.js","sources":["../../src/components/ExtensionBoundary.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n PropsWithChildren,\n ReactNode,\n Suspense,\n useEffect,\n lazy as reactLazy,\n} from 'react';\nimport { AnalyticsContext, useAnalytics } from '../analytics';\nimport { ErrorDisplayBoundary } from './ErrorDisplayBoundary';\nimport { ErrorApiBoundary } from './ErrorApiBoundary';\n// eslint-disable-next-line @backstage/no-relative-monorepo-imports\nimport { routableExtensionRenderedEvent } from '../../../core-plugin-api/src/analytics/Tracker';\nimport { AppNode, ErrorApi, errorApiRef, useApi } from '../apis';\nimport { coreExtensionData } from '../wiring';\nimport { AppNodeProvider } from './AppNodeProvider';\nimport { Progress } from './DefaultSwappableComponents';\n\nfunction useOptionalErrorApi(): ErrorApi | undefined {\n try {\n return useApi(errorApiRef);\n } catch {\n return undefined;\n }\n}\n\ntype RouteTrackerProps = PropsWithChildren<{\n enabled?: boolean;\n}>;\n\nconst RouteTracker = (props: RouteTrackerProps) => {\n const { enabled, children } = props;\n const analytics = useAnalytics();\n\n // This event, never exposed to end-users of the analytics API,\n // helps inform which extension metadata gets associated with a\n // navigation event when the route navigated to is a gathered\n // mountpoint.\n useEffect(() => {\n if (enabled) {\n analytics.captureEvent(routableExtensionRenderedEvent, '');\n }\n }, [analytics, enabled]);\n\n return <>{children}</>;\n};\n\n/** @public */\nexport interface ExtensionBoundaryProps {\n errorPresentation?: 'error-api' | 'error-display';\n node: AppNode;\n children: ReactNode;\n}\n\n/** @public */\nexport function ExtensionBoundary(props: ExtensionBoundaryProps) {\n const { node, children } = props;\n\n const errorApi = useOptionalErrorApi();\n\n const hasRoutePathOutput = Boolean(\n node.instance?.getData(coreExtensionData.routePath),\n );\n\n const plugin = node.spec.plugin;\n\n // Skipping \"routeRef\" attribute in the new system, the extension \"id\" should provide more insight\n const attributes = {\n extensionId: node.spec.id,\n pluginId: plugin.id ?? 'app',\n };\n\n let content = (\n <AnalyticsContext attributes={attributes}>\n <RouteTracker enabled={hasRoutePathOutput}>{children}</RouteTracker>\n </AnalyticsContext>\n );\n\n if (props.errorPresentation === 'error-api') {\n content = (\n <ErrorApiBoundary node={node} errorApi={errorApi}>\n {content}\n </ErrorApiBoundary>\n );\n } else {\n content = (\n <ErrorDisplayBoundary plugin={plugin}>{content}</ErrorDisplayBoundary>\n );\n }\n\n return (\n <AppNodeProvider node={node}>\n <Suspense fallback={<Progress />}>{content}</Suspense>\n </AppNodeProvider>\n );\n}\n\n/** @public */\nexport namespace ExtensionBoundary {\n export function lazy(\n appNode: AppNode,\n loader: () => Promise<JSX.Element>,\n ): JSX.Element {\n const ExtensionComponent = reactLazy(() =>\n loader().then(element => ({ default: () => element })),\n );\n return (\n <ExtensionBoundary node={appNode}>\n <ExtensionComponent />\n </ExtensionBoundary>\n );\n }\n\n export function lazyComponent<TProps extends {}>(\n appNode: AppNode,\n loader: () => Promise<(props: TProps) => JSX.Element>,\n ): (props: TProps) => JSX.Element {\n const ExtensionComponent = reactLazy(() =>\n loader().then(Component => ({ default: Component })),\n ) as unknown as React.ComponentType<TProps>;\n\n return (props: TProps) => (\n <ExtensionBoundary node={appNode}>\n <ExtensionComponent {...props} />\n </ExtensionBoundary>\n );\n }\n}\n"],"names":["ExtensionBoundary","lazy","reactLazy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAS,mBAAA,GAA4C;AACnD,EAAA,IAAI;AACF,IAAA,OAAO,OAAO,WAAW,CAAA;AAAA,EAC3B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAMA,MAAM,YAAA,GAAe,CAAC,KAAA,KAA6B;AACjD,EAAA,MAAM,EAAE,OAAA,EAAS,QAAA,EAAS,GAAI,KAAA;AAC9B,EAAA,MAAM,YAAY,YAAA,EAAa;AAM/B,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,SAAA,CAAU,YAAA,CAAa,gCAAgC,EAAE,CAAA;AAAA,IAC3D;AAAA,EACF,CAAA,EAAG,CAAC,SAAA,EAAW,OAAO,CAAC,CAAA;AAEvB,EAAA,uCAAU,QAAA,EAAS,CAAA;AACrB,CAAA;AAUO,SAAS,kBAAkB,KAAA,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