diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-02-15 22:45:19 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-02-15 23:00:10 +0300 |
commit | 9414fc5c93d83a560da96b52ac062f8574726827 (patch) | |
tree | e4ea90482628f909279402be578489372ac2f8fc /app/assets/javascripts/environments/stores | |
parent | 1285d629064abce3aee8faafaa57492da6f8f163 (diff) |
Moves check for latest key to store instead of poluting the view making it reusable between endpoints.
Diffstat (limited to 'app/assets/javascripts/environments/stores')
-rw-r--r-- | app/assets/javascripts/environments/stores/environments_store.js.es6 | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/app/assets/javascripts/environments/stores/environments_store.js.es6 b/app/assets/javascripts/environments/stores/environments_store.js.es6 index 252e349962e..560d2702c6b 100644 --- a/app/assets/javascripts/environments/stores/environments_store.js.es6 +++ b/app/assets/javascripts/environments/stores/environments_store.js.es6 @@ -20,8 +20,12 @@ class EnvironmentsStore { * * Stores the received environments. * - * Each environment has the following schema + * In the main environments endpoint, each environment has the following schema * { name: String, size: Number, latest: Object } + * In the endpoint to retrieve environments from each folder, the environment does + * not have the `latest` key and the data is all in the root level. + * To avoid doing this check in the view, we store both cases the same by extracting + * what is inside the `latest` key. * * If the `size` is bigger than 1, it means it should be rendered as a folder. * In those cases we add `isFolder` key in order to render it properly. @@ -31,11 +35,20 @@ class EnvironmentsStore { */ storeEnvironments(environments = []) { const filteredEnvironments = environments.map((env) => { + let filtered = {}; + if (env.size > 1) { - return Object.assign({}, env, { isFolder: true }); + filtered = Object.assign({}, env, { isFolder: true }); + } + + if (env.latest) { + filtered = Object.assign(filtered, env, env.latest, { folderName: env.name }); + delete filtered.latest; + } else { + filtered = Object.assign(filtered, env); } - return env; + return filtered; }); this.state.environments = filteredEnvironments; |