From 863060149ad0277dfa1a3e83f947f98f69ce8513 Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Mon, 17 Jun 2019 12:41:02 -0300 Subject: [PATCH 001/161] Add UI for adding tags to a contribution --- .../ContributionForm/ContributionForm.spec.js | 35 +++++++++++++++++-- webapp/components/ContributionForm/index.vue | 25 +++++++++++++ webapp/locales/de.json | 4 ++- webapp/locales/en.json | 4 ++- 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/webapp/components/ContributionForm/ContributionForm.spec.js b/webapp/components/ContributionForm/ContributionForm.spec.js index f7f306fc3..14877c395 100644 --- a/webapp/components/ContributionForm/ContributionForm.spec.js +++ b/webapp/components/ContributionForm/ContributionForm.spec.js @@ -15,6 +15,8 @@ describe('ContributionForm.vue', () => { let deutschOption let cancelBtn let mocks + let tagsInput + let chipText const postTitle = 'this is a title for a post' const postContent = 'this is a post' const computed = { locale: () => 'English' } @@ -79,10 +81,16 @@ describe('ContributionForm.vue', () => { }) describe('valid form submission', () => { - expectedParams = { - variables: { title: postTitle, content: postContent, language: 'en', id: null }, - } beforeEach(async () => { + expectedParams = { + variables: { + title: postTitle, + content: postContent, + language: 'en', + id: null, + tags: [], + }, + } postTitleInput = wrapper.find('.ds-input') postTitleInput.setValue('this is a title for a post') wrapper.vm.updateEditorContent('this is a post') @@ -105,6 +113,27 @@ describe('ContributionForm.vue', () => { expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams)) }) + it('supports adding tags', async () => { + expectedParams.variables.tags = ['Frieden'] + tagsInput = wrapper.findAll('input').at(1) + tagsInput.setValue('Frieden') + tagsInput.trigger('keyup.enter') + await wrapper.find('form').trigger('submit') + expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams)) + }) + + it('displays tags if they exist', () => { + expectedParams.variables.tags = ['Frieden'] + tagsInput = wrapper.findAll('input').at(1) + tagsInput.setValue('Frieden') + tagsInput.trigger('keyup.enter') + chipText = wrapper + .findAll('span.ds-chip') + .at(0) + .text() + expect(chipText).toEqual('Frieden') + }) + it("pushes the user to the post's page", async () => { expect(mocks.$router.push).toHaveBeenCalledTimes(1) }) diff --git a/webapp/components/ContributionForm/index.vue b/webapp/components/ContributionForm/index.vue index 62c3650c8..8a1283902 100644 --- a/webapp/components/ContributionForm/index.vue +++ b/webapp/components/ContributionForm/index.vue @@ -7,6 +7,17 @@ + + + {{ tag }} + @@ -20,6 +31,7 @@ /> +
{ @@ -144,6 +159,16 @@ export default { this.form.languageOptions.push({ label: locale.name, value: locale.code }) }) }, + removeTag(index) { + this.form.tags.splice(index, 1) + }, + handleInput(e) { + this.form.tagValue = e.target ? e.target.value.trim() : '' + }, + addTag(tag) { + this.form.tags.push(tag) + this.form.tagValue = '' + }, }, apollo: { User: { diff --git a/webapp/locales/de.json b/webapp/locales/de.json index efe05a472..7eef78b76 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -304,6 +304,8 @@ }, "contribution": { "success": "Gespeichert!", - "languageSelectLabel": "Sprache" + "languageSelectLabel": "Sprache", + "tagsInputLabel": "Tags", + "tagsInputPlaceholder": "Hinzufügen ein Tag" } } diff --git a/webapp/locales/en.json b/webapp/locales/en.json index 4fdcadedb..597e4f540 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -303,6 +303,8 @@ }, "contribution": { "success": "Saved!", - "languageSelectLabel": "Language" + "languageSelectLabel": "Language", + "tagsInputLabel": "Tags", + "tagsInputPlaceholder": "Add a tag" } } From 4e780f52dc35f731a2d688c2bd7835129d8f9244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Mon, 17 Jun 2019 18:44:17 +0200 Subject: [PATCH 002/161] Copy and refactoring Mentions to Tags, Started --- webapp/components/ContributionForm/index.vue | 35 ++++- webapp/components/Editor/index.vue | 138 +++++++++++++++---- webapp/components/Editor/nodes/Mention.js | 6 +- webapp/components/Editor/nodes/Tag.js | 39 ++++++ 4 files changed, 185 insertions(+), 33 deletions(-) create mode 100644 webapp/components/Editor/nodes/Tag.js diff --git a/webapp/components/ContributionForm/index.vue b/webapp/components/ContributionForm/index.vue index 62c3650c8..3126fdc46 100644 --- a/webapp/components/ContributionForm/index.vue +++ b/webapp/components/ContributionForm/index.vue @@ -4,7 +4,12 @@ - + @@ -75,6 +80,7 @@ export default { disabled: false, slug: null, users: [], + tags: [], } }, watch: { @@ -148,17 +154,34 @@ export default { apollo: { User: { query() { - return gql(`{ - User(orderBy: slug_asc) { - id - slug + return gql` + { + User(orderBy: slug_asc) { + id + slug + } } - }`) + ` }, result(result) { this.users = result.data.User }, }, + Tag: { + query() { + return gql` + { + Tag(orderBy: name_asc) { + id + name + } + } + ` + }, + result(result) { + this.tags = result.data.Tag + }, + }, }, } diff --git a/webapp/components/Editor/index.vue b/webapp/components/Editor/index.vue index 0690b15bd..6307ff5ee 100644 --- a/webapp/components/Editor/index.vue +++ b/webapp/components/Editor/index.vue @@ -1,20 +1,30 @@