removed categories from posts

This commit is contained in:
Moriz Wahl 2021-01-15 00:36:55 +01:00
parent 2b8996a898
commit cbf50014ed
8 changed files with 27 additions and 68 deletions

View File

@ -138,8 +138,6 @@ export default {
Mutation: {
CreateComment: validateCreateComment,
UpdateComment: validateUpdateComment,
CreatePost: validatePost,
UpdatePost: validateUpdatePost,
UpdateUser: validateUpdateUser,
fileReport: validateReport,
review: validateReview,

View File

@ -240,7 +240,7 @@ describe('validateCreateComment', () => {
describe('categories', () => {
describe('null', () => {
it('throws UserInputError', async () => {
it.skip('throws UserInputError', async () => {
createPostVariables = { ...createPostVariables, categoryIds: null }
await expect(
mutate({ mutation: createPostMutation, variables: createPostVariables }),
@ -256,7 +256,7 @@ describe('validateCreateComment', () => {
})
describe('empty', () => {
it('throws UserInputError', async () => {
it.skip('throws UserInputError', async () => {
createPostVariables = { ...createPostVariables, categoryIds: [] }
await expect(
mutate({ mutation: createPostMutation, variables: createPostVariables }),
@ -272,7 +272,7 @@ describe('validateCreateComment', () => {
})
describe('more than 3 categoryIds', () => {
it('throws UserInputError', async () => {
it.skip('throws UserInputError', async () => {
createPostVariables = {
...createPostVariables,
categoryIds: ['cat9', 'cat27', 'cat15', 'cat4'],
@ -313,7 +313,7 @@ describe('validateCreateComment', () => {
}
})
it('requires at least one category for successful update', async () => {
it.skip('requires at least one category for successful update', async () => {
await expect(
mutate({ mutation: updatePostMutation, variables: updatePostVariables }),
).resolves.toMatchObject({

View File

@ -76,7 +76,6 @@ export default {
},
Mutation: {
CreatePost: async (_parent, params, context, _resolveInfo) => {
const { categoryIds } = params
const { image: imageInput } = params
delete params.categoryIds
delete params.image
@ -92,13 +91,9 @@ export default {
WITH post
MATCH (author:User {id: $userId})
MERGE (post)<-[:WROTE]-(author)
WITH post
UNWIND $categoryIds AS categoryId
MATCH (category:Category {id: categoryId})
MERGE (post)-[:CATEGORIZED]->(category)
RETURN post {.*}
`,
{ userId: context.user.id, categoryIds, params },
{ userId: context.user.id, params },
)
const [post] = createPostTransactionResponse.records.map((record) => record.get('post'))
if (imageInput) {

View File

@ -136,7 +136,7 @@ type Post {
"""
)
tags: [Tag]! @relation(name: "TAGGED", direction: "OUT")
categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT")
categories: [Category] @relation(name: "CATEGORIZED", direction: "OUT")
comments: [Comment]! @relation(name: "COMMENTS", direction: "IN")
commentsCount: Int!

View File

@ -104,7 +104,7 @@ type User {
shouted: [Post]! @relation(name: "SHOUTED", direction: "OUT")
shoutedCount: Int! @cypher(statement: "MATCH (this)-[:SHOUTED]->(r:Post) WHERE NOT r.deleted = true AND NOT r.disabled = true RETURN COUNT(DISTINCT r)")
categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT")
categories: [Category] @relation(name: "CATEGORIZED", direction: "OUT")
badges: [Badge]! @relation(name: "REWARDED", direction: "IN")
badgesCount: Int! @cypher(statement: "MATCH (this)<-[:REWARDED]-(r:Badge) RETURN COUNT(r)")

View File

@ -17,6 +17,7 @@ config.stubs['client-only'] = '<span><slot /></span>'
config.stubs['nuxt-link'] = '<span><slot /></span>'
config.stubs['v-popover'] = '<span><slot /></span>'
/*
const categories = [
{
id: 'cat3',
@ -44,6 +45,7 @@ const categories = [
icon: 'tree',
},
]
*/
describe('ContributionForm.vue', () => {
let wrapper,
@ -136,7 +138,7 @@ describe('ContributionForm.vue', () => {
describe('CreatePost', () => {
describe('invalid form submission', () => {
beforeEach(async () => {
wrapper.find(CategoriesSelect).setData({ categories })
// wrapper.find(CategoriesSelect).setData({ categories })
postTitleInput = wrapper.find('.ds-input')
postTitleInput.setValue(postTitle)
await wrapper.vm.updateEditorContent(postContent)
@ -144,10 +146,10 @@ describe('ContributionForm.vue', () => {
.findAll('li')
.filter((language) => language.text() === 'English')
englishLanguage.trigger('click')
dataPrivacyButton = await wrapper
/* dataPrivacyButton = await wrapper
.find(CategoriesSelect)
.find('[data-test="category-buttons-cat12"]')
dataPrivacyButton.trigger('click')
.find('[data-test="category-buttons-cat12"]')
dataPrivacyButton.trigger('click') */
})
it('title cannot be empty', async () => {
@ -174,7 +176,7 @@ describe('ContributionForm.vue', () => {
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
})
it('has at least one category', async () => {
it.skip('has at least one category', async () => {
dataPrivacyButton = await wrapper
.find(CategoriesSelect)
.find('[data-test="category-buttons-cat12"]')
@ -183,7 +185,7 @@ describe('ContributionForm.vue', () => {
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
})
it('has no more than three categories', async () => {
it.skip('has no more than three categories', async () => {
wrapper.vm.formData.categoryIds = ['cat4', 'cat9', 'cat15', 'cat27']
await Vue.nextTick()
wrapper.find('form').trigger('submit')
@ -200,23 +202,23 @@ describe('ContributionForm.vue', () => {
content: postContent,
language: 'en',
id: null,
categoryIds: ['cat12'],
// categoryIds: ['cat12'],
image: null,
},
}
postTitleInput = wrapper.find('.ds-input')
postTitleInput.setValue(postTitle)
await wrapper.vm.updateEditorContent(postContent)
wrapper.find(CategoriesSelect).setData({ categories })
// wrapper.find(CategoriesSelect).setData({ categories })
englishLanguage = wrapper
.findAll('li')
.filter((language) => language.text() === 'English')
englishLanguage.trigger('click')
await Vue.nextTick()
dataPrivacyButton = await wrapper
/* dataPrivacyButton = await wrapper
.find(CategoriesSelect)
.find('[data-test="category-buttons-cat12"]')
dataPrivacyButton.trigger('click')
dataPrivacyButton.trigger('click') */
await Vue.nextTick()
})
@ -293,16 +295,16 @@ describe('ContributionForm.vue', () => {
postTitleInput.setValue(postTitle)
await wrapper.vm.updateEditorContent(postContent)
categoryIds = ['cat12']
wrapper.find(CategoriesSelect).setData({ categories })
// wrapper.find(CategoriesSelect).setData({ categories })
englishLanguage = wrapper
.findAll('li')
.filter((language) => language.text() === 'English')
englishLanguage.trigger('click')
await Vue.nextTick()
dataPrivacyButton = await wrapper
/* dataPrivacyButton = await wrapper
.find(CategoriesSelect)
.find('[data-test="category-buttons-cat12"]')
dataPrivacyButton.trigger('click')
dataPrivacyButton.trigger('click') */
await Vue.nextTick()
})
@ -365,7 +367,7 @@ describe('ContributionForm.vue', () => {
content: propsData.contribution.content,
language: propsData.contribution.language,
id: propsData.contribution.id,
categoryIds: ['cat12'],
// categoryIds: ['cat12'],
image: {
sensitive: false,
},
@ -380,9 +382,9 @@ describe('ContributionForm.vue', () => {
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
})
it('supports updating categories', async () => {
it.skip('supports updating categories', async () => {
expectedParams.variables.categoryIds.push('cat3')
wrapper.find(CategoriesSelect).setData({ categories })
// wrapper.find(CategoriesSelect).setData({ categories })
await Vue.nextTick()
const healthWellbeingButton = await wrapper
.find(CategoriesSelect)

View File

@ -50,11 +50,6 @@
{{ contentLength }}
<base-icon v-if="errors && errors.content" name="warning" />
</ds-chip>
<categories-select model="categoryIds" :existingCategoryIds="formData.categoryIds" />
<ds-chip size="base" :color="errors && errors.categoryIds && 'danger'">
{{ formData.categoryIds.length }} / 3
<base-icon v-if="errors && errors.categoryIds" name="warning" />
</ds-chip>
<ds-select
model="language"
icon="globe"
@ -86,14 +81,12 @@ import { mapGetters } from 'vuex'
import HcEditor from '~/components/Editor/Editor'
import locales from '~/locales'
import PostMutations from '~/graphql/PostMutations.js'
import CategoriesSelect from '~/components/CategoriesSelect/CategoriesSelect'
import ImageUploader from '~/components/ImageUploader/ImageUploader'
import links from '~/constants/links.js'
export default {
components: {
HcEditor,
CategoriesSelect,
ImageUploader,
},
props: {
@ -103,7 +96,7 @@ export default {
},
},
data() {
const { title, content, image, language, categories } = this.contribution
const { title, content, image, language } = this.contribution
const languageOptions = orderBy(locales, 'name').map((locale) => {
return { label: locale.name, value: locale.code }
@ -119,21 +112,10 @@ export default {
imageAspectRatio,
imageBlurred,
language: languageOptions.find((option) => option.value === language) || null,
categoryIds: categories ? categories.map((category) => category.id) : [],
},
formSchema: {
title: { required: true, min: 3, max: 100 },
content: { required: true },
categoryIds: {
type: 'array',
required: true,
validator: (_, value = []) => {
if (value.length === 0 || value.length > 3) {
return [new Error(this.$t('common.validations.categories'))]
}
return []
},
},
language: { required: true },
imageBlurred: { required: false },
},
@ -155,7 +137,7 @@ export default {
methods: {
submit() {
let image = null
const { title, content, categoryIds } = this.formData
const { title, content } = this.formData
if (this.formData.image) {
image = {
sensitive: this.formData.imageBlurred,
@ -172,7 +154,6 @@ export default {
variables: {
title,
content,
categoryIds,
id: this.contribution.id || null,
language: this.formData.language.value,
image,

View File

@ -46,21 +46,6 @@
<content-viewer class="content hyphenate-text" :content="post.content" />
<!-- eslint-enable vue/no-v-html -->
<ds-space margin="xx-large" />
<!-- Categories -->
<div class="categories">
<ds-space margin="xx-small" />
<hc-category
v-for="category in post.categories"
:key="category.id"
:icon="category.icon"
:name="$t(`contribution.category.name.${category.slug}`)"
/>
<!-- Post language -->
<ds-tag v-if="post.language" class="category-tag language">
<base-icon name="globe" />
{{ post.language.toUpperCase() }}
</ds-tag>
</div>
<ds-space margin-bottom="small" />
<!-- Tags -->
<div v-if="post.tags && post.tags.length" class="tags">
@ -110,7 +95,6 @@
<script>
import ContentViewer from '~/components/Editor/ContentViewer'
import HcCategory from '~/components/Category'
import HcHashtag from '~/components/Hashtag/Hashtag'
import ContentMenu from '~/components/ContentMenu/ContentMenu'
import UserTeaser from '~/components/UserTeaser/UserTeaser'
@ -134,7 +118,6 @@ export default {
mode: 'out-in',
},
components: {
HcCategory,
HcHashtag,
UserTeaser,
HcShoutButton,