Merge pull request #15556 from drodil/app_feature_flags

feat: allow specifying app level feature flags
This commit is contained in:
Ben Lambert
2023-01-10 14:30:47 +01:00
committed by GitHub
11 changed files with 67 additions and 8 deletions
+1
View File
@@ -51,6 +51,7 @@ export function createApp(
...options?.icons,
},
plugins: (options?.plugins as BackstagePlugin[]) ?? [],
featureFlags: options?.featureFlags ?? [],
themes: options?.themes ?? themes,
});
}
+4
View File
@@ -115,6 +115,10 @@ const app = createApp({
// Custom icon example
alert: AlarmIcon,
},
// Example of application level feature flag
// featureFlags: [
// { name: 'tech-radar', description: 'Enables the tech radar plugin' },
// ],
components: {
SignInPage: props => {
return (
+1
View File
@@ -208,6 +208,7 @@ export type AppOptions = {
>;
}
>;
featureFlags?: (FeatureFlag & Omit<FeatureFlag, 'pluginId'>)[];
components: AppComponents;
themes: (Partial<AppTheme> & Omit<AppTheme, 'theme'>)[];
configLoader?: AppConfigLoader;
@@ -40,6 +40,7 @@ import {
featureFlagsApiRef,
identityApiRef,
BackstagePlugin,
FeatureFlag,
} from '@backstage/core-plugin-api';
import { ApiFactoryRegistry, ApiResolver } from '../apis/system';
import {
@@ -211,6 +212,8 @@ export class AppManager implements BackstageApp {
private readonly apis: Iterable<AnyApiFactory>;
private readonly icons: NonNullable<AppOptions['icons']>;
private readonly plugins: Set<CompatiblePlugin>;
private readonly featureFlags: (FeatureFlag &
Omit<FeatureFlag, 'pluginId'>)[];
private readonly components: AppComponents;
private readonly themes: AppTheme[];
private readonly configLoader?: AppConfigLoader;
@@ -224,6 +227,7 @@ export class AppManager implements BackstageApp {
this.apis = options.apis ?? [];
this.icons = options.icons;
this.plugins = new Set((options.plugins as CompatiblePlugin[]) ?? []);
this.featureFlags = options.featureFlags ?? [];
this.components = options.components;
this.themes = options.themes as AppTheme[];
this.configLoader = options.configLoader ?? defaultConfigLoader;
@@ -341,6 +345,12 @@ export class AppManager implements BackstageApp {
const featureFlagsApi = this.getApiHolder().get(featureFlagsApiRef)!;
if (featureFlagsApi) {
for (const flag of this.featureFlags) {
featureFlagsApi.registerFlag({
...flag,
pluginId: '',
});
}
for (const plugin of this.plugins.values()) {
if ('getFeatureFlags' in plugin) {
for (const flag of plugin.getFeatureFlags()) {
+6
View File
@@ -24,6 +24,7 @@ import {
SubRouteRef,
ExternalRouteRef,
IdentityApi,
FeatureFlag,
} from '@backstage/core-plugin-api';
import { AppConfig } from '@backstage/config';
@@ -213,6 +214,11 @@ export type AppOptions = {
}
>;
/**
* Application level feature flags.
*/
featureFlags?: (FeatureFlag & Omit<FeatureFlag, 'pluginId'>)[];
/**
* Supply components to the app to override the default ones.
*/
+1
View File
@@ -425,6 +425,7 @@ export type ExternalRouteRef<
export type FeatureFlag = {
name: string;
pluginId: string;
description?: string;
};
// @public
@@ -24,6 +24,7 @@ import { ApiRef, createApiRef } from '../system';
export type FeatureFlag = {
name: string;
pluginId: string;
description?: string;
};
/**