frontend-app-api: Return ExtensionTreeNode instead of raw instance
Co-authored-by: Fredrik Adelöw <freben@gmail.com> Co-authored-by: Camila Belo <camilaibs@gmail.com> Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
```ts
|
||||
import { BackstagePlugin } from '@backstage/frontend-plugin-api';
|
||||
import { Config } from '@backstage/config';
|
||||
import { ConfigApi } from '@backstage/core-plugin-api';
|
||||
<<<<<<< HEAD
|
||||
import { JSX as JSX_2 } from 'react';
|
||||
@@ -20,24 +21,14 @@ export function createApp(options: {
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export function createExtensionTree(): ExtensionTree;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface ExtensionInstance {
|
||||
// (undocumented)
|
||||
readonly $$type: '@backstage/ExtensionInstance';
|
||||
readonly attachments: Map<string, ExtensionInstance[]>;
|
||||
getData<T>(ref: ExtensionDataRef<T>): T | undefined;
|
||||
// (undocumented)
|
||||
readonly id: string;
|
||||
}
|
||||
export function createExtensionTree(options: { config: Config }): ExtensionTree;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface ExtensionTree {
|
||||
// (undocumented)
|
||||
getExtension(id: string): ExtensionInstance | undefined;
|
||||
getExtension(id: string): ExtensionTreeNode | undefined;
|
||||
// (undocumented)
|
||||
getExtensionAttachments(id: string, inputName: string): ExtensionInstance[];
|
||||
getExtensionAttachments(id: string, inputName: string): ExtensionTreeNode[];
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import React, { JSX } from 'react';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { ConfigReader, Config } from '@backstage/config';
|
||||
import {
|
||||
BackstagePlugin,
|
||||
coreExtensionData,
|
||||
@@ -84,29 +84,29 @@ export interface ExtensionTreeNode {
|
||||
|
||||
/** @public */
|
||||
export interface ExtensionTree {
|
||||
getExtension(id: string): ExtensionInstance | undefined;
|
||||
getExtensionAttachments(id: string, inputName: string): ExtensionInstance[];
|
||||
getExtension(id: string): ExtensionTreeNode | undefined;
|
||||
getExtensionAttachments(id: string, inputName: string): ExtensionTreeNode[];
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export function createExtensionTree(): ExtensionTree {
|
||||
export function createExtensionTree(options: {
|
||||
config: Config;
|
||||
}): ExtensionTree {
|
||||
const plugins = getAvailablePlugins();
|
||||
const { instances } = createInstances({
|
||||
plugins,
|
||||
config: ConfigReader.fromConfigs(
|
||||
overrideBaseUrlConfigs(defaultConfigLoaderSync()),
|
||||
),
|
||||
config: options.config,
|
||||
});
|
||||
|
||||
return {
|
||||
getExtension(id: string): ExtensionInstance | undefined {
|
||||
getExtension(id: string): ExtensionTreeNode | undefined {
|
||||
return instances.get(id);
|
||||
},
|
||||
getExtensionAttachments(
|
||||
id: string,
|
||||
inputName: string,
|
||||
): ExtensionInstance[] {
|
||||
return this.getExtension(id)?.attachments.get(inputName) ?? [];
|
||||
): ExtensionTreeNode[] {
|
||||
return instances.get(id)?.attachments.get(inputName) ?? [];
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -116,7 +116,7 @@ export function createExtensionTree(): ExtensionTree {
|
||||
*/
|
||||
export function createInstances(options: {
|
||||
plugins: BackstagePlugin[];
|
||||
config: ConfigApi;
|
||||
config: Config;
|
||||
}) {
|
||||
const builtinExtensions = [Core, CoreRoutes, CoreNav, CoreLayout];
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export type { ExtensionInstance } from './createExtensionInstance';
|
||||
export {
|
||||
createApp,
|
||||
createExtensionTree,
|
||||
|
||||
Reference in New Issue
Block a user