Commit dec19fa9 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'design-management-design-update' into 'master'

Design updates to design management

See merge request gitlab-org/gitlab-ee!10410
parents 63f0f0e0 89e97876
......@@ -24,10 +24,15 @@ export default {
</script>
<template>
<header class="row-content-block border-top-0 pt-2 pb-2 pl-0 pr-0 d-flex">
<div class="ml-auto">
<gl-button :disabled="isSaving" variant="primary" @click="openFileUpload">
{{ s__('DesignManagement|Upload new designs') }}
<header class="row-content-block border-top-0 p-2 d-flex">
<div>
<gl-button
:disabled="isSaving"
variant="primary"
class="btn-inverted"
@click="openFileUpload"
>
{{ s__('DesignManagement|Upload designs') }}
<gl-loading-icon v-if="isSaving" inline class="ml-1" />
</gl-button>
<input
......@@ -36,6 +41,7 @@ export default {
name="design_file"
accept="image/*"
class="hide"
multiple
@change="onFileUploadChange"
/>
</div>
......
......@@ -2,6 +2,7 @@ import Vue from 'vue';
import VueApollo from 'vue-apollo';
import _ from 'underscore';
import createDefaultClient from '~/lib/graphql';
import allDesigns from './queries/allDesigns.graphql';
Vue.use(VueApollo);
......@@ -14,8 +15,7 @@ const createMockDesign = id => ({
__typename: 'Design',
});
export default new VueApollo({
defaultClient: createDefaultClient({
const defaultClient = createDefaultClient({
defaults: {
designs: [
createMockDesign(_.uniqueId()),
......@@ -28,17 +28,32 @@ export default new VueApollo({
resolvers: {
Mutation: {
uploadDesign(ctx, { name }, { cache }) {
const design = {
const designs = name.map(n => ({
...createMockDesign(_.uniqueId()),
name,
name: n,
commentsCount: 0,
};
}));
cache.writeData({ data: design });
cache.writeData({ data: designs });
return design;
return designs;
},
},
},
}),
});
defaultClient
.watchQuery({
query: allDesigns,
})
.subscribe(({ data: { designs } }) => {
const badge = document.querySelector('.js-designs-count');
if (badge) {
badge.textContent = designs.length;
}
});
export default new VueApollo({
defaultClient,
});
......@@ -35,7 +35,14 @@ export default {
},
methods: {
onUploadDesign(files) {
const file = files[0];
const optimisticResponse = [...files].map(file => ({
__typename: 'Design',
id: -1,
image: '',
name: file.name,
commentsCount: 0,
updatedAt: new Date().toString(),
}));
this.isSaving = true;
......@@ -43,24 +50,17 @@ export default {
.mutate({
mutation: uploadDesignQuery,
variables: {
name: file.name,
name: [...files].map(({ name }) => name),
},
update: (store, { data: { uploadDesign } }) => {
const data = store.readQuery({ query: allDesignsQuery });
data.designs.unshift(uploadDesign);
data.designs.unshift(...uploadDesign);
store.writeQuery({ query: allDesignsQuery, data });
},
optimisticResponse: {
__typename: 'Mutation',
uploadDesign: {
__typename: 'Design',
id: -1,
image: '',
name: file.name,
commentsCount: 0,
updatedAt: new Date().toString(),
},
uploadDesign: optimisticResponse,
},
})
.then(() => {
......
mutation addDesigns($name: String) {
mutation addDesigns($name: [String]) {
uploadDesign(name: $name) @client {
id
image
......
......@@ -12,7 +12,7 @@ const router = new VueRouter({
{
name: 'root',
path: '/',
component: null,
component: Home,
meta: {
el: 'discussion',
},
......
......@@ -2,17 +2,16 @@
exports[`Design management upload form component renders loading icon 1`] = `
<header
class="row-content-block border-top-0 pt-2 pb-2 pl-0 pr-0 d-flex"
class="row-content-block border-top-0 p-2 d-flex"
>
<div
class="ml-auto"
>
<div>
<glbutton-stub
class="btn-inverted"
disabled="true"
variant="primary"
>
Upload new designs
Upload designs
<glloadingicon-stub
class="ml-1"
......@@ -26,6 +25,7 @@ exports[`Design management upload form component renders loading icon 1`] = `
<input
accept="image/*"
class="hide"
multiple="multiple"
name="design_file"
type="file"
/>
......@@ -35,16 +35,15 @@ exports[`Design management upload form component renders loading icon 1`] = `
exports[`Design management upload form component renders upload design button 1`] = `
<header
class="row-content-block border-top-0 pt-2 pb-2 pl-0 pr-0 d-flex"
class="row-content-block border-top-0 p-2 d-flex"
>
<div
class="ml-auto"
>
<div>
<glbutton-stub
class="btn-inverted"
variant="primary"
>
Upload new designs
Upload designs
<!---->
</glbutton-stub>
......@@ -52,6 +51,7 @@ exports[`Design management upload form component renders upload design button 1`
<input
accept="image/*"
class="hide"
multiple="multiple"
name="design_file"
type="file"
/>
......
......@@ -66,11 +66,12 @@ describe('Design management index page', () => {
mutation: uploadDesignQuery,
update: expect.any(Function),
variables: {
name: 'test',
name: ['test'],
},
optimisticResponse: {
__typename: 'Mutation',
uploadDesign: {
uploadDesign: [
{
__typename: 'Design',
id: -1,
image: '',
......@@ -78,6 +79,7 @@ describe('Design management index page', () => {
commentsCount: 0,
updatedAt: expect.any(String),
},
],
},
});
});
......
......@@ -40,10 +40,10 @@ describe('Design management router', () => {
});
describe('root', () => {
it('pushes empty component', () => {
it('pushes home component', () => {
router.push('/');
expect(vm.isEmpty()).toBe(true);
expect(vm.find(Designs).exists()).toBe(true);
});
});
......
......@@ -3487,7 +3487,7 @@ msgstr ""
msgid "DesignManagement|Error uploading a new design. Please try again"
msgstr ""
msgid "DesignManagement|Upload new designs"
msgid "DesignManagement|Upload designs"
msgstr ""
msgid "Designs"
......
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