FeatureToggles: typed as optional booleans (#43925)

This commit is contained in:
Ryan McKinley
2022-01-11 16:18:54 -08:00
committed by GitHub
parent 59bda131ec
commit 7e5e3f9dc0
7 changed files with 47 additions and 39 deletions

View File

@ -4,6 +4,7 @@ import { GrafanaTheme } from './theme';
import { SystemDateFormatSettings } from '../datetime';
import { GrafanaTheme2 } from '../themes';
import { MapLayerOptions } from '../geo/layer';
import { FeatureToggles } from './featureToggles.gen';
/**
* Describes the build information that will be available via the Grafana configuration.
@ -29,28 +30,6 @@ export enum GrafanaEdition {
Enterprise = 'Enterprise',
}
/**
* Describes available feature toggles in Grafana. These can be configured via the
* `conf/custom.ini` to enable features under development or not yet available in
* stable version.
*
* @public
*/
export interface FeatureToggles {
[name: string]: boolean;
trimDefaults: boolean;
accesscontrol: boolean;
tempoServiceGraph: boolean;
tempoSearch: boolean;
tempoBackendSearch: boolean;
recordedQueries: boolean;
newNavigation: boolean;
fullRangeLogsVolume: boolean;
queryOverLive: boolean;
dashboardPreviews: boolean;
}
/**
* Describes the license information about the current running instance of Grafana.
*

View File

@ -0,0 +1,39 @@
/**
* Describes available feature toggles in Grafana. These can be configured via
* conf/custom.ini to enable features under development or not yet available in
* stable version.
*
* Only enabled values will be returned in this interface
*
* @public
*/
export interface FeatureToggles {
[name: string]: boolean | undefined; // support any string value
recordedQueries?: boolean;
teamsync?: boolean;
ldapsync?: boolean;
caching?: boolean;
dspermissions?: boolean;
analytics?: boolean;
['enterprise.plugins']?: boolean;
trimDefaults?: boolean;
envelopeEncryption?: boolean;
httpclientprovider_azure_auth?: boolean;
['service-accounts']?: boolean;
database_metrics?: boolean;
dashboardPreviews?: boolean;
['live-config']?: boolean;
['live-pipeline']?: boolean;
['live-service-web-worker']?: boolean;
queryOverLive?: boolean;
tempoSearch?: boolean;
tempoBackendSearch?: boolean;
tempoServiceGraph?: boolean;
fullRangeLogsVolume?: boolean;
accesscontrol?: boolean;
prometheus_azure_auth?: boolean;
newNavigation?: boolean;
showFeatureFlagsInUI?: boolean;
disable_http_request_histogram?: boolean;
}

View File

@ -36,7 +36,8 @@ export * from './live';
export * from './variables';
export * from './geometry';
export { isUnsignedPluginSignature } from './pluginSignature';
export { GrafanaConfig, BuildInfo, FeatureToggles, LicenseInfo, PreloadPlugin } from './config';
export { GrafanaConfig, BuildInfo, LicenseInfo, PreloadPlugin } from './config';
export { FeatureToggles } from './featureToggles.gen';
export * from './alerts';
export * from './slider';
export * from './accesscontrol';

View File

@ -61,18 +61,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
theme: GrafanaTheme;
theme2: GrafanaTheme2;
pluginsToPreload: PreloadPlugin[] = [];
featureToggles: FeatureToggles = {
accesscontrol: false,
trimDefaults: false,
tempoServiceGraph: false,
tempoSearch: false,
tempoBackendSearch: false,
recordedQueries: false,
newNavigation: false,
fullRangeLogsVolume: false,
queryOverLive: false,
dashboardPreviews: false,
};
featureToggles: FeatureToggles = {};
licenseInfo: LicenseInfo = {} as LicenseInfo;
rendererAvailable = false;
rendererVersion = '';

View File

@ -92,7 +92,7 @@ export class AppWrapper extends React.Component<AppWrapperProps, AppWrapperState
render() {
navigationLogger('AppWrapper', false, 'rendering');
const newNavigationEnabled = config.featureToggles.newNavigation;
const newNavigationEnabled = Boolean(config.featureToggles.newNavigation);
return (
<Provider store={store}>

View File

@ -2,7 +2,7 @@ import React, { ReactNode } from 'react';
import { css, cx } from '@emotion/css';
import { GrafanaTheme2 } from '@grafana/data';
import { useTheme2 } from '@grafana/ui';
import config from '../../config';
import { config } from '@grafana/runtime';
export interface Props {
children: ReactNode;
@ -10,7 +10,7 @@ export interface Props {
}
export function NavBarSection({ children, className }: Props) {
const newNavigationEnabled = config.featureToggles.newNavigation;
const newNavigationEnabled = Boolean(config.featureToggles.newNavigation);
const theme = useTheme2();
const styles = getStyles(theme, newNavigationEnabled);

View File

@ -83,7 +83,7 @@ export class ContextSrv {
}
accessControlEnabled(): boolean {
return featureEnabled('accesscontrol') && config.featureToggles['accesscontrol'];
return featureEnabled('accesscontrol') && Boolean(config.featureToggles['accesscontrol']);
}
// Checks whether user has required permission