Commit 85bec20f authored by Jarek Ostrowski's avatar Jarek Ostrowski

Update design mgmt navigation to gl-button

MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/39104
parent e4772db6
...@@ -95,11 +95,9 @@ export default { ...@@ -95,11 +95,9 @@ export default {
:category="buttonCategory" :category="buttonCategory"
:size="buttonSize" :size="buttonSize"
:class="buttonClass" :class="buttonClass"
:disabled="isDeleting || !hasSelectedDesigns"
:loading="loading" :loading="loading"
:icon="buttonIcon" :icon="buttonIcon"
> :disabled="isDeleting || !hasSelectedDesigns"
<slot></slot> />
</gl-button>
</div> </div>
</template> </template>
<script> <script>
/* global Mousetrap */ /* global Mousetrap */
import 'mousetrap'; import 'mousetrap';
import { GlButton, GlButtonGroup } from '@gitlab/ui';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
import PaginationButton from './pagination_button.vue';
import allDesignsMixin from '../../mixins/all_designs'; import allDesignsMixin from '../../mixins/all_designs';
import { DESIGN_ROUTE_NAME } from '../../router/constants'; import { DESIGN_ROUTE_NAME } from '../../router/constants';
export default { export default {
components: { components: {
PaginationButton, GlButton,
GlButtonGroup,
}, },
mixins: [allDesignsMixin], mixins: [allDesignsMixin],
props: { props: {
...@@ -31,12 +32,12 @@ export default { ...@@ -31,12 +32,12 @@ export default {
}); });
}, },
previousDesign() { previousDesign() {
if (!this.designsCount) return null; if (this.currentIndex === 0) return null;
return this.designs[this.currentIndex - 1]; return this.designs[this.currentIndex - 1];
}, },
nextDesign() { nextDesign() {
if (!this.designsCount) return null; if (this.currentIndex + 1 === this.designsCount) return null;
return this.designs[this.currentIndex + 1]; return this.designs[this.currentIndex + 1];
}, },
...@@ -65,19 +66,21 @@ export default { ...@@ -65,19 +66,21 @@ export default {
<template> <template>
<div v-if="designsCount" class="d-flex align-items-center"> <div v-if="designsCount" class="d-flex align-items-center">
{{ paginationText }} {{ paginationText }}
<div class="btn-group gl-ml-3"> <gl-button-group class="ml-3 mr-3">
<pagination-button <gl-button
:design="previousDesign" :disabled="!previousDesign"
:title="s__('DesignManagement|Go to previous design')" :title="s__('DesignManagement|Go to previous design')"
icon-name="angle-left" icon="angle-left"
class="js-previous-design" class="js-previous-design"
@click="navigateToDesign(previousDesign)"
/> />
<pagination-button <gl-button
:design="nextDesign" :disabled="!nextDesign"
:title="s__('DesignManagement|Go to next design')" :title="s__('DesignManagement|Go to next design')"
icon-name="angle-right" icon="angle-right"
class="js-next-design" class="js-next-design"
@click="navigateToDesign(nextDesign)"
/> />
</div> </gl-button-group>
</div> </div>
</template> </template>
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
import { GlButton, GlIcon } from '@gitlab/ui'; import { GlButton, GlIcon } from '@gitlab/ui';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import timeagoMixin from '~/vue_shared/mixins/timeago'; import timeagoMixin from '~/vue_shared/mixins/timeago';
import Pagination from './pagination.vue'; import DesignNavigation from './design_navigation.vue';
import DeleteButton from '../delete_button.vue'; import DeleteButton from '../delete_button.vue';
import permissionsQuery from '../../graphql/queries/design_permissions.query.graphql'; import permissionsQuery from '../../graphql/queries/design_permissions.query.graphql';
import { DESIGNS_ROUTE_NAME } from '../../router/constants'; import { DESIGNS_ROUTE_NAME } from '../../router/constants';
export default { export default {
components: { components: {
GlButton,
GlIcon, GlIcon,
Pagination, DesignNavigation,
DeleteButton, DeleteButton,
GlButton,
}, },
mixins: [timeagoMixin], mixins: [timeagoMixin],
props: { props: {
...@@ -111,19 +111,16 @@ export default { ...@@ -111,19 +111,16 @@ export default {
<small v-if="updatedAt" class="text-secondary">{{ updatedText }}</small> <small v-if="updatedAt" class="text-secondary">{{ updatedText }}</small>
</div> </div>
</div> </div>
<design-navigation :id="id" class="ml-auto flex-shrink-0" />
<div class="gl-display-flex gl-align-items-center"> <gl-button :href="image" icon="download" />
<pagination :id="id" class="gl-mr-3 gl-flex-shrink-0" /> <delete-button
<gl-button :href="image" icon="download" /> v-if="isLatestVersion && canDeleteDesign"
<delete-button class="gl-ml-3"
v-if="isLatestVersion && canDeleteDesign" :is-deleting="isDeleting"
class="gl-ml-3" button-variant="warning"
:is-deleting="isDeleting" button-icon="archive"
button-variant="warning" button-category="secondary"
button-icon="archive" @deleteSelectedDesigns="$emit('delete')"
button-category="secondary" />
@deleteSelectedDesigns="$emit('delete')"
/>
</div>
</header> </header>
</template> </template>
<script>
import Icon from '~/vue_shared/components/icon.vue';
import { DESIGN_ROUTE_NAME } from '../../router/constants';
export default {
components: {
Icon,
},
props: {
design: {
type: Object,
required: false,
default: null,
},
title: {
type: String,
required: true,
},
iconName: {
type: String,
required: true,
},
},
computed: {
designLink() {
if (!this.design) return {};
return {
name: DESIGN_ROUTE_NAME,
params: { id: this.design.filename },
query: this.$route.query,
};
},
},
};
</script>
<template>
<router-link
:to="designLink"
:disabled="!design"
:class="{ disabled: !design }"
:aria-label="title"
class="btn btn-default"
>
<icon :name="iconName" />
</router-link>
</template>
---
title: Update design mgmt navigation to use gl-button
merge_request: 39104
author:
type: changed
...@@ -2,28 +2,34 @@ ...@@ -2,28 +2,34 @@
exports[`Design management pagination component hides components when designs are empty 1`] = `<!---->`; exports[`Design management pagination component hides components when designs are empty 1`] = `<!---->`;
exports[`Design management pagination component renders pagination buttons 1`] = ` exports[`Design management pagination component renders navigation buttons 1`] = `
<div <div
class="d-flex align-items-center" class="d-flex align-items-center"
> >
0 of 2 0 of 2
<div <gl-button-group-stub
class="btn-group gl-ml-3" class="ml-3 mr-3"
> >
<pagination-button-stub <gl-button-stub
category="primary"
class="js-previous-design" class="js-previous-design"
iconname="angle-left" disabled="true"
icon="angle-left"
size="medium"
title="Go to previous design" title="Go to previous design"
variant="default"
/> />
<pagination-button-stub <gl-button-stub
category="primary"
class="js-next-design" class="js-next-design"
design="[object Object]" icon="angle-right"
iconname="angle-right" size="medium"
title="Go to next design" title="Go to next design"
variant="default"
/> />
</div> </gl-button-group-stub>
</div> </div>
`; `;
...@@ -35,31 +35,27 @@ exports[`Design management toolbar component renders design and updated data 1`] ...@@ -35,31 +35,27 @@ exports[`Design management toolbar component renders design and updated data 1`]
</div> </div>
</div> </div>
<div <design-navigation-stub
class="gl-display-flex gl-align-items-center" class="ml-auto flex-shrink-0"
> id="1"
<pagination-stub />
class="gl-mr-3 gl-flex-shrink-0"
id="1" <gl-button-stub
/> category="primary"
href="/-/designs/306/7f747adcd4693afadbe968d7ba7d983349b9012d"
<gl-button-stub icon="download"
category="primary" size="medium"
href="/-/designs/306/7f747adcd4693afadbe968d7ba7d983349b9012d" variant="default"
icon="download" />
size="medium"
variant="default" <delete-button-stub
/> buttoncategory="secondary"
buttonclass=""
<delete-button-stub buttonicon="archive"
buttoncategory="secondary" buttonsize="medium"
buttonclass="" buttonvariant="warning"
buttonicon="archive" class="gl-ml-3"
buttonsize="medium" hasselecteddesigns="true"
buttonvariant="warning" />
class="gl-ml-3"
hasselecteddesigns="true"
/>
</div>
</header> </header>
`; `;
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Design management pagination button component disables button when no design is passed 1`] = `
<router-link-stub
aria-label="Test title"
class="btn btn-default disabled"
disabled="true"
to="[object Object]"
>
<icon-stub
name="angle-right"
size="16"
/>
</router-link-stub>
`;
exports[`Design management pagination button component renders router-link 1`] = `
<router-link-stub
aria-label="Test title"
class="btn btn-default"
to="[object Object]"
>
<icon-stub
name="angle-right"
size="16"
/>
</router-link-stub>
`;
/* global Mousetrap */ /* global Mousetrap */
import 'mousetrap'; import 'mousetrap';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Pagination from '~/design_management/components/toolbar/pagination.vue'; import DesignNavigation from '~/design_management/components/toolbar/design_navigation.vue';
import { DESIGN_ROUTE_NAME } from '~/design_management/router/constants'; import { DESIGN_ROUTE_NAME } from '~/design_management/router/constants';
const push = jest.fn(); const push = jest.fn();
...@@ -18,7 +18,7 @@ describe('Design management pagination component', () => { ...@@ -18,7 +18,7 @@ describe('Design management pagination component', () => {
let wrapper; let wrapper;
function createComponent() { function createComponent() {
wrapper = shallowMount(Pagination, { wrapper = shallowMount(DesignNavigation, {
propsData: { propsData: {
id: '2', id: '2',
}, },
...@@ -41,7 +41,7 @@ describe('Design management pagination component', () => { ...@@ -41,7 +41,7 @@ describe('Design management pagination component', () => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
it('renders pagination buttons', () => { it('renders navigation buttons', () => {
wrapper.setData({ wrapper.setData({
designs: [{ id: '1' }, { id: '2' }], designs: [{ id: '1' }, { id: '2' }],
}); });
......
import { createLocalVue, shallowMount } from '@vue/test-utils';
import VueRouter from 'vue-router';
import PaginationButton from '~/design_management/components/toolbar/pagination_button.vue';
import { DESIGN_ROUTE_NAME } from '~/design_management/router/constants';
const localVue = createLocalVue();
localVue.use(VueRouter);
const router = new VueRouter();
describe('Design management pagination button component', () => {
let wrapper;
function createComponent(design = null) {
wrapper = shallowMount(PaginationButton, {
localVue,
router,
propsData: {
design,
title: 'Test title',
iconName: 'angle-right',
},
stubs: ['router-link'],
});
}
afterEach(() => {
wrapper.destroy();
});
it('disables button when no design is passed', () => {
createComponent();
expect(wrapper.element).toMatchSnapshot();
});
it('renders router-link', () => {
createComponent({ id: '2' });
expect(wrapper.element).toMatchSnapshot();
});
describe('designLink', () => {
it('returns empty link when design is null', () => {
createComponent();
expect(wrapper.vm.designLink).toEqual({});
});
it('returns design link', () => {
createComponent({ id: '2', filename: 'test' });
wrapper.vm.$router.replace('/root/test-project/issues/1/designs/test?version=1');
expect(wrapper.vm.designLink).toEqual({
name: DESIGN_ROUTE_NAME,
params: { id: 'test' },
query: { version: '1' },
});
});
});
});
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