mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Merge pull request #6244 from Ocelot-Social-Community/5441-wrench-refactor-groupform-select-make-a-component
refactor(webapp): make action radius select in group form a reusable component
This commit is contained in:
commit
c9f2192ebe
@ -37,8 +37,6 @@
|
|||||||
<ds-text class="select-label">
|
<ds-text class="select-label">
|
||||||
{{ $t('group.type') }}
|
{{ $t('group.type') }}
|
||||||
</ds-text>
|
</ds-text>
|
||||||
<!-- TODO: change it has to be implemented later -->
|
|
||||||
<!-- TODO: move 'ds-select' from style guide to main code and implement missing translation etc. functionality -->
|
|
||||||
<select
|
<select
|
||||||
class="select ds-input appearance--auto"
|
class="select ds-input appearance--auto"
|
||||||
name="groupType"
|
name="groupType"
|
||||||
@ -94,21 +92,10 @@
|
|||||||
<ds-text class="select-label">
|
<ds-text class="select-label">
|
||||||
{{ $t('group.actionRadius') }}
|
{{ $t('group.actionRadius') }}
|
||||||
</ds-text>
|
</ds-text>
|
||||||
<!-- TODO: move 'ds-select' from styleguide to main code and implement missing translation etc. functionality -->
|
<action-radius-select
|
||||||
<select
|
v-model="formData.actionRadius"
|
||||||
class="select ds-input appearance--auto"
|
@change.native="changeActionRadius($event)"
|
||||||
name="actionRadius"
|
/>
|
||||||
:value="formData.actionRadius"
|
|
||||||
@change="changeActionRadius($event)"
|
|
||||||
>
|
|
||||||
<option
|
|
||||||
v-for="actionRadius in actionRadiusOptions"
|
|
||||||
:key="actionRadius"
|
|
||||||
:value="actionRadius"
|
|
||||||
>
|
|
||||||
{{ $t(`group.actionRadii.${actionRadius}`) }}
|
|
||||||
</option>
|
|
||||||
</select>
|
|
||||||
<ds-chip
|
<ds-chip
|
||||||
size="base"
|
size="base"
|
||||||
:color="
|
:color="
|
||||||
@ -123,6 +110,7 @@
|
|||||||
</ds-chip>
|
</ds-chip>
|
||||||
|
|
||||||
<!-- location -->
|
<!-- location -->
|
||||||
|
<!-- TODO: move 'ds-select' from styleguide to main code and implement missing translation etc. functionality -->
|
||||||
<ds-select
|
<ds-select
|
||||||
id="city"
|
id="city"
|
||||||
:label="$t('settings.data.labelCity') + locationNameLabelAddOnOldName"
|
:label="$t('settings.data.labelCity') + locationNameLabelAddOnOldName"
|
||||||
@ -187,6 +175,7 @@ import {
|
|||||||
DESCRIPTION_WITHOUT_HTML_LENGTH_MIN,
|
DESCRIPTION_WITHOUT_HTML_LENGTH_MIN,
|
||||||
} from '~/constants/groups.js'
|
} from '~/constants/groups.js'
|
||||||
import Editor from '~/components/Editor/Editor'
|
import Editor from '~/components/Editor/Editor'
|
||||||
|
import ActionRadiusSelect from '~/components/Select/ActionRadiusSelect'
|
||||||
import { queryLocations } from '~/graphql/location'
|
import { queryLocations } from '~/graphql/location'
|
||||||
|
|
||||||
let timeout
|
let timeout
|
||||||
@ -196,6 +185,7 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
CategoriesSelect,
|
CategoriesSelect,
|
||||||
Editor,
|
Editor,
|
||||||
|
ActionRadiusSelect,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
update: {
|
update: {
|
||||||
@ -216,7 +206,6 @@ export default {
|
|||||||
categoriesActive: this.$env.CATEGORIES_ACTIVE,
|
categoriesActive: this.$env.CATEGORIES_ACTIVE,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
groupTypeOptions: ['public', 'closed', 'hidden'],
|
groupTypeOptions: ['public', 'closed', 'hidden'],
|
||||||
actionRadiusOptions: ['regional', 'national', 'continental', 'global'],
|
|
||||||
loadingGeo: false,
|
loadingGeo: false,
|
||||||
cities: [],
|
cities: [],
|
||||||
formData: {
|
formData: {
|
||||||
@ -327,10 +316,10 @@ export default {
|
|||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
changeGroupType(event) {
|
changeGroupType(event) {
|
||||||
this.formData.groupType = event.target.value
|
this.$refs.groupForm.update('groupType', event.target.value)
|
||||||
},
|
},
|
||||||
changeActionRadius(event) {
|
changeActionRadius(event) {
|
||||||
this.formData.actionRadius = event.target.value
|
this.$refs.groupForm.update('actionRadius', event.target.value)
|
||||||
},
|
},
|
||||||
updateEditorDescription(value) {
|
updateEditorDescription(value) {
|
||||||
this.$refs.groupForm.update('description', value)
|
this.$refs.groupForm.update('description', value)
|
||||||
|
|||||||
37
webapp/components/Select/ActionRadiusSelect.spec.js
Normal file
37
webapp/components/Select/ActionRadiusSelect.spec.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { shallowMount } from '@vue/test-utils'
|
||||||
|
import ActionRadiusSelect from './ActionRadiusSelect'
|
||||||
|
|
||||||
|
const localVue = global.localVue
|
||||||
|
const propsData = { value: 'regional' }
|
||||||
|
|
||||||
|
describe('ActionRadiusSelect.', () => {
|
||||||
|
let wrapper
|
||||||
|
let mocks
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mocks = {
|
||||||
|
$t: jest.fn(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('mount', () => {
|
||||||
|
const Wrapper = () => {
|
||||||
|
return shallowMount(ActionRadiusSelect, { propsData, mocks, localVue })
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = Wrapper()
|
||||||
|
})
|
||||||
|
it('renders the select', () => {
|
||||||
|
expect(wrapper.findComponent(ActionRadiusSelect).exists()).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('when an option is selected', () => {
|
||||||
|
it('emits a change event with the new value', () => {
|
||||||
|
const select = wrapper.find('select')
|
||||||
|
select.trigger('change')
|
||||||
|
expect(wrapper.emitted().change[0]).toEqual(['regional'])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
33
webapp/components/Select/ActionRadiusSelect.vue
Normal file
33
webapp/components/Select/ActionRadiusSelect.vue
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<template>
|
||||||
|
<select
|
||||||
|
class="select ds-input appearance--auto"
|
||||||
|
name="actionRadius"
|
||||||
|
:value="value"
|
||||||
|
@change="onActionRadiusChange"
|
||||||
|
>
|
||||||
|
<option v-for="actionRadius in actionRadiusOptions" :key="actionRadius" :value="actionRadius">
|
||||||
|
{{ $t(`group.actionRadii.${actionRadius}`) }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'ActionRadiusSelect',
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
actionRadiusOptions: ['regional', 'national', 'continental', 'global'],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onActionRadiusChange(event) {
|
||||||
|
this.$emit('change', event.target.value)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
Loading…
x
Reference in New Issue
Block a user