From 40084e4a9ab45313b803e32e10e47d06ccdc0a24 Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Mon, 30 Nov 2020 08:12:15 -0600 Subject: [PATCH] Add query parameter to override Mirage scenario (#9380) --- ui/README.md | 2 ++ ui/mirage/scenarios/default.js | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ui/README.md b/ui/README.md index f1be90040..8960b099e 100644 --- a/ui/README.md +++ b/ui/README.md @@ -30,6 +30,8 @@ You may need to reference the direct path to `ember`, typically in `./node_modul The fake data in development is generated from a stable seed of 1. To generate different data, you can include a query parameter of `?faker-seed=2` or any other number in the URL. To turn off the seed and get different data with every load, use `?faker=seed=0`. +When running with Mirage, the default scenario is set in `config/environment.js` but can be overridden with a query parameter to any of the scenarios named in `mirage/scenarios/default.js` with something like `?mirage-scenario=emptyCluster`. + ## Running / Development with Vagrant All necessary tools for UI development are installed as part of the Vagrantfile. This is primarily to make it easy to build the UI from source while working on Nomad. Due to the filesystem requirements of [Broccoli](http://broccolijs.com/) (which powers Ember CLI), it is strongly discouraged to use Vagrant for developing changes to the UI. diff --git a/ui/mirage/scenarios/default.js b/ui/mirage/scenarios/default.js index da5a4148a..e6b5c1da2 100644 --- a/ui/mirage/scenarios/default.js +++ b/ui/mirage/scenarios/default.js @@ -18,7 +18,7 @@ const allScenarios = { ...topoScenarios, }; -const scenario = getConfigValue('mirageScenario', 'emptyCluster'); +const scenario = getScenarioQueryParameter() || getConfigValue('mirageScenario', 'emptyCluster'); export default function(server) { const activeScenario = allScenarios[scenario]; @@ -169,4 +169,9 @@ function getConfigValue(variableName, defaultValue) { ); return defaultValue; } + +function getScenarioQueryParameter() { + const params = new URLSearchParams(window.location.search); + return params.get('mirage-scenario'); +} /* eslint-enable */