Commit 450f6c19 authored by Ammar Alakkad's avatar Ammar Alakkad

Add icons to project's storage table

Changelog: other
parent 1972ec41
<script> <script>
import { GlLink, GlIcon, GlTable, GlSprintf } from '@gitlab/ui'; import { GlLink, GlIcon, GlTableLite as GlTable, GlSprintf } from '@gitlab/ui';
import { numberToHumanSize } from '~/lib/utils/number_utils'; import { numberToHumanSize } from '~/lib/utils/number_utils';
import { thWidthClass } from '~/lib/utils/table_utility'; import { thWidthClass } from '~/lib/utils/table_utility';
import { sprintf } from '~/locale'; import { sprintf } from '~/locale';
import { PROJECT_TABLE_LABELS, HELP_LINK_ARIA_LABEL } from '../constants'; import { PROJECT_TABLE_LABELS, HELP_LINK_ARIA_LABEL } from '../constants';
import StorageTypeIcon from './storage_type_icon.vue';
export default { export default {
name: 'StorageTable', name: 'StorageTable',
...@@ -12,6 +13,7 @@ export default { ...@@ -12,6 +13,7 @@ export default {
GlIcon, GlIcon,
GlTable, GlTable,
GlSprintf, GlSprintf,
StorageTypeIcon,
}, },
props: { props: {
storageTypes: { storageTypes: {
...@@ -48,31 +50,39 @@ export default { ...@@ -48,31 +50,39 @@ export default {
<template> <template>
<gl-table :items="storageTypes" :fields="$options.projectTableFields"> <gl-table :items="storageTypes" :fields="$options.projectTableFields">
<template #cell(storageType)="{ item }"> <template #cell(storageType)="{ item }">
<p class="gl-font-weight-bold gl-mb-0" :data-testid="`${item.storageType.id}-name`"> <div class="gl-display-flex gl-flex-direction-row">
{{ item.storageType.name }} <storage-type-icon
<gl-link :name="item.storageType.id"
v-if="item.storageType.helpPath" :data-testid="`${item.storageType.id}-icon`"
:href="item.storageType.helpPath" />
target="_blank" <div>
:aria-label="helpLinkAriaLabel(item.storageType.name)" <p class="gl-font-weight-bold gl-mb-0" :data-testid="`${item.storageType.id}-name`">
:data-testid="`${item.storageType.id}-help-link`" {{ item.storageType.name }}
> <gl-link
<gl-icon name="question" :size="12" /> v-if="item.storageType.helpPath"
</gl-link> :href="item.storageType.helpPath"
</p> target="_blank"
<p class="gl-mb-0" :data-testid="`${item.storageType.id}-description`"> :aria-label="helpLinkAriaLabel(item.storageType.name)"
{{ item.storageType.description }} :data-testid="`${item.storageType.id}-help-link`"
</p> >
<p v-if="item.storageType.warningMessage" class="gl-mb-0 gl-font-sm"> <gl-icon name="question" :size="12" />
<gl-icon name="warning" :size="12" /> </gl-link>
<gl-sprintf :message="item.storageType.warningMessage"> </p>
<template #warningLink="{ content }"> <p class="gl-mb-0" :data-testid="`${item.storageType.id}-description`">
<gl-link :href="item.storageType.warningLink" target="_blank" class="gl-font-sm">{{ {{ item.storageType.description }}
content </p>
}}</gl-link> <p v-if="item.storageType.warningMessage" class="gl-mb-0 gl-font-sm">
</template> <gl-icon name="warning" :size="12" />
</gl-sprintf> <gl-sprintf :message="item.storageType.warningMessage">
</p> <template #warningLink="{ content }">
<gl-link :href="item.storageType.warningLink" target="_blank" class="gl-font-sm">{{
content
}}</gl-link>
</template>
</gl-sprintf>
</p>
</div>
</div>
</template> </template>
</gl-table> </gl-table>
</template> </template>
<script>
import { GlIcon } from '@gitlab/ui';
export default {
components: { GlIcon },
props: {
name: {
type: String,
required: false,
default: '',
},
},
methods: {
iconName(storageTypeName) {
const defaultStorageTypeIcon = 'disk';
const storageTypeIconMap = {
lfsObjectsSize: 'doc-image',
snippetsSize: 'snippet',
uploadsSize: 'upload',
repositorySize: 'infrastructure-registry',
packagesSize: 'package',
};
return storageTypeIconMap[`${storageTypeName}`] ?? defaultStorageTypeIcon;
},
},
};
</script>
<template>
<span
class="gl-display-inline-flex gl-align-items-flex-start gl-justify-content-center gl-min-w-8 gl-pr-2 gl-pt-1"
>
<gl-icon :name="iconName(name)" :size="16" class="gl-mt-1" />
</span>
</template>
import { GlTable } from '@gitlab/ui'; import { GlTableLite } from '@gitlab/ui';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import StorageTable from '~/projects/storage_counter/components/storage_table.vue'; import StorageTable from '~/projects/storage_counter/components/storage_table.vue';
...@@ -22,7 +22,7 @@ describe('StorageTable', () => { ...@@ -22,7 +22,7 @@ describe('StorageTable', () => {
); );
}; };
const findTable = () => wrapper.findComponent(GlTable); const findTable = () => wrapper.findComponent(GlTableLite);
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
...@@ -37,6 +37,7 @@ describe('StorageTable', () => { ...@@ -37,6 +37,7 @@ describe('StorageTable', () => {
({ storageType: { id, name, description } }) => { ({ storageType: { id, name, description } }) => {
expect(wrapper.findByTestId(`${id}-name`).text()).toBe(name); expect(wrapper.findByTestId(`${id}-name`).text()).toBe(name);
expect(wrapper.findByTestId(`${id}-description`).text()).toBe(description); expect(wrapper.findByTestId(`${id}-description`).text()).toBe(description);
expect(wrapper.findByTestId(`${id}-icon`).props('name')).toBe(id);
expect(wrapper.findByTestId(`${id}-help-link`).attributes('href')).toBe( expect(wrapper.findByTestId(`${id}-help-link`).attributes('href')).toBe(
defaultProvideValues.helpLinks[id.replace(`Size`, `HelpPagePath`)] defaultProvideValues.helpLinks[id.replace(`Size`, `HelpPagePath`)]
.replace(`Size`, ``) .replace(`Size`, ``)
......
import { mount } from '@vue/test-utils';
import { GlIcon } from '@gitlab/ui';
import StorageTypeIcon from '~/projects/storage_counter/components/storage_type_icon.vue';
describe('StorageTypeIcon', () => {
let wrapper;
const createComponent = (props = {}) => {
wrapper = mount(StorageTypeIcon, {
propsData: {
...props,
},
});
};
const findGlIcon = () => wrapper.findComponent(GlIcon);
describe('rendering icon', () => {
afterEach(() => {
wrapper.destroy();
});
it.each`
expected | provided
${'doc-image'} | ${'lfsObjectsSize'}
${'snippet'} | ${'snippetsSize'}
${'infrastructure-registry'} | ${'repositorySize'}
${'package'} | ${'packagesSize'}
${'upload'} | ${'uploadsSize'}
${'disk'} | ${'wikiSize'}
${'disk'} | ${'anything-else'}
`(
'renders icon with name of $expected when name prop is $provided',
({ expected, provided }) => {
createComponent({ name: provided });
expect(findGlIcon().props('name')).toBe(expected);
},
);
});
});
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