mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
FeatureToggles: Support changing feature toggles with localstorage (#71567)
This commit is contained in:
parent
03c2efa2d6
commit
bc5bcd8b26
@ -199,6 +199,8 @@ export class GrafanaBootConfig implements GrafanaConfig {
|
||||
overrideFeatureTogglesFromUrl(this);
|
||||
}
|
||||
|
||||
overrideFeatureTogglesFromLocalStorage(this);
|
||||
|
||||
if (this.featureToggles.disableAngular) {
|
||||
this.angularSupportEnabled = false;
|
||||
}
|
||||
@ -210,6 +212,24 @@ export class GrafanaBootConfig implements GrafanaConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// localstorage key: grafana.featureToggles
|
||||
// example value: panelEditor=1,panelInspector=1
|
||||
function overrideFeatureTogglesFromLocalStorage(config: GrafanaBootConfig) {
|
||||
const featureToggles = config.featureToggles;
|
||||
const localStorageKey = 'grafana.featureToggles';
|
||||
const localStorageValue = window.localStorage.getItem(localStorageKey);
|
||||
if (localStorageValue) {
|
||||
const features = localStorageValue.split(',');
|
||||
for (const feature of features) {
|
||||
const [featureName, featureValue] = feature.split('=');
|
||||
const toggleState = featureValue === 'true' || featureValue === '1';
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
featureToggles[featureName as keyof FeatureToggles] = toggleState;
|
||||
console.log(`Setting feature toggle ${featureName} = ${toggleState} via localstorage`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function overrideFeatureTogglesFromUrl(config: GrafanaBootConfig) {
|
||||
if (window.location.href.indexOf('__feature') === -1) {
|
||||
return;
|
||||
@ -223,7 +243,7 @@ function overrideFeatureTogglesFromUrl(config: GrafanaBootConfig) {
|
||||
const toggleState = value === 'true' || value === ''; // browser rewrites true as ''
|
||||
if (toggleState !== featureToggles[key]) {
|
||||
featureToggles[featureName] = toggleState;
|
||||
console.log(`Setting feature toggle ${featureName} = ${toggleState}`);
|
||||
console.log(`Setting feature toggle ${featureName} = ${toggleState} via url`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user