Commit d68b2f2c authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by Brandon Labuschagne

Add commit column to package files table

- source
- tests
parent e0dcb376
<script> <script>
import { GlLink, GlTable } from '@gitlab/ui'; import { GlLink, GlTable } from '@gitlab/ui';
import { last } from 'lodash';
import { __ } from '~/locale'; import { __ } from '~/locale';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import { numberToHumanSize } from '~/lib/utils/number_utils'; import { numberToHumanSize } from '~/lib/utils/number_utils';
...@@ -27,30 +28,41 @@ export default { ...@@ -27,30 +28,41 @@ export default {
return this.packageFiles.map(pf => ({ return this.packageFiles.map(pf => ({
...pf, ...pf,
size: this.formatSize(pf.size), size: this.formatSize(pf.size),
pipeline: last(pf.pipelines),
})); }));
}, },
showCommitColumn() {
return this.filesTableRows.some(row => Boolean(row.pipeline?.id));
},
filesTableHeaderFields() {
return [
{
key: 'name',
label: __('Name'),
tdClass: 'gl-display-flex gl-align-items-center',
},
{
key: 'commit',
label: __('Commit'),
hide: !this.showCommitColumn,
},
{
key: 'size',
label: __('Size'),
},
{
key: 'created',
label: __('Created'),
class: 'gl-text-right',
},
].filter(c => !c.hide);
},
}, },
methods: { methods: {
formatSize(size) { formatSize(size) {
return numberToHumanSize(size); return numberToHumanSize(size);
}, },
}, },
filesTableHeaderFields: [
{
key: 'name',
label: __('Name'),
tdClass: 'gl-display-flex gl-align-items-center',
},
{
key: 'size',
label: __('Size'),
},
{
key: 'created',
label: __('Created'),
class: 'gl-text-right',
},
],
}; };
</script> </script>
...@@ -58,14 +70,14 @@ export default { ...@@ -58,14 +70,14 @@ export default {
<div> <div>
<h3 class="gl-font-lg gl-mt-5">{{ __('Files') }}</h3> <h3 class="gl-font-lg gl-mt-5">{{ __('Files') }}</h3>
<gl-table <gl-table
:fields="$options.filesTableHeaderFields" :fields="filesTableHeaderFields"
:items="filesTableRows" :items="filesTableRows"
:tbody-tr-attr="{ 'data-testid': 'file-row' }" :tbody-tr-attr="{ 'data-testid': 'file-row' }"
> >
<template #cell(name)="{ item }"> <template #cell(name)="{ item }">
<gl-link <gl-link
:href="item.download_path" :href="item.download_path"
class="gl-relative" class="gl-relative gl-text-gray-500"
data-testid="download-link" data-testid="download-link"
@click="$emit('download-file')" @click="$emit('download-file')"
> >
...@@ -78,6 +90,15 @@ export default { ...@@ -78,6 +90,15 @@ export default {
</gl-link> </gl-link>
</template> </template>
<template #cell(commit)="{item}">
<gl-link
:href="item.pipeline.project.commit_url"
class="gl-text-gray-500"
data-testid="commit-link"
>{{ item.pipeline.git_commit_message }}</gl-link
>
</template>
<template #cell(created)="{ item }"> <template #cell(created)="{ item }">
<time-ago-tooltip :time="item.created_at" /> <time-ago-tooltip :time="item.created_at" />
</template> </template>
......
---
title: Update package_file table to display commits when present
merge_request: 48882
author:
type: changed
...@@ -12,6 +12,7 @@ describe('Package Files', () => { ...@@ -12,6 +12,7 @@ describe('Package Files', () => {
const findAllRows = () => wrapper.findAll('[data-testid="file-row"'); const findAllRows = () => wrapper.findAll('[data-testid="file-row"');
const findFirstRow = () => findAllRows().at(0); const findFirstRow = () => findAllRows().at(0);
const findFirstRowDownloadLink = () => findFirstRow().find('[data-testid="download-link"'); const findFirstRowDownloadLink = () => findFirstRow().find('[data-testid="download-link"');
const findFirstRowCommitLink = () => findFirstRow().find('[data-testid="commit-link"');
const findFirstRowFileIcon = () => findFirstRow().find(FileIcon); const findFirstRowFileIcon = () => findFirstRow().find(FileIcon);
const findFirstRowCreatedAt = () => findFirstRow().find(TimeAgoTooltip); const findFirstRowCreatedAt = () => findFirstRow().find(TimeAgoTooltip);
...@@ -96,4 +97,35 @@ describe('Package Files', () => { ...@@ -96,4 +97,35 @@ describe('Package Files', () => {
expect(findFirstRowCreatedAt().props('time')).toBe(npmFiles[0].created_at); expect(findFirstRowCreatedAt().props('time')).toBe(npmFiles[0].created_at);
}); });
}); });
describe('commit', () => {
describe('when package file has a pipeline associated', () => {
it('exists', () => {
createComponent();
expect(findFirstRowCommitLink().exists()).toBe(true);
});
it('the link points to the commit url', () => {
createComponent();
expect(findFirstRowCommitLink().attributes('href')).toBe(
npmFiles[0].pipelines[0].project.commit_url,
);
});
it('the text is git_commit_message', () => {
createComponent();
expect(findFirstRowCommitLink().text()).toBe(npmFiles[0].pipelines[0].git_commit_message);
});
});
describe('when package file has no pipeline associated', () => {
it('does not exist', () => {
createComponent(mavenFiles);
expect(findFirstRowCommitLink().exists()).toBe(false);
});
});
});
}); });
...@@ -76,6 +76,9 @@ export const npmFiles = [ ...@@ -76,6 +76,9 @@ export const npmFiles = [
id: 2, id: 2,
size: 200, size: 200,
download_path: '/-/package_files/2/download', download_path: '/-/package_files/2/download',
pipelines: [
{ id: 1, project: { commit_url: 'http://foo.bar' }, git_commit_message: 'foo bar baz?' },
],
}, },
]; ];
......
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