Commit fe10ea1f authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'design-management-fe-be-integration' into 'master'

Design management uploading

See merge request gitlab-org/gitlab-ee!10655
parents 6245b6ea f4cb8cfd
...@@ -21,7 +21,7 @@ export default { ...@@ -21,7 +21,7 @@ export default {
:id="design.id" :id="design.id"
:comments-count="design.commentsCount" :comments-count="design.commentsCount"
:image="design.image" :image="design.image"
:name="design.name" :name="design.filename"
:updated-at="design.updatedAt" :updated-at="design.updatedAt"
/> />
</li> </li>
......
...@@ -10,12 +10,13 @@ export default { ...@@ -10,12 +10,13 @@ export default {
}, },
props: { props: {
id: { id: {
type: Number, type: [Number, String],
required: true, required: true,
}, },
commentsCount: { commentsCount: {
type: Number, type: Number,
required: true, required: false,
default: 0,
}, },
image: { image: {
type: String, type: String,
...@@ -27,7 +28,8 @@ export default { ...@@ -27,7 +28,8 @@ export default {
}, },
updatedAt: { updatedAt: {
type: String, type: String,
required: true, required: false,
default: null,
}, },
}, },
computed: { computed: {
...@@ -49,7 +51,7 @@ export default { ...@@ -49,7 +51,7 @@ export default {
<div class="card-footer d-flex w-100"> <div class="card-footer d-flex w-100">
<div class="d-flex flex-column str-truncated-100"> <div class="d-flex flex-column str-truncated-100">
<span class="bold str-truncated-100">{{ name }}</span> <span class="bold str-truncated-100">{{ name }}</span>
<span class="str-truncated-100"> <span v-if="updatedAt" class="str-truncated-100">
{{ __('Updated') }} <timeago :time="updatedAt" tooltip-placement="bottom" /> {{ __('Updated') }} <timeago :time="updatedAt" tooltip-placement="bottom" />
</span> </span>
</div> </div>
......
...@@ -29,7 +29,7 @@ export default { ...@@ -29,7 +29,7 @@ export default {
updatedAt: { updatedAt: {
type: String, type: String,
required: false, required: false,
default: '', default: null,
}, },
updatedBy: { updatedBy: {
type: Object, type: Object,
...@@ -61,7 +61,7 @@ export default { ...@@ -61,7 +61,7 @@ export default {
<gl-loading-icon v-if="isLoading" size="md" class="mt-2 mb-2" /> <gl-loading-icon v-if="isLoading" size="md" class="mt-2 mb-2" />
<template v-else> <template v-else>
<h2 class="m-0">{{ name }}</h2> <h2 class="m-0">{{ name }}</h2>
<small class="text-secondary">{{ updatedText }}</small> <small v-if="updatedAt" class="text-secondary">{{ updatedText }}</small>
</template> </template>
</div> </div>
<pagination :id="id" class="ml-auto" /> <pagination :id="id" class="ml-auto" />
......
...@@ -2,35 +2,26 @@ ...@@ -2,35 +2,26 @@
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import PaginationButton from './pagination_button.vue'; import PaginationButton from './pagination_button.vue';
import allDesignsQuery from '../../queries/allDesigns.graphql'; import allDesignsMixin from '../../mixins/all_designs';
export default { export default {
apollo: {
designs: {
query: allDesignsQuery,
},
},
components: { components: {
Icon, Icon,
PaginationButton, PaginationButton,
}, },
mixins: [allDesignsMixin],
props: { props: {
id: { id: {
type: Number, type: Number,
required: true, required: true,
}, },
}, },
data() {
return {
designs: [],
};
},
computed: { computed: {
designsCount() { designsCount() {
return this.designs.length; return this.designs.length;
}, },
currentIndex() { currentIndex() {
return this.designs.findIndex(design => design.id === this.id); return this.designs.findIndex(design => parseInt(design.id, 10) === this.id);
}, },
paginationText() { paginationText() {
return sprintf(s__('DesignManagement|%{current_design} of %{designs_count}'), { return sprintf(s__('DesignManagement|%{current_design} of %{designs_count}'), {
......
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import _ from 'underscore';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import appDataQuery from './queries/appData.graphql';
import allDesigns from './queries/allDesigns.graphql'; import allDesigns from './queries/allDesigns.graphql';
Vue.use(VueApollo); Vue.use(VueApollo);
const createMockDesign = id => ({
id: Number(id),
image: 'http://via.placeholder.com/1000',
name: 'test.jpg',
commentsCount: 2,
updatedAt: new Date().toString(),
updatedBy: {
name: 'Test Name',
__typename: 'Author',
},
__typename: 'Design',
});
const designsStore = [
createMockDesign(_.uniqueId()),
createMockDesign(_.uniqueId()),
createMockDesign(_.uniqueId()),
createMockDesign(_.uniqueId()),
createMockDesign(_.uniqueId()),
];
const defaultClient = createDefaultClient({ const defaultClient = createDefaultClient({
Query: { Query: {
design(ctx, { id }) { design(ctx, { id }, { cache }) {
return designsStore.find(design => design.id === id); const { projectPath, issueIid } = cache.readQuery({ query: appDataQuery });
}, const result = cache.readQuery({
}, query: allDesigns,
Mutation: { variables: { fullPath: projectPath, iid: issueIid },
uploadDesign(ctx, { files }, { cache }) { });
const previousDesigns = cache.readQuery({ query: allDesigns });
const designs = Array.from(files).map(n => ({ return {
...createMockDesign(_.uniqueId()), ...result.project.issue.designs.designs.edges.find(
name: n.name, ({ node }) => parseInt(node.id, 10) === id,
commentsCount: 0, ).node,
})); // TODO: Remove this once backend exposes raw images
const data = { image: 'http://via.placeholder.com/1000',
designs: designs.concat(previousDesigns.designs),
}; };
designsStore.unshift(...designs);
cache.writeQuery({ query: allDesigns, data });
return designs;
}, },
}, },
}); });
defaultClient.cache.writeData({
data: {
designs: designsStore,
},
});
defaultClient
.watchQuery({
query: allDesigns,
})
.subscribe(({ data: { designs } }) => {
const badge = document.querySelector('.js-designs-count');
if (badge) {
badge.textContent = designs.length;
}
});
export default new VueApollo({ export default new VueApollo({
defaultClient, defaultClient,
}); });
...@@ -3,9 +3,11 @@ import Vue from 'vue'; ...@@ -3,9 +3,11 @@ import Vue from 'vue';
import router from './router'; import router from './router';
import App from './components/app.vue'; import App from './components/app.vue';
import apolloProvider from './graphql'; import apolloProvider from './graphql';
import allDesigns from './queries/allDesigns.graphql';
export default () => { export default () => {
const el = document.getElementById('js-design-management'); const el = document.getElementById('js-design-management');
const badge = document.querySelector('.js-designs-count');
const { issueIid, projectPath } = el.dataset; const { issueIid, projectPath } = el.dataset;
$('.js-issue-tabs').on('shown.bs.tab', ({ target: { id } }) => { $('.js-issue-tabs').on('shown.bs.tab', ({ target: { id } }) => {
...@@ -23,6 +25,20 @@ export default () => { ...@@ -23,6 +25,20 @@ export default () => {
}, },
}); });
apolloProvider.clients.defaultClient
.watchQuery({
query: allDesigns,
variables: {
fullPath: projectPath,
iid: issueIid,
},
})
.subscribe(({ data }) => {
if (badge) {
badge.textContent = data.project.issue.designs.designs.length;
}
});
return new Vue({ return new Vue({
el, el,
router, router,
......
import appDataQuery from '../queries/appData.graphql';
import allDesignsQuery from '../queries/allDesigns.graphql';
export default {
apollo: {
appData: {
query: appDataQuery,
manual: true,
result({ data: { projectPath, issueIid } }) {
this.projectPath = projectPath;
this.issueIid = issueIid;
},
},
designs: {
query: allDesignsQuery,
variables() {
return {
fullPath: this.projectPath,
iid: this.issueIid,
};
},
update: data =>
data.project.issue.designs.designs.edges.map(({ node }) => ({
...node,
// TODO: Remove this once backend exposes raw images
image: 'http://via.placeholder.com/1000',
})),
error() {
this.error = true;
},
},
},
data() {
return {
designs: [],
error: false,
projectPath: '',
issueIid: null,
};
},
};
...@@ -50,10 +50,10 @@ export default { ...@@ -50,10 +50,10 @@ export default {
<toolbar <toolbar
:id="id" :id="id"
:is-loading="isLoading" :is-loading="isLoading"
:name="design.name" :name="design.filename"
:updated-at="design.updatedAt" :updated-at="design.updatedAt"
:updated-by="design.updatedBy" :updated-by="design.updatedBy"
/> />
<design-image :is-loading="isLoading" :image="design.image" :name="design.name" /> <design-image :is-loading="isLoading" :image="design.image" :name="design.filename" />
</div> </div>
</template> </template>
<script> <script>
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import _ from 'underscore';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { s__ } from '~/locale'; import { s__, sprintf } from '~/locale';
import DesignList from '../components/list/index.vue'; import DesignList from '../components/list/index.vue';
import UploadForm from '../components/upload/form.vue'; import UploadForm from '../components/upload/form.vue';
import EmptyState from '../components/empty_state.vue'; import EmptyState from '../components/empty_state.vue';
import allDesignsQuery from '../queries/allDesigns.graphql'; import allDesignsQuery from '../queries/allDesigns.graphql';
import uploadDesignQuery from '../queries/uploadDesign.graphql'; import uploadDesignMutation from '../queries/uploadDesign.graphql';
import appDataQuery from '../queries/appData.graphql';
import permissionsQuery from '../queries/permissions.graphql'; import permissionsQuery from '../queries/permissions.graphql';
import allDesignsMixin from '../mixins/all_designs';
const MAXIMUM_FILE_UPLOAD_LIMIT = 10;
export default { export default {
components: { components: {
...@@ -17,21 +20,8 @@ export default { ...@@ -17,21 +20,8 @@ export default {
UploadForm, UploadForm,
EmptyState, EmptyState,
}, },
mixins: [allDesignsMixin],
apollo: { apollo: {
appData: {
query: appDataQuery,
manual: true,
result({ data: { projectPath, issueIid } }) {
this.projectPath = projectPath;
this.issueIid = issueIid;
},
},
designs: {
query: allDesignsQuery,
error() {
this.error = true;
},
},
permissions: { permissions: {
query: permissionsQuery, query: permissionsQuery,
variables() { variables() {
...@@ -45,14 +35,10 @@ export default { ...@@ -45,14 +35,10 @@ export default {
}, },
data() { data() {
return { return {
designs: [],
permissions: { permissions: {
createDesign: false, createDesign: false,
}, },
error: false,
isSaving: false, isSaving: false,
projectPath: '',
issueIid: null,
}; };
}, },
computed: { computed: {
...@@ -73,33 +59,81 @@ export default { ...@@ -73,33 +59,81 @@ export default {
onUploadDesign(files) { onUploadDesign(files) {
if (!this.canCreateDesign) return null; if (!this.canCreateDesign) return null;
if (files.length >= MAXIMUM_FILE_UPLOAD_LIMIT) {
createFlash(
sprintf(
s__(
'DesignManagement|The maximum number of designs allowed to be uploaded is %{upload_limit}. Please try again.',
),
{
upload_limit: MAXIMUM_FILE_UPLOAD_LIMIT,
},
),
);
return null;
}
const optimisticResponse = Array.from(files).map(file => ({ const optimisticResponse = Array.from(files).map(file => ({
__typename: 'Design', __typename: 'Design',
id: -1, id: -_.uniqueId(),
image: '', image: '',
name: file.name, filename: file.name,
commentsCount: 0,
updatedAt: new Date().toString(),
})); }));
this.isSaving = true; this.isSaving = true;
return this.$apollo return this.$apollo
.mutate({ .mutate({
mutation: uploadDesignQuery, mutation: uploadDesignMutation,
variables: { variables: {
files, files,
projectPath: this.projectPath,
iid: this.issueIid,
}, },
// update: (store, { data: { uploadDesign } }) => { update: (store, { data: { designManagementUpload } }) => {
// const data = store.readQuery({ query: allDesignsQuery }); const data = store.readQuery({
// console.log(data, uploadDesign); query: allDesignsQuery,
variables: { fullPath: this.projectPath, iid: this.issueIid },
});
const newDesigns = data.project.issue.designs.designs.edges.reduce((acc, design) => {
if (!acc.find(d => d.filename === design.node.filename)) {
acc.push(design.node);
}
// data.designs.unshift(...uploadDesign); return acc;
// store.writeQuery({ query: allDesignsQuery, data }); }, designManagementUpload.designs);
// }, const newQueryData = {
project: {
__typename: 'Project',
issue: {
__typename: 'Issue',
designs: {
__typename: 'DesignCollection',
designs: {
__typename: 'DesignConnection',
edges: newDesigns.map(design => ({
__typename: 'DesignEdge',
node: design,
})),
},
},
},
},
};
store.writeQuery({
query: allDesignsQuery,
variables: { fullPath: this.projectPath, iid: this.issueIid },
data: newQueryData,
});
},
optimisticResponse: { optimisticResponse: {
__typename: 'Mutation', __typename: 'Mutation',
uploadDesign: optimisticResponse, designManagementUpload: {
__typename: 'DesignManagementUploadPayload',
designs: optimisticResponse,
},
}, },
}) })
.then(() => { .then(() => {
......
query allDesigns { #import "./designListFragment.graphql"
designs @client {
id query allDesigns($fullPath: ID!, $iid: ID!) {
image project(fullPath: $fullPath) {
name issue(iid: $iid) {
updatedAt designs {
commentsCount designs {
edges {
node {
...DesignListItem
}
}
}
}
}
} }
} }
query getDesign($id: ID!) { query getDesign($id: ID!) {
design(id: $id) @client { design(id: $id) @client {
image image
name filename
updatedAt
updatedBy {
name
}
} }
} }
mutation addDesigns($files: [Upload!]!) { #import "./designListFragment.graphql"
uploadDesign(files: $files) @client {
id mutation uploadDesign($files: [Upload!]!, $projectPath: ID!, $iid: ID!) {
image designManagementUpload(input: { projectPath: $projectPath, iid: $iid, files: $files }) {
name designs {
updatedAt ...DesignListItem
commentsCount }
} }
} }
...@@ -39,7 +39,7 @@ const router = new VueRouter({ ...@@ -39,7 +39,7 @@ const router = new VueRouter({
from, from,
next, next,
) { ) {
if (id !== -1) next(); if (id > 0) next();
}, },
props: ({ params: { id } }) => ({ id: parseInt(id, 10) }), props: ({ params: { id } }) => ({ id: parseInt(id, 10) }),
}, },
......
...@@ -5,6 +5,9 @@ describe 'User paginates issue designs', :js do ...@@ -5,6 +5,9 @@ describe 'User paginates issue designs', :js do
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
before do before do
create(:design, issue: issue, filename: 'world.png')
create(:design, issue: issue, filename: 'dk.png')
stub_licensed_features(design_management: true) stub_licensed_features(design_management: true)
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
...@@ -20,7 +23,7 @@ describe 'User paginates issue designs', :js do ...@@ -20,7 +23,7 @@ describe 'User paginates issue designs', :js do
expect(find('.js-previous-design')[:disabled]).to eq('true') expect(find('.js-previous-design')[:disabled]).to eq('true')
page.within(find('.js-design-header')) do page.within(find('.js-design-header')) do
expect(page).to have_content('1 of 5') expect(page).to have_content('1 of 2')
end end
find('.js-next-design').click find('.js-next-design').click
...@@ -28,7 +31,7 @@ describe 'User paginates issue designs', :js do ...@@ -28,7 +31,7 @@ describe 'User paginates issue designs', :js do
expect(find('.js-previous-design')[:disabled]).not_to eq('true') expect(find('.js-previous-design')[:disabled]).not_to eq('true')
page.within(find('.js-design-header')) do page.within(find('.js-design-header')) do
expect(page).to have_content('2 of 5') expect(page).to have_content('2 of 2')
end end
end end
end end
...@@ -23,11 +23,10 @@ describe 'User uploads new design', :js do ...@@ -23,11 +23,10 @@ describe 'User uploads new design', :js do
it 'uploads design' do it 'uploads design' do
attach_file(:design_file, logo_fixture, make_visible: true) attach_file(:design_file, logo_fixture, make_visible: true)
expect(page).to have_selector('.js-design-list-item', count: 6) expect(page).to have_selector('.js-design-list-item', count: 1)
within first('#designs-tab .card') do within first('#designs-tab .card') do
expect(page).to have_content('dk.png') expect(page).to have_content('dk.png')
expect(page).to have_content('Updated just now')
end end
end end
end end
......
...@@ -5,6 +5,8 @@ describe 'User views issue designs', :js do ...@@ -5,6 +5,8 @@ describe 'User views issue designs', :js do
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
before do before do
create(:design, issue: issue, filename: 'world.png')
stub_licensed_features(design_management: true) stub_licensed_features(design_management: true)
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
...@@ -18,8 +20,7 @@ describe 'User views issue designs', :js do ...@@ -18,8 +20,7 @@ describe 'User views issue designs', :js do
find('.js-design-list-item', match: :first).click find('.js-design-list-item', match: :first).click
page.within(find('.js-design-header')) do page.within(find('.js-design-header')) do
expect(page).to have_content('test.jpg') expect(page).to have_content('world.png')
expect(page).to have_content('Test Name')
end end
expect(page).to have_selector('.js-design-image') expect(page).to have_selector('.js-design-image')
......
...@@ -5,6 +5,8 @@ describe 'User views issue designs', :js do ...@@ -5,6 +5,8 @@ describe 'User views issue designs', :js do
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
before do before do
create(:design, issue: issue, filename: 'world.png')
stub_licensed_features(design_management: true) stub_licensed_features(design_management: true)
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
...@@ -15,6 +17,6 @@ describe 'User views issue designs', :js do ...@@ -15,6 +17,6 @@ describe 'User views issue designs', :js do
end end
it 'fetches list of designs' do it 'fetches list of designs' do
expect(page).to have_selector('.js-design-list-item', count: 5) expect(page).to have_selector('.js-design-list-item', count: 1)
end end
end end
...@@ -3,7 +3,7 @@ import List from 'ee/design_management/components/list/index.vue'; ...@@ -3,7 +3,7 @@ import List from 'ee/design_management/components/list/index.vue';
const createMockDesign = id => ({ const createMockDesign = id => ({
id, id,
name: 'test', filename: 'test',
image: 'test', image: 'test',
commentsCount: 2, commentsCount: 2,
updatedAt: '01-01-2019', updatedAt: '01-01-2019',
......
...@@ -7,7 +7,6 @@ exports[`Design management design index page renders design index 1`] = ` ...@@ -7,7 +7,6 @@ exports[`Design management design index page renders design index 1`] = `
<toolbar-stub <toolbar-stub
id="1" id="1"
name="test.jpg" name="test.jpg"
updatedat=""
updatedby="[object Object]" updatedby="[object Object]"
/> />
...@@ -26,7 +25,6 @@ exports[`Design management design index page sets loading state 1`] = ` ...@@ -26,7 +25,6 @@ exports[`Design management design index page sets loading state 1`] = `
id="1" id="1"
isloading="true" isloading="true"
name="" name=""
updatedat=""
updatedby="[object Object]" updatedby="[object Object]"
/> />
......
...@@ -30,7 +30,7 @@ describe('Design management design index page', () => { ...@@ -30,7 +30,7 @@ describe('Design management design index page', () => {
vm.setData({ vm.setData({
design: { design: {
name: 'test.jpg', filename: 'test.jpg',
image: 'test.jpg', image: 'test.jpg',
updatedAt: '01-01-2019', updatedAt: '01-01-2019',
updatedBy: { updatedBy: {
......
...@@ -95,19 +95,23 @@ describe('Design management index page', () => { ...@@ -95,19 +95,23 @@ describe('Design management index page', () => {
mutation: uploadDesignQuery, mutation: uploadDesignQuery,
variables: { variables: {
files: [{ name: 'test' }], files: [{ name: 'test' }],
projectPath: '',
iid: null,
}, },
update: expect.anything(),
optimisticResponse: { optimisticResponse: {
__typename: 'Mutation', __typename: 'Mutation',
uploadDesign: [ designManagementUpload: {
{ __typename: 'DesignManagementUploadPayload',
__typename: 'Design', designs: [
id: -1, {
image: '', __typename: 'Design',
name: 'test', id: expect.anything(),
commentsCount: 0, image: '',
updatedAt: expect.any(String), filename: 'test',
}, },
], ],
},
}, },
}); });
}); });
......
...@@ -4031,6 +4031,9 @@ msgstr "" ...@@ -4031,6 +4031,9 @@ msgstr ""
msgid "DesignManagement|Go to previous design" msgid "DesignManagement|Go to previous design"
msgstr "" msgstr ""
msgid "DesignManagement|The maximum number of designs allowed to be uploaded is %{upload_limit}. Please try again."
msgstr ""
msgid "DesignManagement|The one place for your designs" msgid "DesignManagement|The one place for your designs"
msgstr "" msgstr ""
......
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