Commit 99ae878f authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/treeFileIcons' into 'master'

Use file icons for repository tree rows

Closes #33806

See merge request gitlab-org/gitlab!28112
parents 32eb78d7 72aa735c
<script> <script>
import { escapeRegExp } from 'lodash'; import { escapeRegExp } from 'lodash';
import { GlBadge, GlLink, GlSkeletonLoading, GlTooltipDirective, GlLoadingIcon } from '@gitlab/ui'; import {
GlBadge,
GlLink,
GlSkeletonLoading,
GlTooltipDirective,
GlLoadingIcon,
GlIcon,
} from '@gitlab/ui';
import { escapeFileUrl } from '~/lib/utils/url_utility'; import { escapeFileUrl } from '~/lib/utils/url_utility';
import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import Icon from '~/vue_shared/components/icon.vue'; import FileIcon from '~/vue_shared/components/file_icon.vue';
import { getIconName } from '../../utils/icon';
import getRefMixin from '../../mixins/get_ref'; import getRefMixin from '../../mixins/get_ref';
import getCommit from '../../queries/getCommit.query.graphql'; import getCommit from '../../queries/getCommit.query.graphql';
...@@ -14,8 +20,9 @@ export default { ...@@ -14,8 +20,9 @@ export default {
GlLink, GlLink,
GlSkeletonLoading, GlSkeletonLoading,
GlLoadingIcon, GlLoadingIcon,
GlIcon,
TimeagoTooltip, TimeagoTooltip,
Icon, FileIcon,
}, },
directives: { directives: {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
...@@ -95,9 +102,6 @@ export default { ...@@ -95,9 +102,6 @@ export default {
? { path: `/-/tree/${escape(this.ref)}/${escapeFileUrl(this.path)}` } ? { path: `/-/tree/${escape(this.ref)}/${escapeFileUrl(this.path)}` }
: null; : null;
}, },
iconName() {
return `fa-${getIconName(this.type, this.path)}`;
},
isFolder() { isFolder() {
return this.type === 'tree'; return this.type === 'tree';
}, },
...@@ -123,12 +127,6 @@ export default { ...@@ -123,12 +127,6 @@ export default {
<template> <template>
<tr class="tree-item"> <tr class="tree-item">
<td class="tree-item-file-name cursor-default position-relative"> <td class="tree-item-file-name cursor-default position-relative">
<gl-loading-icon
v-if="path === loadingPath"
size="sm"
inline
class="d-inline-block align-text-bottom fa-fw"
/>
<component <component
:is="linkComponent" :is="linkComponent"
ref="link" ref="link"
...@@ -140,27 +138,27 @@ export default { ...@@ -140,27 +138,27 @@ export default {
class="tree-item-link str-truncated" class="tree-item-link str-truncated"
data-qa-selector="file_name_link" data-qa-selector="file_name_link"
> >
<i <file-icon
v-if="path !== loadingPath" :file-name="fullPath"
:aria-label="type" :folder="isFolder"
role="img" :submodule="isSubmodule"
:class="iconName" :loading="path === loadingPath"
class="fa fa-fw mr-1" css-classes="position-relative file-icon"
></i class="mr-1 position-relative text-secondary"
><span class="position-relative">{{ fullPath }}</span> /><span class="position-relative">{{ fullPath }}</span>
</component> </component>
<!-- eslint-disable-next-line @gitlab/vue-require-i18n-strings --> <!-- eslint-disable-next-line @gitlab/vue-require-i18n-strings -->
<gl-badge v-if="lfsOid" variant="default" class="label-lfs ml-1">LFS</gl-badge> <gl-badge v-if="lfsOid" variant="default" class="label-lfs ml-1">LFS</gl-badge>
<template v-if="isSubmodule"> <template v-if="isSubmodule">
@ <gl-link :href="submoduleTreeUrl" class="commit-sha">{{ shortSha }}</gl-link> @ <gl-link :href="submoduleTreeUrl" class="commit-sha">{{ shortSha }}</gl-link>
</template> </template>
<icon <gl-icon
v-if="hasLockLabel" v-if="hasLockLabel"
v-gl-tooltip v-gl-tooltip
:title="commit.lockLabel" :title="commit.lockLabel"
name="lock" name="lock"
:size="12" :size="12"
class="ml-2 vertical-align-middle" class="ml-1"
/> />
</td> </td>
<td class="d-none d-sm-table-cell tree-commit cursor-default"> <td class="d-none d-sm-table-cell tree-commit cursor-default">
......
<script> <script>
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
import getIconForFile from './file_icon/file_icon_map'; import getIconForFile from './file_icon/file_icon_map';
import icon from '../../vue_shared/components/icon.vue';
/* This is a re-usable vue component for rendering a svg sprite /* This is a re-usable vue component for rendering a svg sprite
icon icon
...@@ -17,8 +16,8 @@ import icon from '../../vue_shared/components/icon.vue'; ...@@ -17,8 +16,8 @@ import icon from '../../vue_shared/components/icon.vue';
*/ */
export default { export default {
components: { components: {
icon,
GlLoadingIcon, GlLoadingIcon,
GlIcon,
}, },
props: { props: {
fileName: { fileName: {
...@@ -31,7 +30,11 @@ export default { ...@@ -31,7 +30,11 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
submodule: {
type: Boolean,
required: false,
default: false,
},
opened: { opened: {
type: Boolean, type: Boolean,
required: false, required: false,
...@@ -58,7 +61,7 @@ export default { ...@@ -58,7 +61,7 @@ export default {
}, },
computed: { computed: {
spriteHref() { spriteHref() {
const iconName = getIconForFile(this.fileName) || 'file'; const iconName = this.submodule ? 'folder-git' : getIconForFile(this.fileName) || 'file';
return `${gon.sprite_file_icons}#${iconName}`; return `${gon.sprite_file_icons}#${iconName}`;
}, },
folderIconName() { folderIconName() {
...@@ -73,9 +76,12 @@ export default { ...@@ -73,9 +76,12 @@ export default {
<template> <template>
<span> <span>
<svg v-if="!loading && !folder" :class="[iconSizeClass, cssClasses]"> <svg v-if="!loading && !folder" :class="[iconSizeClass, cssClasses]">
<use v-bind="{ 'xlink:href': spriteHref }" /> <use v-bind="{ 'xlink:href': spriteHref }" /></svg
</svg> ><gl-icon
<icon v-if="!loading && folder" :name="folderIconName" :size="size" class="folder-icon" /> v-if="!loading && folder"
<gl-loading-icon v-if="loading" :inline="true" /> :name="folderIconName"
:size="size"
class="folder-icon"
/><gl-loading-icon v-if="loading" :inline="true" />
</span> </span>
</template> </template>
...@@ -138,6 +138,12 @@ ...@@ -138,6 +138,12 @@
} }
.tree-item { .tree-item {
.file-icon,
.folder-icon {
position: relative;
top: 2px;
}
.link-container { .link-container {
padding: 0; padding: 0;
......
---
title: Use rich icons for thw rows on the file tree
merge_request: 28112
author:
type: changed
...@@ -7,17 +7,16 @@ exports[`Repository table row component renders table row 1`] = ` ...@@ -7,17 +7,16 @@ exports[`Repository table row component renders table row 1`] = `
<td <td
class="tree-item-file-name cursor-default position-relative" class="tree-item-file-name cursor-default position-relative"
> >
<!---->
<a <a
class="tree-item-link str-truncated" class="tree-item-link str-truncated"
data-qa-selector="file_name_link" data-qa-selector="file_name_link"
href="https://test.com" href="https://test.com"
> >
<i <file-icon-stub
aria-label="file" class="mr-1 position-relative text-secondary"
class="fa fa-fw mr-1 fa-file-text-o" cssclasses="position-relative file-icon"
role="img" filename="test"
size="16"
/> />
<span <span
class="position-relative" class="position-relative"
...@@ -60,17 +59,16 @@ exports[`Repository table row component renders table row for path with special ...@@ -60,17 +59,16 @@ exports[`Repository table row component renders table row for path with special
<td <td
class="tree-item-file-name cursor-default position-relative" class="tree-item-file-name cursor-default position-relative"
> >
<!---->
<a <a
class="tree-item-link str-truncated" class="tree-item-link str-truncated"
data-qa-selector="file_name_link" data-qa-selector="file_name_link"
href="https://test.com" href="https://test.com"
> >
<i <file-icon-stub
aria-label="file" class="mr-1 position-relative text-secondary"
class="fa fa-fw mr-1 fa-file-text-o" cssclasses="position-relative file-icon"
role="img" filename="test"
size="16"
/> />
<span <span
class="position-relative" class="position-relative"
......
import { shallowMount, RouterLinkStub } from '@vue/test-utils'; import { shallowMount, RouterLinkStub } from '@vue/test-utils';
import { GlBadge, GlLink, GlLoadingIcon } from '@gitlab/ui'; import { GlBadge, GlLink, GlIcon } from '@gitlab/ui';
import TableRow from '~/repository/components/table/row.vue'; import TableRow from '~/repository/components/table/row.vue';
import Icon from '~/vue_shared/components/icon.vue'; import FileIcon from '~/vue_shared/components/file_icon.vue';
let vm; let vm;
let $router; let $router;
...@@ -188,7 +188,8 @@ describe('Repository table row component', () => { ...@@ -188,7 +188,8 @@ describe('Repository table row component', () => {
vm.setData({ commit: { lockLabel: 'Locked by Root', committedDate: '2019-01-01' } }); vm.setData({ commit: { lockLabel: 'Locked by Root', committedDate: '2019-01-01' } });
return vm.vm.$nextTick().then(() => { return vm.vm.$nextTick().then(() => {
expect(vm.find(Icon).exists()).toBe(true); expect(vm.find(GlIcon).exists()).toBe(true);
expect(vm.find(GlIcon).props('name')).toBe('lock');
}); });
}); });
...@@ -202,6 +203,6 @@ describe('Repository table row component', () => { ...@@ -202,6 +203,6 @@ describe('Repository table row component', () => {
loadingPath: 'test', loadingPath: 'test',
}); });
expect(vm.find(GlLoadingIcon).exists()).toBe(true); expect(vm.find(FileIcon).props('loading')).toBe(true);
}); });
}); });
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
import FileIcon from '~/vue_shared/components/file_icon.vue'; import FileIcon from '~/vue_shared/components/file_icon.vue';
import Icon from '~/vue_shared/components/icon.vue';
describe('File Icon component', () => { describe('File Icon component', () => {
let wrapper; let wrapper;
...@@ -48,7 +47,7 @@ describe('File Icon component', () => { ...@@ -48,7 +47,7 @@ describe('File Icon component', () => {
}); });
expect(findIcon().exists()).toBe(false); expect(findIcon().exists()).toBe(false);
expect(wrapper.find(Icon).classes()).toContain('folder-icon'); expect(wrapper.find(GlIcon).classes()).toContain('folder-icon');
}); });
it('should render a loading icon', () => { it('should render a loading icon', () => {
......
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