summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/environments/stores
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-02-15 19:45:19 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-02-15 20:00:10 +0000
commit9414fc5c93d83a560da96b52ac062f8574726827 (patch)
treee4ea90482628f909279402be578489372ac2f8fc /app/assets/javascripts/environments/stores
parent1285d629064abce3aee8faafaa57492da6f8f163 (diff)
downloadgitlab-ce-9414fc5c93d83a560da96b52ac062f8574726827.tar.gz
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.es619
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;