FeatureToggles: Support changing feature toggles with URL parameters (#50275)

This commit is contained in:
Ryan McKinley
2022-06-09 11:42:38 +02:00
committed by GitHub
parent 8318876b34
commit fdf67276ea
2 changed files with 21 additions and 3 deletions
+20
View File
@@ -153,9 +153,29 @@ export class GrafanaBootConfig implements GrafanaConfig {
if (this.dateFormats) {
systemDateFormats.update(this.dateFormats);
}
overrideFeatureTogglesFromUrl(this);
}
}
function overrideFeatureTogglesFromUrl(config: GrafanaBootConfig) {
if (window.location.href.indexOf('__feature') === -1) {
return;
}
const params = new URLSearchParams(window.location.search);
params.forEach((value, key) => {
if (key.startsWith('__feature.')) {
const featureName = key.substring(10);
const toggleState = value === 'true';
if (toggleState !== config.featureToggles[key]) {
config.featureToggles[featureName] = toggleState;
console.log(`Setting feature toggle ${featureName} = ${toggleState}`);
}
}
});
}
const bootData = (window as any).grafanaBootData || {
settings: {},
user: {},