Fix processing nested data for dispatch setting

This commit is contained in:
Angelina Filippova 2020-01-03 13:31:07 +07:00
parent 1814e67adb
commit 1c7a7cc906
4 changed files with 17 additions and 13 deletions

View file

@ -134,14 +134,14 @@ export const partialUpdate = (group, key) => {
export const processNested = (valueForState, valueForUpdatedSettings, group, parentKey, parents, settings, updatedSettings) => { export const processNested = (valueForState, valueForUpdatedSettings, group, parentKey, parents, settings, updatedSettings) => {
const [{ key, type }, ...otherParents] = parents const [{ key, type }, ...otherParents] = parents
const path = [group, parentKey, ...parents.reverse().map(parent => parent.key)] const path = [group, parentKey, ...parents.reverse().map(parent => parent.key).slice(0, -1)]
const updatedValueForState = valueExists(settings, path) const updatedValueForState = valueExists(settings, path)
? { ...getCurrentValue(settings[group][parentKey], parents.map(el => el.key).slice(0, -1)), ? { ...getCurrentValue(settings[group][parentKey], parents.map(el => el.key).slice(0, -1)),
...{ [key]: valueForState }} ...{ [key]: valueForState }}
: { [key]: valueForState } : { [key]: valueForState }
const updatedValueForUpdatedSettings = valueExists(updatedSettings, path) const updatedValueForUpdatedSettings = valueExists(updatedSettings, path)
? { ...getCurrentValue(settings[group][parentKey], parents.map(el => el.key).slice(0, -1)), ? { ...getCurrentValue(updatedSettings[group][parentKey], parents.map(el => el.key).slice(0, -1))[1],
...{ [key]: [type, valueForUpdatedSettings] }} ...{ [key]: [type, valueForUpdatedSettings] }}
: { [key]: [type, valueForUpdatedSettings] } : { [key]: [type, valueForUpdatedSettings] }
@ -197,8 +197,10 @@ const wrapValues = (settings, currentState) => {
return { 'tuple': [setting, wrapValues(value, currentState)] } return { 'tuple': [setting, wrapValues(value, currentState)] }
} else if (type === 'atom' && value.length > 0) { } else if (type === 'atom' && value.length > 0) {
return { 'tuple': [setting, `:${value}`] } return { 'tuple': [setting, `:${value}`] }
} else if (type.includes('tuple') && (type.includes('string') || type.includes('list') || type.includes('atom'))) { } else if (type.includes('tuple') && (type.includes('string') || type.includes('atom'))) {
return { 'tuple': [setting, { 'tuple': value }] } return { 'tuple': [setting, { 'tuple': value }] }
} else if (type.includes('tuple') && type.includes('list')) {
return { 'tuple': [setting, value] }
} else if (type === 'map') { } else if (type === 'map') {
const mapValue = Object.keys(value).reduce((acc, key) => { const mapValue = Object.keys(value).reduce((acc, key) => {
acc[key] = setting === ':match_actor' ? value[key] : value[key][1] acc[key] = setting === ':match_actor' ? value[key] : value[key][1]

View file

@ -59,7 +59,7 @@
<div v-for="subSetting in setting.children" :key="subSetting.key"> <div v-for="subSetting in setting.children" :key="subSetting.key">
<inputs <inputs
:setting-group="settingGroup" :setting-group="settingGroup"
:setting-parent="[...settingParent, setting, subSetting]" :setting-parent="[...settingParent, subSetting]"
:setting="subSetting" :setting="subSetting"
:data="data[setting.key]" :data="data[setting.key]"
:custom-label-width="'100px'" :custom-label-width="'100px'"
@ -164,7 +164,7 @@ export default {
return this.data[this.setting.key] ? this.data[this.setting.key][0] : '' return this.data[this.setting.key] ? this.data[this.setting.key][0] : ''
}, },
set: function(value) { set: function(value) {
this.processNestedData([value], this.settingGroup.group, this.settingGroup.key, this.settingParent[0].key, this.settingParent[0].type) this.processNestedData([value], this.settingGroup.group, this.settingGroup.key, this.settingParent)
} }
}, },
inputValue() { inputValue() {

View file

@ -33,7 +33,7 @@
<div v-for="subSetting in setting.children" :key="subSetting.key"> <div v-for="subSetting in setting.children" :key="subSetting.key">
<inputs <inputs
:setting-group="settingGroup" :setting-group="settingGroup"
:setting-parent="[setting]" :setting-parent="[setting, subSetting]"
:setting="subSetting" :setting="subSetting"
:data="data[setting.key]" :data="data[setting.key]"
:nested="true"/> :nested="true"/>

View file

@ -47,6 +47,9 @@
<el-tab-pane :label="$t('settings.mailer')" lazy> <el-tab-pane :label="$t('settings.mailer')" lazy>
<mailer/> <mailer/>
</el-tab-pane> </el-tab-pane>
<!-- <el-tab-pane :label="$t('settings.mediaProxy')" lazy>
<media-proxy/>
</el-tab-pane> -->
<el-tab-pane :label="$t('settings.metadata')" lazy> <el-tab-pane :label="$t('settings.metadata')" lazy>
<metadata/> <metadata/>
</el-tab-pane> </el-tab-pane>
@ -59,18 +62,17 @@
<el-tab-pane :label="$t('settings.relays')" lazy> <el-tab-pane :label="$t('settings.relays')" lazy>
<relays/> <relays/>
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="$t('settings.webPush')" lazy>
<web-push/>
</el-tab-pane>
<el-tab-pane :label="$t('settings.other')" lazy> <el-tab-pane :label="$t('settings.other')" lazy>
<other/> <other/>
</el-tab-pane> </el-tab-pane>
<!-- <el-tab-pane :label="$t('settings.mediaProxy')" lazy> <!--
<media-proxy/>
</el-tab-pane>
<el-tab-pane :label="$t('settings.upload')" lazy> <el-tab-pane :label="$t('settings.upload')" lazy>
<upload/> <upload/>
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="$t('settings.webPush')" lazy> -->
<web-push/>
</el-tab-pane> -->
</el-tabs> </el-tabs>
</div> </div>
</template> </template>