Commit ba225602 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/25973/mergeRequestSidebarLongPathTruncating' into 'master'

Fixed paths in MR sidebar truncating incorrectly

See merge request gitlab-org/gitlab!45994
parents ac0709f4 eb780234
...@@ -62,6 +62,7 @@ export default { ...@@ -62,6 +62,7 @@ export default {
v-bind="$attrs" v-bind="$attrs"
:class="{ 'is-active': isActive }" :class="{ 'is-active': isActive }"
class="diff-file-row" class="diff-file-row"
truncate-middle
:file-classes="fileClasses" :file-classes="fileClasses"
v-on="$listeners" v-on="$listeners"
> >
......
<script> <script>
import { GlTruncate } from '@gitlab/ui';
import FileHeader from '~/vue_shared/components/file_row_header.vue'; import FileHeader from '~/vue_shared/components/file_row_header.vue';
import FileIcon from '~/vue_shared/components/file_icon.vue'; import FileIcon from '~/vue_shared/components/file_icon.vue';
import { escapeFileUrl } from '~/lib/utils/url_utility'; import { escapeFileUrl } from '~/lib/utils/url_utility';
...@@ -8,6 +9,7 @@ export default { ...@@ -8,6 +9,7 @@ export default {
components: { components: {
FileHeader, FileHeader,
FileIcon, FileIcon,
GlTruncate,
}, },
props: { props: {
file: { file: {
...@@ -28,6 +30,11 @@ export default { ...@@ -28,6 +30,11 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
truncateMiddle: {
type: Boolean,
required: false,
default: false,
},
}, },
computed: { computed: {
isTree() { isTree() {
...@@ -134,9 +141,9 @@ export default { ...@@ -134,9 +141,9 @@ export default {
<span <span
ref="textOutput" ref="textOutput"
:style="levelIndentation" :style="levelIndentation"
class="file-row-name str-truncated" class="file-row-name"
data-qa-selector="file_name_content" data-qa-selector="file_name_content"
:class="fileClasses" :class="[fileClasses, { 'str-truncated': !truncateMiddle, 'gl-min-w-0': truncateMiddle }]"
> >
<file-icon <file-icon
class="file-row-icon" class="file-row-icon"
...@@ -147,7 +154,8 @@ export default { ...@@ -147,7 +154,8 @@ export default {
:opened="file.opened" :opened="file.opened"
:size="16" :size="16"
/> />
{{ file.name }} <gl-truncate v-if="truncateMiddle" :text="file.name" position="middle" class="gl-pr-7" />
<template v-else>{{ file.name }}</template>
</span> </span>
<slot></slot> <slot></slot>
</div> </div>
......
<script> <script>
import { truncatePathMiddleToLength } from '~/lib/utils/text_utility'; import { GlTruncate } from '@gitlab/ui';
const MAX_PATH_LENGTH = 40;
export default { export default {
components: {
GlTruncate,
},
props: { props: {
path: { path: {
type: String, type: String,
required: true, required: true,
}, },
}, },
computed: {
truncatedPath() {
return truncatePathMiddleToLength(this.path, MAX_PATH_LENGTH);
},
},
}; };
</script> </script>
<template> <template>
<div class="file-row-header bg-white sticky-top p-2 js-file-row-header" :title="path"> <div class="file-row-header bg-white sticky-top p-2 js-file-row-header" :title="path">
<span class="bold">{{ truncatedPath }}</span> <gl-truncate :text="path" position="middle" class="bold" />
</div> </div>
</template> </template>
---
title: Fixed long paths truncating in merge request sidebar incorrectly
merge_request: 45994
author:
type: fixed
...@@ -91,12 +91,12 @@ describe('Diffs tree list component', () => { ...@@ -91,12 +91,12 @@ describe('Diffs tree list component', () => {
expect( expect(
getFileRows() getFileRows()
.at(0) .at(0)
.text(), .html(),
).toContain('index.js'); ).toContain('index.js');
expect( expect(
getFileRows() getFileRows()
.at(1) .at(1)
.text(), .html(),
).toContain('app'); ).toContain('app');
}); });
...@@ -138,7 +138,7 @@ describe('Diffs tree list component', () => { ...@@ -138,7 +138,7 @@ describe('Diffs tree list component', () => {
wrapper.vm.$store.state.diffs.renderTreeList = false; wrapper.vm.$store.state.diffs.renderTreeList = false;
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find('.file-row').text()).toContain('index.js'); expect(wrapper.find('.file-row').html()).toContain('index.js');
}); });
}); });
}); });
......
...@@ -5,11 +5,11 @@ exports[`File row header component adds multiple ellipsises after 40 characters ...@@ -5,11 +5,11 @@ exports[`File row header component adds multiple ellipsises after 40 characters
class="file-row-header bg-white sticky-top p-2 js-file-row-header" class="file-row-header bg-white sticky-top p-2 js-file-row-header"
title="app/assets/javascripts/merge_requests/widget/diffs/notes" title="app/assets/javascripts/merge_requests/widget/diffs/notes"
> >
<span <gl-truncate-stub
class="bold" class="bold"
> position="middle"
app/assets/javascripts/…/…/diffs/notes text="app/assets/javascripts/merge_requests/widget/diffs/notes"
</span> />
</div> </div>
`; `;
...@@ -18,11 +18,11 @@ exports[`File row header component renders file path 1`] = ` ...@@ -18,11 +18,11 @@ exports[`File row header component renders file path 1`] = `
class="file-row-header bg-white sticky-top p-2 js-file-row-header" class="file-row-header bg-white sticky-top p-2 js-file-row-header"
title="app/assets" title="app/assets"
> >
<span <gl-truncate-stub
class="bold" class="bold"
> position="middle"
app/assets text="app/assets"
</span> />
</div> </div>
`; `;
...@@ -31,10 +31,10 @@ exports[`File row header component trucates path after 40 characters 1`] = ` ...@@ -31,10 +31,10 @@ exports[`File row header component trucates path after 40 characters 1`] = `
class="file-row-header bg-white sticky-top p-2 js-file-row-header" class="file-row-header bg-white sticky-top p-2 js-file-row-header"
title="app/assets/javascripts/merge_requests" title="app/assets/javascripts/merge_requests"
> >
<span <gl-truncate-stub
class="bold" class="bold"
> position="middle"
app/assets/javascripts/merge_requests text="app/assets/javascripts/merge_requests"
</span> />
</div> </div>
`; `;
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