2018-06-21 12:22:40 +00:00
|
|
|
<script>
|
2020-04-21 18:09:31 +00:00
|
|
|
import { escape } from 'lodash';
|
2018-07-09 17:13:41 +00:00
|
|
|
import { mapActions, mapGetters } from 'vuex';
|
2020-04-03 09:09:31 +00:00
|
|
|
import { GlDeprecatedButton, GlTooltipDirective, GlLoadingIcon } from '@gitlab/ui';
|
2019-12-10 07:53:40 +00:00
|
|
|
import { polyfillSticky } from '~/lib/utils/sticky';
|
2018-06-21 12:22:40 +00:00
|
|
|
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
|
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
2018-07-05 12:02:56 +00:00
|
|
|
import FileIcon from '~/vue_shared/components/file_icon.vue';
|
2018-06-21 12:22:40 +00:00
|
|
|
import { truncateSha } from '~/lib/utils/text_utility';
|
|
|
|
import { __, s__, sprintf } from '~/locale';
|
2019-02-15 17:56:50 +00:00
|
|
|
import { diffViewerModes } from '~/ide/constants';
|
2018-06-21 12:22:40 +00:00
|
|
|
import EditButton from './edit_button.vue';
|
2019-01-30 03:21:26 +00:00
|
|
|
import DiffStats from './diff_stats.vue';
|
2019-12-10 07:53:40 +00:00
|
|
|
import { scrollToElement } from '~/lib/utils/common_utils';
|
2018-06-21 12:22:40 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2019-02-28 14:14:15 +00:00
|
|
|
GlLoadingIcon,
|
2020-04-03 09:09:31 +00:00
|
|
|
GlDeprecatedButton,
|
2018-06-21 12:22:40 +00:00
|
|
|
ClipboardButton,
|
|
|
|
EditButton,
|
|
|
|
Icon,
|
2018-07-05 12:02:56 +00:00
|
|
|
FileIcon,
|
2019-01-30 03:21:26 +00:00
|
|
|
DiffStats,
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
directives: {
|
2018-11-05 13:12:40 +00:00
|
|
|
GlTooltip: GlTooltipDirective,
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
props: {
|
2018-10-11 22:32:28 +00:00
|
|
|
discussionPath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2018-06-21 12:22:40 +00:00
|
|
|
diffFile: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
collapsible: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
addMergeRequestButtons: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
expanded: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
|
|
|
},
|
2018-07-17 15:47:02 +00:00
|
|
|
canCurrentUserFork: {
|
|
|
|
type: Boolean,
|
2018-06-21 12:22:40 +00:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
2018-07-17 11:54:33 +00:00
|
|
|
...mapGetters('diffs', ['diffHasExpandedDiscussions', 'diffHasDiscussions']),
|
2019-03-25 15:13:22 +00:00
|
|
|
diffContentIDSelector() {
|
|
|
|
return `#diff-content-${this.diffFile.file_hash}`;
|
|
|
|
},
|
2018-06-21 12:22:40 +00:00
|
|
|
|
|
|
|
titleLink() {
|
|
|
|
if (this.diffFile.submodule) {
|
2018-11-09 19:48:41 +00:00
|
|
|
return this.diffFile.submodule_tree_url || this.diffFile.submodule_link;
|
2018-06-21 12:22:40 +00:00
|
|
|
}
|
2019-03-25 15:13:22 +00:00
|
|
|
|
|
|
|
if (!this.discussionPath) {
|
|
|
|
return this.diffContentIDSelector;
|
|
|
|
}
|
|
|
|
|
2018-10-11 22:32:28 +00:00
|
|
|
return this.discussionPath;
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
filePath() {
|
|
|
|
if (this.diffFile.submodule) {
|
2018-11-09 19:48:41 +00:00
|
|
|
return `${this.diffFile.file_path} @ ${truncateSha(this.diffFile.blob.id)}`;
|
2018-06-21 12:22:40 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 19:48:41 +00:00
|
|
|
if (this.diffFile.deleted_file) {
|
|
|
|
return sprintf(__('%{filePath} deleted'), { filePath: this.diffFile.file_path }, false);
|
2018-06-21 12:22:40 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 19:48:41 +00:00
|
|
|
return this.diffFile.file_path;
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
isUsingLfs() {
|
2018-11-09 19:48:41 +00:00
|
|
|
return this.diffFile.stored_externally && this.diffFile.external_storage === 'lfs';
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
collapseIcon() {
|
|
|
|
return this.expanded ? 'chevron-down' : 'chevron-right';
|
|
|
|
},
|
|
|
|
viewFileButtonText() {
|
2020-04-21 18:09:31 +00:00
|
|
|
const truncatedContentSha = escape(truncateSha(this.diffFile.content_sha));
|
2018-06-21 12:22:40 +00:00
|
|
|
return sprintf(
|
|
|
|
s__('MergeRequests|View file @ %{commitId}'),
|
2019-04-15 22:28:20 +00:00
|
|
|
{ commitId: truncatedContentSha },
|
2018-06-21 12:22:40 +00:00
|
|
|
false,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
viewReplacedFileButtonText() {
|
2020-04-21 18:09:31 +00:00
|
|
|
const truncatedBaseSha = escape(truncateSha(this.diffFile.diff_refs.base_sha));
|
2018-06-21 12:22:40 +00:00
|
|
|
return sprintf(
|
|
|
|
s__('MergeRequests|View replaced file @ %{commitId}'),
|
|
|
|
{
|
|
|
|
commitId: `<span class="commit-sha">${truncatedBaseSha}</span>`,
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
},
|
2018-07-30 13:37:28 +00:00
|
|
|
gfmCopyText() {
|
2018-11-09 19:48:41 +00:00
|
|
|
return `\`${this.diffFile.file_path}\``;
|
2018-07-30 13:37:28 +00:00
|
|
|
},
|
2019-02-15 17:56:50 +00:00
|
|
|
isFileRenamed() {
|
2019-08-21 08:23:22 +00:00
|
|
|
return this.diffFile.renamed_file;
|
2019-02-15 17:56:50 +00:00
|
|
|
},
|
|
|
|
isModeChanged() {
|
|
|
|
return this.diffFile.viewer.name === diffViewerModes.mode_changed;
|
|
|
|
},
|
2019-03-28 21:37:06 +00:00
|
|
|
expandDiffToFullFileTitle() {
|
|
|
|
if (this.diffFile.isShowingFullFile) {
|
|
|
|
return s__('MRDiff|Show changes only');
|
|
|
|
}
|
|
|
|
return s__('MRDiff|Show full file');
|
|
|
|
},
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
2018-11-20 18:47:59 +00:00
|
|
|
mounted() {
|
|
|
|
polyfillSticky(this.$refs.header);
|
|
|
|
},
|
2018-06-21 12:22:40 +00:00
|
|
|
methods: {
|
2019-07-03 08:26:57 +00:00
|
|
|
...mapActions('diffs', [
|
|
|
|
'toggleFileDiscussions',
|
|
|
|
'toggleFileDiscussionWrappers',
|
|
|
|
'toggleFullDiff',
|
|
|
|
]),
|
2019-09-12 05:04:22 +00:00
|
|
|
handleToggleFile() {
|
|
|
|
this.$emit('toggleFile');
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
showForkMessage() {
|
|
|
|
this.$emit('showForkMessage');
|
|
|
|
},
|
2019-03-25 15:13:22 +00:00
|
|
|
handleFileNameClick(e) {
|
|
|
|
const isLinkToOtherPage =
|
|
|
|
this.diffFile.submodule_tree_url || this.diffFile.submodule_link || this.discussionPath;
|
|
|
|
|
|
|
|
if (!isLinkToOtherPage) {
|
|
|
|
e.preventDefault();
|
|
|
|
const selector = this.diffContentIDSelector;
|
|
|
|
scrollToElement(document.querySelector(selector));
|
|
|
|
window.location.hash = selector;
|
|
|
|
}
|
|
|
|
},
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
ref="header"
|
|
|
|
class="js-file-title file-title file-title-flex-parent"
|
2019-09-12 05:04:22 +00:00
|
|
|
@click.self="handleToggleFile"
|
2018-06-21 12:22:40 +00:00
|
|
|
>
|
|
|
|
<div class="file-header-content">
|
|
|
|
<icon
|
|
|
|
v-if="collapsible"
|
2019-09-12 05:04:22 +00:00
|
|
|
ref="collapseIcon"
|
2018-06-21 12:22:40 +00:00
|
|
|
:name="collapseIcon"
|
|
|
|
:size="16"
|
|
|
|
aria-hidden="true"
|
2018-07-05 12:02:56 +00:00
|
|
|
class="diff-toggle-caret append-right-5"
|
2019-09-12 05:04:22 +00:00
|
|
|
@click.stop="handleToggleFile"
|
2018-06-21 12:22:40 +00:00
|
|
|
/>
|
2019-03-25 15:13:22 +00:00
|
|
|
<a
|
|
|
|
v-once
|
|
|
|
ref="titleWrapper"
|
2019-09-12 05:04:22 +00:00
|
|
|
class="append-right-4"
|
2019-03-25 15:13:22 +00:00
|
|
|
:href="titleLink"
|
|
|
|
@click="handleFileNameClick"
|
|
|
|
>
|
2018-07-05 12:02:56 +00:00
|
|
|
<file-icon
|
|
|
|
:file-name="filePath"
|
|
|
|
:size="18"
|
2018-06-21 12:22:40 +00:00
|
|
|
aria-hidden="true"
|
2019-09-12 05:04:22 +00:00
|
|
|
css-classes="append-right-5"
|
2018-07-05 12:02:56 +00:00
|
|
|
/>
|
2019-02-15 17:56:50 +00:00
|
|
|
<span v-if="isFileRenamed">
|
2018-06-21 12:22:40 +00:00
|
|
|
<strong
|
2018-11-05 13:12:40 +00:00
|
|
|
v-gl-tooltip
|
2018-11-09 19:48:41 +00:00
|
|
|
:title="diffFile.old_path"
|
2018-06-21 12:22:40 +00:00
|
|
|
class="file-title-name"
|
2018-11-09 19:48:41 +00:00
|
|
|
v-html="diffFile.old_path_html"
|
2018-10-03 18:14:39 +00:00
|
|
|
></strong>
|
2018-06-21 12:22:40 +00:00
|
|
|
→
|
|
|
|
<strong
|
2018-11-05 13:12:40 +00:00
|
|
|
v-gl-tooltip
|
2018-11-09 19:48:41 +00:00
|
|
|
:title="diffFile.new_path"
|
2018-06-21 12:22:40 +00:00
|
|
|
class="file-title-name"
|
2018-11-09 19:48:41 +00:00
|
|
|
v-html="diffFile.new_path_html"
|
2018-10-03 18:14:39 +00:00
|
|
|
></strong>
|
2018-06-21 12:22:40 +00:00
|
|
|
</span>
|
|
|
|
|
2018-11-05 13:12:40 +00:00
|
|
|
<strong v-else v-gl-tooltip :title="filePath" class="file-title-name" data-container="body">
|
2018-06-21 12:22:40 +00:00
|
|
|
{{ filePath }}
|
|
|
|
</strong>
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<clipboard-button
|
2019-10-09 12:06:13 +00:00
|
|
|
:title="__('Copy file path')"
|
2018-11-09 19:48:41 +00:00
|
|
|
:text="diffFile.file_path"
|
2018-07-30 13:37:28 +00:00
|
|
|
:gfm="gfmCopyText"
|
2018-06-21 12:22:40 +00:00
|
|
|
css-class="btn-default btn-transparent btn-clipboard"
|
2020-01-23 09:09:07 +00:00
|
|
|
data-track-event="click_copy_file_button"
|
|
|
|
data-track-label="diff_copy_file_path_button"
|
|
|
|
data-track-property="diff_copy_file"
|
2018-06-21 12:22:40 +00:00
|
|
|
/>
|
|
|
|
|
2019-05-30 12:54:12 +00:00
|
|
|
<small v-if="isModeChanged" ref="fileMode" class="mr-1">
|
2018-11-09 19:48:41 +00:00
|
|
|
{{ diffFile.a_mode }} → {{ diffFile.b_mode }}
|
2018-06-21 12:22:40 +00:00
|
|
|
</small>
|
|
|
|
|
2018-11-16 20:07:38 +00:00
|
|
|
<span v-if="isUsingLfs" class="label label-lfs append-right-5"> {{ __('LFS') }} </span>
|
2018-06-21 12:22:40 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div
|
|
|
|
v-if="!diffFile.submodule && addMergeRequestButtons"
|
2020-02-05 09:08:43 +00:00
|
|
|
class="file-actions d-none d-sm-flex align-items-center flex-wrap"
|
2018-06-21 12:22:40 +00:00
|
|
|
>
|
2019-01-30 03:21:26 +00:00
|
|
|
<diff-stats :added-lines="diffFile.added_lines" :removed-lines="diffFile.removed_lines" />
|
2019-03-28 21:37:06 +00:00
|
|
|
<div class="btn-group" role="group">
|
|
|
|
<template v-if="diffFile.blob && diffFile.blob.readable_text">
|
2019-06-01 02:12:45 +00:00
|
|
|
<span v-gl-tooltip.hover :title="s__('MergeRequests|Toggle comments for this file')">
|
2020-04-03 09:09:31 +00:00
|
|
|
<gl-deprecated-button
|
2019-09-12 05:04:22 +00:00
|
|
|
ref="toggleDiscussionsButton"
|
2019-06-01 02:12:45 +00:00
|
|
|
:disabled="!diffHasDiscussions(diffFile)"
|
2019-09-12 05:04:22 +00:00
|
|
|
:class="{ active: diffHasExpandedDiscussions(diffFile) }"
|
2019-06-01 02:12:45 +00:00
|
|
|
class="js-btn-vue-toggle-comments btn"
|
2019-07-27 04:23:34 +00:00
|
|
|
data-qa-selector="toggle_comments_button"
|
2020-01-23 09:09:07 +00:00
|
|
|
data-track-event="click_toggle_comments_button"
|
|
|
|
data-track-label="diff_toggle_comments_button"
|
|
|
|
data-track-property="diff_toggle_comments"
|
2019-06-01 02:12:45 +00:00
|
|
|
type="button"
|
2019-09-12 05:04:22 +00:00
|
|
|
@click="toggleFileDiscussionWrappers(diffFile)"
|
2019-06-01 02:12:45 +00:00
|
|
|
>
|
|
|
|
<icon name="comment" />
|
2020-04-03 09:09:31 +00:00
|
|
|
</gl-deprecated-button>
|
2019-06-01 02:12:45 +00:00
|
|
|
</span>
|
2018-06-21 12:22:40 +00:00
|
|
|
|
2019-03-28 21:37:06 +00:00
|
|
|
<edit-button
|
|
|
|
v-if="!diffFile.deleted_file"
|
|
|
|
:can-current-user-fork="canCurrentUserFork"
|
|
|
|
:edit-path="diffFile.edit_path"
|
|
|
|
:can-modify-blob="diffFile.can_modify_blob"
|
2020-01-23 09:09:07 +00:00
|
|
|
data-track-event="click_toggle_edit_button"
|
|
|
|
data-track-label="diff_toggle_edit_button"
|
|
|
|
data-track-property="diff_toggle_edit"
|
2019-03-28 21:37:06 +00:00
|
|
|
@showForkMessage="showForkMessage"
|
|
|
|
/>
|
2019-02-28 14:14:15 +00:00
|
|
|
</template>
|
2018-06-21 12:22:40 +00:00
|
|
|
|
2019-03-28 21:37:06 +00:00
|
|
|
<a
|
|
|
|
v-if="diffFile.replaced_view_path"
|
2019-09-12 05:04:22 +00:00
|
|
|
ref="replacedFileButton"
|
2019-03-28 21:37:06 +00:00
|
|
|
:href="diffFile.replaced_view_path"
|
2019-09-12 05:04:22 +00:00
|
|
|
class="btn view-file"
|
2019-03-28 21:37:06 +00:00
|
|
|
v-html="viewReplacedFileButtonText"
|
|
|
|
>
|
|
|
|
</a>
|
2020-04-03 09:09:31 +00:00
|
|
|
<gl-deprecated-button
|
2019-03-28 21:37:06 +00:00
|
|
|
v-if="!diffFile.is_fully_expanded"
|
|
|
|
ref="expandDiffToFullFileButton"
|
|
|
|
v-gl-tooltip.hover
|
|
|
|
:title="expandDiffToFullFileTitle"
|
2019-09-12 05:04:22 +00:00
|
|
|
class="expand-file"
|
2020-01-23 09:09:07 +00:00
|
|
|
data-track-event="click_toggle_view_full_button"
|
|
|
|
data-track-label="diff_toggle_view_full_button"
|
|
|
|
data-track-property="diff_toggle_view_full"
|
2019-03-28 21:37:06 +00:00
|
|
|
@click="toggleFullDiff(diffFile.file_path)"
|
|
|
|
>
|
|
|
|
<gl-loading-icon v-if="diffFile.isLoadingFullFile" color="dark" inline />
|
|
|
|
<icon v-else-if="diffFile.isShowingFullFile" name="doc-changes" />
|
|
|
|
<icon v-else name="doc-expand" />
|
2020-04-03 09:09:31 +00:00
|
|
|
</gl-deprecated-button>
|
|
|
|
<gl-deprecated-button
|
2019-03-28 21:37:06 +00:00
|
|
|
ref="viewButton"
|
|
|
|
v-gl-tooltip.hover
|
|
|
|
:href="diffFile.view_path"
|
2020-02-06 21:08:48 +00:00
|
|
|
target="_blank"
|
2019-09-12 05:04:22 +00:00
|
|
|
class="view-file"
|
2020-01-23 09:09:07 +00:00
|
|
|
data-track-event="click_toggle_view_sha_button"
|
|
|
|
data-track-label="diff_toggle_view_sha_button"
|
|
|
|
data-track-property="diff_toggle_view_sha"
|
2019-03-28 21:37:06 +00:00
|
|
|
:title="viewFileButtonText"
|
|
|
|
>
|
2019-04-15 08:40:19 +00:00
|
|
|
<icon name="doc-text" />
|
2020-04-03 09:09:31 +00:00
|
|
|
</gl-deprecated-button>
|
2019-03-28 21:37:06 +00:00
|
|
|
|
|
|
|
<a
|
|
|
|
v-if="diffFile.external_url"
|
2019-09-12 05:04:22 +00:00
|
|
|
ref="externalLink"
|
2019-03-28 21:37:06 +00:00
|
|
|
v-gl-tooltip.hover
|
|
|
|
:href="diffFile.external_url"
|
|
|
|
:title="`View on ${diffFile.formatted_external_url}`"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
2020-01-23 09:09:07 +00:00
|
|
|
data-track-event="click_toggle_external_button"
|
|
|
|
data-track-label="diff_toggle_external_button"
|
|
|
|
data-track-property="diff_toggle_external"
|
2019-09-12 05:04:22 +00:00
|
|
|
class="btn btn-file-option"
|
2019-03-28 21:37:06 +00:00
|
|
|
>
|
|
|
|
<icon name="external-link" />
|
|
|
|
</a>
|
|
|
|
</div>
|
2018-06-21 12:22:40 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|