Commit 3cd4a7de authored by Jeremy Elder's avatar Jeremy Elder Committed by Martin Wortschack

Migrate buttons to new components in …settings_dropdown.vue

parent c9450eab
<script> <script>
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { GlDeprecatedButton, GlIcon } from '@gitlab/ui'; import { GlButtonGroup, GlButton, GlDropdown } from '@gitlab/ui';
import { __ } from '~/locale';
export default { export default {
components: { components: {
GlDeprecatedButton, GlButtonGroup,
GlIcon, GlButton,
GlDropdown,
}, },
computed: { computed: {
...mapGetters('diffs', ['isInlineView', 'isParallelView']), ...mapGetters('diffs', ['isInlineView', 'isParallelView']),
...mapState('diffs', ['renderTreeList', 'showWhitespace']), ...mapState('diffs', ['renderTreeList', 'showWhitespace']),
}, },
mounted() {
this.patchAriaLabel();
},
updated() {
this.patchAriaLabel();
},
methods: { methods: {
...mapActions('diffs', [ ...mapActions('diffs', [
'setInlineDiffViewType', 'setInlineDiffViewType',
...@@ -18,74 +26,69 @@ export default { ...@@ -18,74 +26,69 @@ export default {
'setRenderTreeList', 'setRenderTreeList',
'setShowWhitespace', 'setShowWhitespace',
]), ]),
patchAriaLabel() {
this.$el
.querySelector('.js-show-diff-settings')
.setAttribute('aria-label', __('Diff view settings'));
},
}, },
}; };
</script> </script>
<template> <template>
<div class="dropdown"> <gl-dropdown icon="settings" toggle-class="js-show-diff-settings" right>
<button <div class="gl-px-3">
type="button" <span class="gl-font-weight-bold gl-display-block gl-mb-2">{{ __('File browser') }}</span>
class="btn btn-default js-show-diff-settings" <gl-button-group class="gl-display-flex">
data-toggle="dropdown" <gl-button
data-display="static" :class="{ selected: !renderTreeList }"
> class="gl-w-half js-list-view"
<gl-icon name="settings" /> <gl-icon name="chevron-down" /> @click="setRenderTreeList(false)"
</button> >
<div class="dropdown-menu dropdown-menu-right p-2 pt-3 pb-3"> {{ __('List view') }}
<div> </gl-button>
<span class="bold d-block mb-1">{{ __('File browser') }}</span> <gl-button
<div class="btn-group d-flex"> :class="{ selected: renderTreeList }"
<gl-deprecated-button class="gl-w-half js-tree-view"
:class="{ active: !renderTreeList }" @click="setRenderTreeList(true)"
class="w-100 js-list-view" >
@click="setRenderTreeList(false)" {{ __('Tree view') }}
> </gl-button>
{{ __('List view') }} </gl-button-group>
</gl-deprecated-button> </div>
<gl-deprecated-button <div class="gl-mt-3 gl-px-3">
:class="{ active: renderTreeList }" <span class="gl-font-weight-bold gl-display-block gl-mb-2">{{ __('Compare changes') }}</span>
class="w-100 js-tree-view" <gl-button-group class="gl-display-flex js-diff-view-buttons">
@click="setRenderTreeList(true)" <gl-button
> id="inline-diff-btn"
{{ __('Tree view') }} :class="{ selected: isInlineView }"
</gl-deprecated-button> class="gl-w-half js-inline-diff-button"
</div> data-view-type="inline"
</div> @click="setInlineDiffViewType"
<div class="mt-2"> >
<span class="bold d-block mb-1">{{ __('Compare changes') }}</span> {{ __('Inline') }}
<div class="btn-group d-flex js-diff-view-buttons"> </gl-button>
<gl-deprecated-button <gl-button
id="inline-diff-btn" id="parallel-diff-btn"
:class="{ active: isInlineView }" :class="{ selected: isParallelView }"
class="w-100 js-inline-diff-button" class="gl-w-half js-parallel-diff-button"
data-view-type="inline" data-view-type="parallel"
@click="setInlineDiffViewType" @click="setParallelDiffViewType"
> >
{{ __('Inline') }} {{ __('Side-by-side') }}
</gl-deprecated-button> </gl-button>
<gl-deprecated-button </gl-button-group>
id="parallel-diff-btn" </div>
:class="{ active: isParallelView }" <div class="gl-mt-3 gl-px-3">
class="w-100 js-parallel-diff-button" <label class="gl-mb-0">
data-view-type="parallel" <input
@click="setParallelDiffViewType" id="show-whitespace"
> type="checkbox"
{{ __('Side-by-side') }} :checked="showWhitespace"
</gl-deprecated-button> @change="setShowWhitespace({ showWhitespace: $event.target.checked, pushState: true })"
</div> />
</div> {{ __('Show whitespace changes') }}
<div class="mt-2"> </label>
<label class="mb-0">
<input
id="show-whitespace"
type="checkbox"
:checked="showWhitespace"
@change="setShowWhitespace({ showWhitespace: $event.target.checked, pushState: true })"
/>
{{ __('Show whitespace changes') }}
</label>
</div>
</div> </div>
</div> </gl-dropdown>
</template> </template>
---
title: Migrating buttons and classes to match GitLab UI
merge_request: 40409
author:
type: other
...@@ -8586,6 +8586,9 @@ msgstr "" ...@@ -8586,6 +8586,9 @@ msgstr ""
msgid "Diff limits" msgid "Diff limits"
msgstr "" msgstr ""
msgid "Diff view settings"
msgstr ""
msgid "Difference between start date and now" msgid "Difference between start date and now"
msgstr "" msgstr ""
......
...@@ -7,7 +7,7 @@ import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '~/diffs/constant ...@@ -7,7 +7,7 @@ import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '~/diffs/constant
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
describe('Diff settiings dropdown component', () => { describe('Diff settings dropdown component', () => {
let vm; let vm;
let actions; let actions;
...@@ -61,50 +61,50 @@ describe('Diff settiings dropdown component', () => { ...@@ -61,50 +61,50 @@ describe('Diff settiings dropdown component', () => {
expect(actions.setRenderTreeList).toHaveBeenCalledWith(expect.anything(), true, undefined); expect(actions.setRenderTreeList).toHaveBeenCalledWith(expect.anything(), true, undefined);
}); });
it('sets list button as active when renderTreeList is false', () => { it('sets list button as selected when renderTreeList is false', () => {
createComponent(store => { createComponent(store => {
Object.assign(store.state.diffs, { Object.assign(store.state.diffs, {
renderTreeList: false, renderTreeList: false,
}); });
}); });
expect(vm.find('.js-list-view').classes('active')).toBe(true); expect(vm.find('.js-list-view').classes('selected')).toBe(true);
expect(vm.find('.js-tree-view').classes('active')).toBe(false); expect(vm.find('.js-tree-view').classes('selected')).toBe(false);
}); });
it('sets tree button as active when renderTreeList is true', () => { it('sets tree button as selected when renderTreeList is true', () => {
createComponent(store => { createComponent(store => {
Object.assign(store.state.diffs, { Object.assign(store.state.diffs, {
renderTreeList: true, renderTreeList: true,
}); });
}); });
expect(vm.find('.js-list-view').classes('active')).toBe(false); expect(vm.find('.js-list-view').classes('selected')).toBe(false);
expect(vm.find('.js-tree-view').classes('active')).toBe(true); expect(vm.find('.js-tree-view').classes('selected')).toBe(true);
}); });
}); });
describe('compare changes', () => { describe('compare changes', () => {
it('sets inline button as active', () => { it('sets inline button as selected', () => {
createComponent(store => { createComponent(store => {
Object.assign(store.state.diffs, { Object.assign(store.state.diffs, {
diffViewType: INLINE_DIFF_VIEW_TYPE, diffViewType: INLINE_DIFF_VIEW_TYPE,
}); });
}); });
expect(vm.find('.js-inline-diff-button').classes('active')).toBe(true); expect(vm.find('.js-inline-diff-button').classes('selected')).toBe(true);
expect(vm.find('.js-parallel-diff-button').classes('active')).toBe(false); expect(vm.find('.js-parallel-diff-button').classes('selected')).toBe(false);
}); });
it('sets parallel button as active', () => { it('sets parallel button as selected', () => {
createComponent(store => { createComponent(store => {
Object.assign(store.state.diffs, { Object.assign(store.state.diffs, {
diffViewType: PARALLEL_DIFF_VIEW_TYPE, diffViewType: PARALLEL_DIFF_VIEW_TYPE,
}); });
}); });
expect(vm.find('.js-inline-diff-button').classes('active')).toBe(false); expect(vm.find('.js-inline-diff-button').classes('selected')).toBe(false);
expect(vm.find('.js-parallel-diff-button').classes('active')).toBe(true); expect(vm.find('.js-parallel-diff-button').classes('selected')).toBe(true);
}); });
it('calls setInlineDiffViewType when clicking inline button', () => { it('calls setInlineDiffViewType when clicking inline button', () => {
......
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