Commit 0d16e67e authored by pburdette's avatar pburdette

Simplify several computed props

Utilize the JS syntax to simplify
computed props. And edit another component
instead of editing the data.
parent 5dabb296
...@@ -12,11 +12,6 @@ import PipelineUrl from './pipeline_url.vue'; ...@@ -12,11 +12,6 @@ import PipelineUrl from './pipeline_url.vue';
import PipelineTriggerer from './pipeline_triggerer.vue'; import PipelineTriggerer from './pipeline_triggerer.vue';
import PipelinesTimeago from './time_ago.vue'; import PipelinesTimeago from './time_ago.vue';
/**
* Pipeline table row.
*
* Given the received object renders a table row in the pipelines' table.
*/
export default { export default {
i18n: { i18n: {
cancelTitle: __('Cancel'), cancelTitle: __('Cancel'),
...@@ -127,116 +122,30 @@ export default { ...@@ -127,116 +122,30 @@ export default {
return commitAuthorInformation; return commitAuthorInformation;
}, },
/**
* If provided, returns the commit tag.
* Needed to render the commit component column.
*
* @returns {String|Undefined}
*/
commitTag() { commitTag() {
if (this.pipeline.ref && this.pipeline.ref.tag) { return this.pipeline?.ref?.tag;
return this.pipeline.ref.tag;
}
return undefined;
}, },
/**
* If provided, returns the commit ref.
* Needed to render the commit component column.
*
* Matches `path` prop sent in the API to `ref_url` prop needed
* in the commit component.
*
* @returns {Object|Undefined}
*/
commitRef() { commitRef() {
if (this.pipeline.ref) { return this.pipeline?.ref;
return Object.keys(this.pipeline.ref).reduce((accumulator, prop) => {
if (prop === 'path') {
accumulator.ref_url = this.pipeline.ref[prop];
} else {
accumulator[prop] = this.pipeline.ref[prop];
}
return accumulator;
}, {});
}
return undefined;
}, },
/**
* If provided, returns the commit url.
* Needed to render the commit component column.
*
* @returns {String|Undefined}
*/
commitUrl() { commitUrl() {
if (this.pipeline.commit && this.pipeline.commit.commit_path) { return this.pipeline?.commit?.commit_path;
return this.pipeline.commit.commit_path;
}
return undefined;
}, },
/**
* If provided, returns the commit short sha.
* Needed to render the commit component column.
*
* @returns {String|Undefined}
*/
commitShortSha() { commitShortSha() {
if (this.pipeline.commit && this.pipeline.commit.short_id) { return this.pipeline?.commit?.short_id;
return this.pipeline.commit.short_id;
}
return undefined;
}, },
/**
* If provided, returns the commit title.
* Needed to render the commit component column.
*
* @returns {String|Undefined}
*/
commitTitle() { commitTitle() {
if (this.pipeline.commit && this.pipeline.commit.title) { return this.pipeline?.commit?.title;
return this.pipeline.commit.title;
}
return undefined;
}, },
/**
* Timeago components expects a number
*
* @return {type} description
*/
pipelineDuration() { pipelineDuration() {
if (this.pipeline.details && this.pipeline.details.duration) { return this.pipeline?.details?.duration ?? 0;
return this.pipeline.details.duration;
}
return 0;
}, },
/**
* Timeago component expects a String.
*
* @return {String}
*/
pipelineFinishedAt() { pipelineFinishedAt() {
if (this.pipeline.details && this.pipeline.details.finished_at) { return this.pipeline?.details?.finished_at ?? '';
return this.pipeline.details.finished_at;
}
return '';
}, },
pipelineStatus() { pipelineStatus() {
if (this.pipeline.details && this.pipeline.details.status) { return this.pipeline?.details?.status ?? {};
return this.pipeline.details.status;
}
return {};
}, },
displayPipelineActions() { displayPipelineActions() {
return ( return (
this.pipeline.flags.retryable || this.pipeline.flags.retryable ||
...@@ -245,11 +154,9 @@ export default { ...@@ -245,11 +154,9 @@ export default {
this.pipeline.details.artifacts.length this.pipeline.details.artifacts.length
); );
}, },
isChildView() { isChildView() {
return this.viewType === 'child'; return this.viewType === 'child';
}, },
isCancelling() { isCancelling() {
return this.cancelingPipeline === this.pipeline.id; return this.cancelingPipeline === this.pipeline.id;
}, },
......
...@@ -133,6 +133,9 @@ export default { ...@@ -133,6 +133,9 @@ export default {
? sprintf(__("%{username}'s avatar"), { username: this.author.username }) ? sprintf(__("%{username}'s avatar"), { username: this.author.username })
: null; : null;
}, },
refUrl() {
return this.commitRef.ref_url ?? this.commitRef.path;
},
}, },
}; };
</script> </script>
...@@ -153,14 +156,9 @@ export default { ...@@ -153,14 +156,9 @@ export default {
class="ref-name" class="ref-name"
>{{ mergeRequestRef.iid }}</gl-link >{{ mergeRequestRef.iid }}</gl-link
> >
<gl-link <gl-link v-else v-gl-tooltip :href="refUrl" :title="commitRef.name" class="ref-name">{{
v-else commitRef.name
v-gl-tooltip }}</gl-link>
:href="commitRef.ref_url"
:title="commitRef.name"
class="ref-name"
>{{ commitRef.name }}</gl-link
>
</template> </template>
<gl-icon name="commit" class="commit-icon js-commit-icon" /> <gl-icon name="commit" class="commit-icon js-commit-icon" />
......
...@@ -223,4 +223,20 @@ describe('Commit component', () => { ...@@ -223,4 +223,20 @@ describe('Commit component', () => {
expect(wrapper.find('.ref-name').exists()).toBe(false); expect(wrapper.find('.ref-name').exists()).toBe(false);
}); });
}); });
describe('When commitRef has a path property instead of ref_url property', () => {
it('should render path as href attribute', () => {
props = {
commitRef: {
name: 'master',
path: 'http://localhost/namespace2/gitlabhq/tree/master',
},
};
createComponent(props);
expect(wrapper.find('.ref-name').exists()).toBe(true);
expect(wrapper.find('.ref-name').attributes('href')).toBe(props.commitRef.path);
});
});
}); });
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