Commit 3b29870e authored by Samantha Ming's avatar Samantha Ming

Add tooltip to file tree

- Move ide tooltip message to ide specific component
- Add tooltip message to passed down to changed_file_icon component
- Create tooltip message for filetree
parent 04852a58
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import FileRow from '~/vue_shared/components/file_row.vue'; import FileRow from '~/vue_shared/components/file_row.vue';
import FileRowStats from './file_row_stats.vue'; import FileRowStats from './file_row_stats.vue';
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue'; import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
import { __ } from '~/locale';
export default { export default {
name: 'DiffFileRow', name: 'DiffFileRow',
...@@ -28,6 +29,19 @@ export default { ...@@ -28,6 +29,19 @@ export default {
showFileRowStats() { showFileRowStats() {
return !this.hideFileStats && this.file.type === 'blob'; return !this.hideFileStats && this.file.type === 'blob';
}, },
tooltipTitle() {
if (!this.file.changed) return undefined;
if (this.file.deleted) {
return __('Deleted');
}
if (this.file.tempFile) {
return __('Added');
}
return __('Modified');
},
}, },
}; };
</script> </script>
...@@ -35,6 +49,6 @@ export default { ...@@ -35,6 +49,6 @@ export default {
<template> <template>
<file-row :file="file" v-bind="$attrs" v-on="$listeners"> <file-row :file="file" v-bind="$attrs" v-on="$listeners">
<file-row-stats v-if="showFileRowStats" :file="file" class="mr-1" /> <file-row-stats v-if="showFileRowStats" :file="file" class="mr-1" />
<changed-file-icon :file="file" :size="16" /> <changed-file-icon :file="file" :size="16" :show-tooltip="true" :tooltip-title="tooltipTitle" />
</file-row> </file-row>
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { n__ } from '~/locale'; import { n__, __ } from '~/locale';
import tooltip from '~/vue_shared/directives/tooltip'; import tooltip from '~/vue_shared/directives/tooltip';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue'; import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
...@@ -60,6 +60,11 @@ export default { ...@@ -60,6 +60,11 @@ export default {
showChangedFileIcon() { showChangedFileIcon() {
return !this.isTree && this.isModified; return !this.isTree && this.isModified;
}, },
tooltipTitle() {
if (!this.file.changed) return undefined;
return this.file.tempFile ? __('Added') : __('Modified');
},
}, },
}; };
</script> </script>
...@@ -84,6 +89,7 @@ export default { ...@@ -84,6 +89,7 @@ export default {
:file="file" :file="file"
:show-tooltip="true" :show-tooltip="true"
:show-staged-icon="false" :show-staged-icon="false"
:tooltip-title="tooltipTitle"
/> />
<new-dropdown <new-dropdown
:type="file.type" :type="file.type"
......
<script> <script>
import { GlTooltipDirective } from '@gitlab/ui'; import { GlTooltipDirective } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import { __ } from '~/locale';
import { getCommitIconMap } from '~/ide/utils'; import { getCommitIconMap } from '~/ide/utils';
export default { export default {
...@@ -36,6 +35,11 @@ export default { ...@@ -36,6 +35,11 @@ export default {
required: false, required: false,
default: true, default: true,
}, },
tooltipTitle: {
type: String,
required: false,
default: null,
},
}, },
computed: { computed: {
changedIcon() { changedIcon() {
...@@ -48,10 +52,10 @@ export default { ...@@ -48,10 +52,10 @@ export default {
changedIconClass() { changedIconClass() {
return `${this.changedIcon} float-left d-block`; return `${this.changedIcon} float-left d-block`;
}, },
tooltipTitle() { changedTooltipTitle() {
if (!this.showTooltip || !this.file.changed) return undefined; if (!this.showTooltip) return undefined;
return this.file.tempFile ? __('Added') : __('Modified'); return this.tooltipTitle;
}, },
showIcon() { showIcon() {
return ( return (
...@@ -69,7 +73,7 @@ export default { ...@@ -69,7 +73,7 @@ export default {
<template> <template>
<span <span
v-gl-tooltip.right v-gl-tooltip.right
:title="tooltipTitle" :title="changedTooltipTitle"
:class="{ 'ml-auto': isCentered }" :class="{ 'ml-auto': isCentered }"
class="file-changed-icon d-inline-block" class="file-changed-icon d-inline-block"
> >
......
---
title: Add tooltip to modification icon in the file tree
merge_request: 27158
author:
type: other
...@@ -39,21 +39,56 @@ describe('Diff File Row component', () => { ...@@ -39,21 +39,56 @@ describe('Diff File Row component', () => {
); );
}); });
it('renders ChangedFileIcon component', () => { describe('ChangedFileIcon component', () => {
createComponent({ const fileObject = (file = {}) => {
return {
changed: true,
...file,
};
};
const componentProps = file => {
return {
level: 4, level: 4,
file: {}, file,
hideFileStats: false, hideFileStats: false,
}); };
};
it('renders component with showTooltip', () => {
const file = fileObject();
createComponent(componentProps(file));
expect(wrapper.find(ChangedFileIcon).props()).toEqual( expect(wrapper.find(ChangedFileIcon).props()).toEqual(
expect.objectContaining({ expect.objectContaining({
file: {}, file,
size: 16, size: 16,
showTooltip: true,
}), }),
); );
}); });
it.each`
message | file | desc
${'Deleted'} | ${'deleted'} | ${'shows "Deleted" tooltip if file has been deleted'}
${'Added'} | ${'tempFile'} | ${'shows "Added" tooltip if file has been added'}
`('$desc', ({ message, file }) => {
createComponent(
componentProps(
fileObject({
[file]: true,
}),
),
);
expect(wrapper.find(ChangedFileIcon).props('tooltipTitle')).toBe(message);
});
it('shows "Modified" tooltip if file has been modified', () => {
const file = fileObject({ deleted: false, tempFile: false });
createComponent(componentProps(file));
expect(wrapper.find(ChangedFileIcon).props('tooltipTitle')).toBe('Modified');
});
});
describe('FileRowStats components', () => { describe('FileRowStats components', () => {
it.each` it.each`
type | hideFileStats | value | desc type | hideFileStats | value | desc
......
...@@ -60,7 +60,7 @@ describe('Changed file icon', () => { ...@@ -60,7 +60,7 @@ describe('Changed file icon', () => {
${newFile()} | ${'file-addition'} | ${'Added'} | ${'with file new'} ${newFile()} | ${'file-addition'} | ${'Added'} | ${'with file new'}
`('$desc', ({ file, iconName, tooltipText }) => { `('$desc', ({ file, iconName, tooltipText }) => {
beforeEach(() => { beforeEach(() => {
factory({ file }); factory({ file, tooltipTitle: tooltipText });
}); });
it('renders icon', () => { it('renders icon', () => {
......
...@@ -150,6 +150,27 @@ describe('IDE extra file row component', () => { ...@@ -150,6 +150,27 @@ describe('IDE extra file row component', () => {
done(); done();
}); });
}); });
it('shows "Added" tooltip if file has been added', done => {
vm.file.changed = true;
vm.file.tempFile = true;
vm.$nextTick(() => {
expect(vm.$el.querySelector('.file-changed-icon').getAttribute('title')).toBe('Added');
done();
});
});
it('shows "Modified" tooltip if file has been modified', done => {
vm.file.changed = true;
vm.$nextTick(() => {
expect(vm.$el.querySelector('.file-changed-icon').getAttribute('title')).toBe('Modified');
done();
});
});
}); });
describe('merge request icon', () => { describe('merge request 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