debian-mirror-gitlab/app/assets/javascripts/diffs/components/edit_button.vue

66 lines
1.3 KiB
Vue
Raw Normal View History

2018-11-08 19:23:39 +05:30
<script>
2020-04-22 19:07:51 +05:30
import { GlTooltipDirective, GlDeprecatedButton } from '@gitlab/ui';
2020-05-24 23:13:21 +05:30
import { __ } from '~/locale';
2019-07-07 11:18:12 +05:30
import Icon from '~/vue_shared/components/icon.vue';
2018-11-08 19:23:39 +05:30
export default {
2019-07-07 11:18:12 +05:30
components: {
2020-04-22 19:07:51 +05:30
GlDeprecatedButton,
2019-07-07 11:18:12 +05:30
Icon,
},
directives: {
GlTooltip: GlTooltipDirective,
},
2018-11-08 19:23:39 +05:30
props: {
editPath: {
type: String,
2020-05-24 23:13:21 +05:30
required: false,
default: '',
2018-11-08 19:23:39 +05:30
},
canCurrentUserFork: {
type: Boolean,
required: true,
},
canModifyBlob: {
type: Boolean,
required: false,
default: false,
},
},
2020-05-24 23:13:21 +05:30
computed: {
tooltipTitle() {
if (this.isDisabled) {
return __("Can't edit as source branch was deleted");
}
return __('Edit file');
},
isDisabled() {
return !this.editPath;
},
},
2018-11-08 19:23:39 +05:30
methods: {
handleEditClick(evt) {
2019-07-07 11:18:12 +05:30
if (this.canCurrentUserFork && !this.canModifyBlob) {
2018-11-08 19:23:39 +05:30
evt.preventDefault();
this.$emit('showForkMessage');
}
},
},
};
</script>
<template>
2020-05-24 23:13:21 +05:30
<span v-gl-tooltip.top :title="tooltipTitle">
<gl-deprecated-button
:href="editPath"
:disabled="isDisabled"
:class="{ 'cursor-not-allowed': isDisabled }"
class="rounded-0 js-edit-blob"
@click.native="handleEditClick"
>
<icon name="pencil" />
</gl-deprecated-button>
</span>
2018-11-08 19:23:39 +05:30
</template>