Fix wrapping :icons setting and parsing tuples in settings with key :headers

This commit is contained in:
Angelina Filippova 2020-11-18 17:52:17 +03:00
parent 06fb9178b7
commit 27f11164d8
3 changed files with 45 additions and 4 deletions

View file

@ -66,7 +66,11 @@ export const parseTuples = (tuples, key) => {
return [...acc, { [mascot.tuple[0]]: { ...mascot.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}]
}, [])
} else if (Array.isArray(item.tuple[1]) &&
(item.tuple[0] === ':groups' || item.tuple[0] === ':replace' || item.tuple[0] === ':retries' || item.tuple[0] === ':headers' || item.tuple[0] === ':crontab')) {
(item.tuple[0] === ':groups' ||
item.tuple[0] === ':replace' ||
item.tuple[0] === ':retries' ||
(item.tuple[0] === ':headers' && key === 'Pleroma.Web.MediaProxy.Invalidation.Http') ||
item.tuple[0] === ':crontab')) {
if (item.tuple[0] === ':crontab') {
accum[item.tuple[0]] = item.tuple[1].reduce((acc, group) => {
return [...acc, { [group.tuple[1]]: { value: group.tuple[0], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}]
@ -245,7 +249,7 @@ const wrapValues = (settings, currentState) => {
return acc
}, {})
return { 'tuple': [setting, { ...currentState[setting], ...mapValue }] }
} else if (type.includes('map')) {
} else if (type.includes('map') && !type.includes('list')) {
const mapValue = Object.keys(value).reduce((acc, key) => {
acc[key] = value[key][1]
return acc

View file

@ -42,7 +42,8 @@
@change="update($event, settingGroup.group, settingGroup.key, settingParent, setting.key, setting.type, nested)"
/>
<el-input
v-else-if="setting.type === 'string' || (setting.type.includes('string') && setting.type.includes('atom'))"
v-else-if="setting.type === 'string' ||
(Array.isArray(setting.type) && setting.type.includes('string') && setting.type.includes('atom'))"
:value="inputValue"
:placeholder="setting.suggestions ? setting.suggestions[0] : null"
:data-search="setting.key || setting.group"
@ -358,7 +359,10 @@ export default {
)
},
renderSingleSelect(type) {
return !this.reducedSelects && (type === 'module' || (type.includes('atom') && type.includes('dropdown')))
return !this.reducedSelects && (
type === 'module' ||
(Array.isArray(type) && type.includes('atom') && type.includes('dropdown'))
)
},
senderInput({ key, type }) {
return Array.isArray(type) && type.includes('string') && type.includes('tuple') && key === ':sender'

View file

@ -340,6 +340,39 @@ describe('Wrap settings', () => {
expect(_.isEqual(result1, expectedResult1)).toBeTruthy()
expect(_.isEqual(result2, expectedResult2)).toBeTruthy()
})
it('wraps settings with type [`list`, `map`]', () => {
const settings = { ':manifest': { ':icons': [['map', 'list'], [
{ ':src': '/static/logo.png', ':type': 'image/png' },
{ ':src': '/static/icon.png', ':type': 'image/png' }
]]}}
const state = { ':pleroma': { ':manifest': {
':background_color': '#191b22',
':theme_color': '#282c37',
':icons': [
[
{ 'id': 'f21318c4', 'key': ':src', 'value': '/static/logo.png' },
{ 'id': 'f4b87549', 'key': ':type', 'value': 'image/png' }
], [
{ 'id': 'f31d351e', 'key': ':src', 'value': '/static/icon.png' },
{ 'id': 'f1455852', 'key': ':type', 'value': 'image/png' }
]
]
}}}
const result = wrapUpdatedSettings(':pleroma', settings, state)
const expectedResult = [{
group: ':pleroma',
key: ':manifest',
value: [{ tuple: [':icons', [
{ ':src': '/static/logo.png', ':type': 'image/png' },
{ ':src': '/static/icon.png', ':type': 'image/png' }
]]}]
}]
expect(_.isEqual(result, expectedResult)).toBeTruthy()
})
it('wraps IP setting', () => {
const settings = { ':gopher': { ':ip': ['tuple', '127.0.0.1']}}