Commit 76e20d1d authored by Denys Mishunov's avatar Denys Mishunov Committed by Phil Hughes

Disabled Edit button for binary snippets

parent fe0f7e1a
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
GlButton, GlButton,
GlTooltipDirective,
} from '@gitlab/ui'; } from '@gitlab/ui';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
...@@ -30,6 +31,9 @@ export default { ...@@ -30,6 +31,9 @@ export default {
TimeAgoTooltip, TimeAgoTooltip,
GlButton, GlButton,
}, },
directives: {
GlTooltip: GlTooltipDirective,
},
apollo: { apollo: {
canCreateSnippet: { canCreateSnippet: {
query() { query() {
...@@ -67,6 +71,10 @@ export default { ...@@ -67,6 +71,10 @@ export default {
condition: this.snippet.userPermissions.updateSnippet, condition: this.snippet.userPermissions.updateSnippet,
text: __('Edit'), text: __('Edit'),
href: this.editLink, href: this.editLink,
disabled: this.snippet.blob.binary,
title: this.snippet.blob.binary
? __('Snippets with non-text files can only be edited via Git.')
: undefined,
}, },
{ {
condition: this.snippet.userPermissions.adminSnippet, condition: this.snippet.userPermissions.adminSnippet,
...@@ -186,9 +194,14 @@ export default { ...@@ -186,9 +194,14 @@ export default {
<div class="detail-page-header-actions"> <div class="detail-page-header-actions">
<div class="d-none d-sm-flex"> <div class="d-none d-sm-flex">
<template v-for="(action, index) in personalSnippetActions"> <template v-for="(action, index) in personalSnippetActions">
<gl-button <div
v-if="action.condition" v-if="action.condition"
:key="index" :key="index"
v-gl-tooltip
:title="action.title"
class="d-inline-block"
>
<gl-button
:disabled="action.disabled" :disabled="action.disabled"
:variant="action.variant" :variant="action.variant"
:category="action.category" :category="action.category"
...@@ -198,6 +211,7 @@ export default { ...@@ -198,6 +211,7 @@ export default {
> >
{{ action.text }} {{ action.text }}
</gl-button> </gl-button>
</div>
</template> </template>
</div> </div>
<div class="d-block d-sm-none dropdown"> <div class="d-block d-sm-none dropdown">
...@@ -205,6 +219,8 @@ export default { ...@@ -205,6 +219,8 @@ export default {
<gl-dropdown-item <gl-dropdown-item
v-for="(action, index) in personalSnippetActions" v-for="(action, index) in personalSnippetActions"
:key="index" :key="index"
:disabled="action.disabled"
:title="action.title"
:href="action.href" :href="action.href"
@click="action.click ? action.click() : undefined" @click="action.click ? action.click() : undefined"
>{{ action.text }}</gl-dropdown-item >{{ action.text }}</gl-dropdown-item
......
---
title: Disabled Edit button for binary snippets
merge_request: 30904
author:
type: added
...@@ -19178,6 +19178,9 @@ msgstr "" ...@@ -19178,6 +19178,9 @@ msgstr ""
msgid "Snippets" msgid "Snippets"
msgstr "" msgstr ""
msgid "Snippets with non-text files can only be edited via Git."
msgstr ""
msgid "SnippetsEmptyState|Code snippets" msgid "SnippetsEmptyState|Code snippets"
msgstr "" msgstr ""
......
...@@ -7,7 +7,6 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -7,7 +7,6 @@ import { shallowMount } from '@vue/test-utils';
describe('Snippet header component', () => { describe('Snippet header component', () => {
let wrapper; let wrapper;
const snippet = { const snippet = {
snippet: {
id: 'gid://gitlab/PersonalSnippet/50', id: 'gid://gitlab/PersonalSnippet/50',
title: 'The property of Thor', title: 'The property of Thor',
visibilityLevel: 'private', visibilityLevel: 'private',
...@@ -21,12 +20,14 @@ describe('Snippet header component', () => { ...@@ -21,12 +20,14 @@ describe('Snippet header component', () => {
author: { author: {
name: 'Thor Odinson', name: 'Thor Odinson',
}, },
blob: {
binary: false,
}, },
}; };
const mutationVariables = { const mutationVariables = {
mutation: DeleteSnippetMutation, mutation: DeleteSnippetMutation,
variables: { variables: {
id: snippet.snippet.id, id: snippet.id,
}, },
}; };
const errorMsg = 'Foo bar'; const errorMsg = 'Foo bar';
...@@ -46,10 +47,12 @@ describe('Snippet header component', () => { ...@@ -46,10 +47,12 @@ describe('Snippet header component', () => {
loading = false, loading = false,
permissions = {}, permissions = {},
mutationRes = mutationTypes.RESOLVE, mutationRes = mutationTypes.RESOLVE,
snippetProps = {},
} = {}) { } = {}) {
const defaultProps = Object.assign({}, snippet); // const defaultProps = Object.assign({}, snippet, snippetProps);
const defaultProps = Object.assign(snippet, snippetProps);
if (permissions) { if (permissions) {
Object.assign(defaultProps.snippet.userPermissions, { Object.assign(defaultProps.userPermissions, {
...permissions, ...permissions,
}); });
} }
...@@ -65,8 +68,10 @@ describe('Snippet header component', () => { ...@@ -65,8 +68,10 @@ describe('Snippet header component', () => {
wrapper = shallowMount(SnippetHeader, { wrapper = shallowMount(SnippetHeader, {
mocks: { $apollo }, mocks: { $apollo },
propsData: { propsData: {
snippet: {
...defaultProps, ...defaultProps,
}, },
},
stubs: { stubs: {
ApolloMutation, ApolloMutation,
}, },
...@@ -126,6 +131,17 @@ describe('Snippet header component', () => { ...@@ -126,6 +131,17 @@ describe('Snippet header component', () => {
expect(wrapper.find(GlModal).exists()).toBe(true); expect(wrapper.find(GlModal).exists()).toBe(true);
}); });
it('renders Edit button as disabled for binary snippets', () => {
createComponent({
snippetProps: {
blob: {
binary: true,
},
},
});
expect(wrapper.find('[href*="edit"]').props('disabled')).toBe(true);
});
describe('Delete mutation', () => { describe('Delete mutation', () => {
const { location } = window; const { location } = window;
......
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