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