Commit 9414fc5c authored by Filipa Lacerda's avatar Filipa Lacerda

Moves check for latest key to store instead of poluting the view making it...

Moves check for latest key to store instead of poluting the view making it reusable between endpoints.
parent 1285d629
...@@ -72,9 +72,9 @@ module.exports = Vue.component('environment-item', { ...@@ -72,9 +72,9 @@ module.exports = Vue.component('environment-item', {
* @returns {Boolean} * @returns {Boolean}
*/ */
hasLastDeploymentKey() { hasLastDeploymentKey() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
!this.$options.isObjectEmpty(this.model.latest.last_deployment)) { !this.$options.isObjectEmpty(this.model.last_deployment)) {
return true; return true;
} }
return false; return false;
...@@ -87,10 +87,10 @@ module.exports = Vue.component('environment-item', { ...@@ -87,10 +87,10 @@ module.exports = Vue.component('environment-item', {
* @returns {Boolean|Undefined} * @returns {Boolean|Undefined}
*/ */
hasManualActions() { hasManualActions() {
return this.model.latest && return this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.manual_actions && this.model.last_deployment.manual_actions &&
this.model.latest.last_deployment.manual_actions.length > 0; this.model.last_deployment.manual_actions.length > 0;
}, },
/** /**
...@@ -99,7 +99,7 @@ module.exports = Vue.component('environment-item', { ...@@ -99,7 +99,7 @@ module.exports = Vue.component('environment-item', {
* @returns {Boolean} * @returns {Boolean}
*/ */
hasStopAction() { hasStopAction() {
return this.model.latest && this.model.latest['stop_action?']; return this.model && this.model['stop_action?'];
}, },
/** /**
...@@ -109,10 +109,10 @@ module.exports = Vue.component('environment-item', { ...@@ -109,10 +109,10 @@ module.exports = Vue.component('environment-item', {
* @returns {Boolean|Undefined} * @returns {Boolean|Undefined}
*/ */
canRetry() { canRetry() {
return this.model.latest && return this.model &&
this.hasLastDeploymentKey && this.hasLastDeploymentKey &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.deployable; this.model.last_deployment.deployable;
}, },
/** /**
...@@ -121,10 +121,10 @@ module.exports = Vue.component('environment-item', { ...@@ -121,10 +121,10 @@ module.exports = Vue.component('environment-item', {
* @returns {Boolean|Undefined} * @returns {Boolean|Undefined}
*/ */
canShowDate() { canShowDate() {
return this.model.latest && return this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.deployable && this.model.last_deployment.deployable &&
this.model.latest.last_deployment.deployable !== undefined; this.model.last_deployment.deployable !== undefined;
}, },
/** /**
...@@ -133,11 +133,11 @@ module.exports = Vue.component('environment-item', { ...@@ -133,11 +133,11 @@ module.exports = Vue.component('environment-item', {
* @returns {String} * @returns {String}
*/ */
createdDate() { createdDate() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.deployable && this.model.last_deployment.deployable &&
this.model.latest.last_deployment.deployable.created_at) { this.model.last_deployment.deployable.created_at) {
return timeagoInstance.format(this.model.latest.last_deployment.deployable.created_at); return timeagoInstance.format(this.model.last_deployment.deployable.created_at);
} }
return ''; return '';
}, },
...@@ -149,7 +149,7 @@ module.exports = Vue.component('environment-item', { ...@@ -149,7 +149,7 @@ module.exports = Vue.component('environment-item', {
*/ */
manualActions() { manualActions() {
if (this.hasManualActions) { if (this.hasManualActions) {
return this.model.latest.last_deployment.manual_actions.map((action) => { return this.model.last_deployment.manual_actions.map((action) => {
const parsedAction = { const parsedAction = {
name: gl.text.humanize(action.name), name: gl.text.humanize(action.name),
play_path: action.play_path, play_path: action.play_path,
...@@ -166,11 +166,11 @@ module.exports = Vue.component('environment-item', { ...@@ -166,11 +166,11 @@ module.exports = Vue.component('environment-item', {
* @returns {String} * @returns {String}
*/ */
userImageAltDescription() { userImageAltDescription() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.user && this.model.last_deployment.user &&
this.model.latest.last_deployment.user.username) { this.model.last_deployment.user.username) {
return `${this.model.latest.last_deployment.user.username}'s avatar'`; return `${this.model.last_deployment.user.username}'s avatar'`;
} }
return ''; return '';
}, },
...@@ -181,10 +181,10 @@ module.exports = Vue.component('environment-item', { ...@@ -181,10 +181,10 @@ module.exports = Vue.component('environment-item', {
* @returns {String|Undefined} * @returns {String|Undefined}
*/ */
commitTag() { commitTag() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.tag) { this.model.last_deployment.tag) {
return this.model.latest.last_deployment.tag; return this.model.last_deployment.tag;
} }
return undefined; return undefined;
}, },
...@@ -195,10 +195,10 @@ module.exports = Vue.component('environment-item', { ...@@ -195,10 +195,10 @@ module.exports = Vue.component('environment-item', {
* @returns {Object|Undefined} * @returns {Object|Undefined}
*/ */
commitRef() { commitRef() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.ref) { this.model.last_deployment.ref) {
return this.model.latest.last_deployment.ref; return this.model.last_deployment.ref;
} }
return undefined; return undefined;
}, },
...@@ -209,11 +209,11 @@ module.exports = Vue.component('environment-item', { ...@@ -209,11 +209,11 @@ module.exports = Vue.component('environment-item', {
* @returns {String|Undefined} * @returns {String|Undefined}
*/ */
commitUrl() { commitUrl() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.commit && this.model.last_deployment.commit &&
this.model.latest.last_deployment.commit.commit_path) { this.model.last_deployment.commit.commit_path) {
return this.model.latest.last_deployment.commit.commit_path; return this.model.last_deployment.commit.commit_path;
} }
return undefined; return undefined;
}, },
...@@ -224,11 +224,11 @@ module.exports = Vue.component('environment-item', { ...@@ -224,11 +224,11 @@ module.exports = Vue.component('environment-item', {
* @returns {String|Undefined} * @returns {String|Undefined}
*/ */
commitShortSha() { commitShortSha() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.commit && this.model.last_deployment.commit &&
this.model.latest.last_deployment.commit.short_id) { this.model.last_deployment.commit.short_id) {
return this.model.latest.last_deployment.commit.short_id; return this.model.last_deployment.commit.short_id;
} }
return undefined; return undefined;
}, },
...@@ -239,11 +239,11 @@ module.exports = Vue.component('environment-item', { ...@@ -239,11 +239,11 @@ module.exports = Vue.component('environment-item', {
* @returns {String|Undefined} * @returns {String|Undefined}
*/ */
commitTitle() { commitTitle() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.commit && this.model.last_deployment.commit &&
this.model.latest.last_deployment.commit.title) { this.model.last_deployment.commit.title) {
return this.model.latest.last_deployment.commit.title; return this.model.last_deployment.commit.title;
} }
return undefined; return undefined;
}, },
...@@ -254,11 +254,11 @@ module.exports = Vue.component('environment-item', { ...@@ -254,11 +254,11 @@ module.exports = Vue.component('environment-item', {
* @returns {Object|Undefined} * @returns {Object|Undefined}
*/ */
commitAuthor() { commitAuthor() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.commit && this.model.last_deployment.commit &&
this.model.latest.last_deployment.commit.author) { this.model.last_deployment.commit.author) {
return this.model.latest.last_deployment.commit.author; return this.model.last_deployment.commit.author;
} }
return undefined; return undefined;
...@@ -270,11 +270,11 @@ module.exports = Vue.component('environment-item', { ...@@ -270,11 +270,11 @@ module.exports = Vue.component('environment-item', {
* @returns {String|Undefined} * @returns {String|Undefined}
*/ */
retryUrl() { retryUrl() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.deployable && this.model.last_deployment.deployable &&
this.model.latest.last_deployment.deployable.retry_path) { this.model.last_deployment.deployable.retry_path) {
return this.model.latest.last_deployment.deployable.retry_path; return this.model.last_deployment.deployable.retry_path;
} }
return undefined; return undefined;
}, },
...@@ -285,8 +285,8 @@ module.exports = Vue.component('environment-item', { ...@@ -285,8 +285,8 @@ module.exports = Vue.component('environment-item', {
* @returns {Boolean|Undefined} * @returns {Boolean|Undefined}
*/ */
isLastDeployment() { isLastDeployment() {
return this.model.latest && this.model.latest.last_deployment && return this.model && this.model.last_deployment &&
this.model.latest.last_deployment['last?']; this.model.last_deployment['last?'];
}, },
/** /**
...@@ -295,10 +295,10 @@ module.exports = Vue.component('environment-item', { ...@@ -295,10 +295,10 @@ module.exports = Vue.component('environment-item', {
* @returns {String} * @returns {String}
*/ */
buildName() { buildName() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.deployable) { this.model.last_deployment.deployable) {
return `${this.model.latest.last_deployment.deployable.name} #${this.model.latest.last_deployment.deployable.id}`; return `${this.model.last_deployment.deployable.name} #${this.model.last_deployment.deployable.id}`;
} }
return ''; return '';
}, },
...@@ -309,10 +309,10 @@ module.exports = Vue.component('environment-item', { ...@@ -309,10 +309,10 @@ module.exports = Vue.component('environment-item', {
* @returns {String} * @returns {String}
*/ */
deploymentInternalId() { deploymentInternalId() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.iid) { this.model.last_deployment.iid) {
return `#${this.model.latest.last_deployment.iid}`; return `#${this.model.last_deployment.iid}`;
} }
return ''; return '';
}, },
...@@ -323,9 +323,9 @@ module.exports = Vue.component('environment-item', { ...@@ -323,9 +323,9 @@ module.exports = Vue.component('environment-item', {
* @returns {Boolean} * @returns {Boolean}
*/ */
deploymentHasUser() { deploymentHasUser() {
return this.model.latest && return this.model &&
!this.$options.isObjectEmpty(this.model.latest.last_deployment) && !this.$options.isObjectEmpty(this.model.last_deployment) &&
!this.$options.isObjectEmpty(this.model.latest.last_deployment.user); !this.$options.isObjectEmpty(this.model.last_deployment.user);
}, },
/** /**
...@@ -335,10 +335,10 @@ module.exports = Vue.component('environment-item', { ...@@ -335,10 +335,10 @@ module.exports = Vue.component('environment-item', {
* @returns {Object} * @returns {Object}
*/ */
deploymentUser() { deploymentUser() {
if (this.model.latest && if (this.model &&
!this.$options.isObjectEmpty(this.model.latest.last_deployment) && !this.$options.isObjectEmpty(this.model.last_deployment) &&
!this.$options.isObjectEmpty(this.model.latest.last_deployment.user)) { !this.$options.isObjectEmpty(this.model.last_deployment.user)) {
return this.model.latest.last_deployment.user; return this.model.last_deployment.user;
} }
return {}; return {};
}, },
...@@ -352,9 +352,8 @@ module.exports = Vue.component('environment-item', { ...@@ -352,9 +352,8 @@ module.exports = Vue.component('environment-item', {
*/ */
shouldRenderBuildName() { shouldRenderBuildName() {
return !this.model.isFolder && return !this.model.isFolder &&
this.model.latest && !this.$options.isObjectEmpty(this.model.last_deployment) &&
!this.$options.isObjectEmpty(this.model.latest.last_deployment) && !this.$options.isObjectEmpty(this.model.last_deployment.deployable);
!this.$options.isObjectEmpty(this.model.latest.last_deployment.deployable);
}, },
/** /**
...@@ -363,11 +362,11 @@ module.exports = Vue.component('environment-item', { ...@@ -363,11 +362,11 @@ module.exports = Vue.component('environment-item', {
* @return {String} * @return {String}
*/ */
buildPath() { buildPath() {
if (this.model.latest && if (this.model &&
this.model.latest.last_deployment && this.model.last_deployment &&
this.model.latest.last_deployment.deployable && this.model.last_deployment.deployable &&
this.model.latest.last_deployment.deployable.build_path) { this.model.last_deployment.deployable.build_path) {
return this.model.latest.last_deployment.deployable.build_path; return this.model.last_deployment.deployable.build_path;
} }
return ''; return '';
...@@ -379,8 +378,8 @@ module.exports = Vue.component('environment-item', { ...@@ -379,8 +378,8 @@ module.exports = Vue.component('environment-item', {
* @return {String} * @return {String}
*/ */
externalURL() { externalURL() {
if (this.model.latest && this.model.latest.external_url) { if (this.model && this.model.external_url) {
return this.model.latest.external_url; return this.model.external_url;
} }
return ''; return '';
...@@ -395,14 +394,13 @@ module.exports = Vue.component('environment-item', { ...@@ -395,14 +394,13 @@ module.exports = Vue.component('environment-item', {
*/ */
shouldRenderDeploymentID() { shouldRenderDeploymentID() {
return !this.model.isFolder && return !this.model.isFolder &&
this.model.latest && !this.$options.isObjectEmpty(this.model.last_deployment) &&
!this.$options.isObjectEmpty(this.model.latest.last_deployment) && this.model.last_deployment.iid !== undefined;
this.model.latest.last_deployment.iid !== undefined;
}, },
environmentPath() { environmentPath() {
if (this.model && this.model.latest && this.model.latest.environment_path) { if (this.model && this.model.environment_path) {
return this.model.latest.environment_path; return this.model.environment_path;
} }
return ''; return '';
...@@ -414,7 +412,7 @@ module.exports = Vue.component('environment-item', { ...@@ -414,7 +412,7 @@ module.exports = Vue.component('environment-item', {
* @return {String} * @return {String}
*/ */
folderUrl() { folderUrl() {
return `${window.location.pathname}/folders/${this.model.name}`; return `${window.location.pathname}/folders/${this.model.folderName}`;
}, },
}, },
...@@ -449,7 +447,7 @@ module.exports = Vue.component('environment-item', { ...@@ -449,7 +447,7 @@ module.exports = Vue.component('environment-item', {
</span> </span>
<span> <span>
{{model.name}} {{model.folderName}}
</span> </span>
<span class="badge"> <span class="badge">
...@@ -523,18 +521,18 @@ module.exports = Vue.component('environment-item', { ...@@ -523,18 +521,18 @@ module.exports = Vue.component('environment-item', {
</external-url-component> </external-url-component>
</div> </div>
<div v-if="hasStopAction && canCreateDeployment && model.latest" <div v-if="hasStopAction && canCreateDeployment"
class="inline js-stop-component-container"> class="inline js-stop-component-container">
<stop-component <stop-component
:stop-url="model.latest.stop_path"> :stop-url="model.stop_path">
</stop-component> </stop-component>
</div> </div>
<div v-if="model.latest && model.latest.terminal_path" <div v-if="model && model.terminal_path"
class="inline js-terminal-button-container"> class="inline js-terminal-button-container">
<terminal-button-component <terminal-button-component
:terminal-icon-svg="terminalIconSvg" :terminal-icon-svg="terminalIconSvg"
:terminal-path="model.latest.terminal_path"> :terminal-path="model.terminal_path">
</terminal-button-component> </terminal-button-component>
</div> </div>
......
...@@ -20,8 +20,12 @@ class EnvironmentsStore { ...@@ -20,8 +20,12 @@ class EnvironmentsStore {
* *
* Stores the received environments. * 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 } * { 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. * 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. * In those cases we add `isFolder` key in order to render it properly.
...@@ -31,11 +35,20 @@ class EnvironmentsStore { ...@@ -31,11 +35,20 @@ class EnvironmentsStore {
*/ */
storeEnvironments(environments = []) { storeEnvironments(environments = []) {
const filteredEnvironments = environments.map((env) => { const filteredEnvironments = environments.map((env) => {
let filtered = {};
if (env.size > 1) { 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; this.state.environments = filteredEnvironments;
......
...@@ -118,6 +118,7 @@ ...@@ -118,6 +118,7 @@
.folder-icon { .folder-icon {
margin-right: 3px; margin-right: 3px;
color: $gl-text-color-secondary; color: $gl-text-color-secondary;
display: inline-block;
.fa:nth-child(1) { .fa:nth-child(1) {
margin-right: 3px; margin-right: 3px;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment