Implement types ['map', 'string'] and ['map', ['list', 'string']]

This commit is contained in:
Angelina Filippova 2020-07-11 21:31:19 +03:00
parent 6577376642
commit 5ae214fbbe
4 changed files with 25 additions and 24 deletions

View file

@ -93,7 +93,7 @@ export const parseTuples = (tuples, key) => {
return [...acc, { [mascot.tuple[0]]: { ...mascot.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}] return [...acc, { [mascot.tuple[0]]: { ...mascot.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}]
}, []) }, [])
} else if (Array.isArray(item.tuple[1]) && } 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] === ':params' || item.tuple[0] === ':crontab')) { (item.tuple[0] === ':groups' || item.tuple[0] === ':replace' || item.tuple[0] === ':retries' || item.tuple[0] === ':headers' || item.tuple[0] === ':params' || item.tuple[0] === ':crontab' || item.tuple[0] === ':match_actor')) {
if (item.tuple[0] === ':crontab') { if (item.tuple[0] === ':crontab') {
accum[item.tuple[0]] = item.tuple[1].reduce((acc, group) => { 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)}` }}] return [...acc, { [group.tuple[1]]: { value: group.tuple[0], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}]
@ -103,10 +103,6 @@ export const parseTuples = (tuples, key) => {
return [...acc, { [group.tuple[0]]: { value: group.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}] return [...acc, { [group.tuple[0]]: { value: group.tuple[1], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}]
}, []) }, [])
} }
} else if (item.tuple[0] === ':match_actor') {
accum[item.tuple[0]] = Object.keys(item.tuple[1]).reduce((acc, regex) => {
return [...acc, { [regex]: { value: item.tuple[1][regex], id: `f${(~~(Math.random() * 1e8)).toString(16)}` }}]
}, [])
} else if (item.tuple[0] === ':icons') { } else if (item.tuple[0] === ':icons') {
accum[item.tuple[0]] = item.tuple[1].map(icon => { accum[item.tuple[0]] = item.tuple[1].map(icon => {
return Object.keys(icon).map(name => { return Object.keys(icon).map(name => {
@ -240,8 +236,10 @@ const wrapValues = (settings, currentState) => {
if ( if (
type === 'keyword' || type === 'keyword' ||
type.includes('keyword') || type.includes('keyword') ||
type.includes('tuple') && type.includes('list') || (type.includes('tuple') && type.includes('list')) ||
setting === ':replace' setting === ':replace' ||
(type.includes('map') && type.includes('string')) ||
type.includes('map') && type.findIndex(el => el.includes('list') && el.includes('string')) !== -1
) { ) {
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) {
@ -254,15 +252,10 @@ const wrapValues = (settings, currentState) => {
return { 'tuple': [value, setting] } return { 'tuple': [value, setting] }
} 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] = value[key][1]
return acc return acc
}, {}) }, {})
const mapCurrentState = setting === ':match_actor' return { 'tuple': [setting, { ...currentState[setting], ...mapValue }] }
? currentState[setting].reduce((acc, element) => {
return { ...acc, ...{ [Object.keys(element)[0]]: Object.values(element)[0].value }}
}, {})
: currentState[setting]
return { 'tuple': [setting, { ...mapCurrentState, ...mapValue }] }
} else if (setting === ':ip') { } else if (setting === ':ip') {
const ip = value.split('.').map(s => parseInt(s, 10)) const ip = value.split('.').map(s => parseInt(s, 10))
return { 'tuple': [setting, { 'tuple': ip }] } return { 'tuple': [setting, { 'tuple': ip }] }

View file

@ -281,11 +281,14 @@ export default {
}, },
methods: { methods: {
editableKeyword(key, type) { editableKeyword(key, type) {
return type === 'map' || return Array.isArray(type) && (
(Array.isArray(type) && type.includes('keyword') && type.includes('integer')) || (type.includes('map') && type.includes('string')) ||
(Array.isArray(type) && type.includes('keyword') && type.includes('string')) || (type.includes('map') && type.findIndex(el => el.includes('list') && el.includes('string')) !== -1) ||
(Array.isArray(type) && type.includes('tuple') && type.includes('list')) || (type.includes('keyword') && type.includes('integer')) ||
(Array.isArray(type) && type.includes('keyword') && type.findIndex(el => el.includes('list') && el.includes('string')) !== -1) (type.includes('keyword') && type.includes('string')) ||
(type.includes('tuple') && type.includes('list')) ||
(type.includes('keyword') && type.findIndex(el => el.includes('list') && el.includes('string')) !== -1)
)
}, },
getFormattedDescription(desc) { getFormattedDescription(desc) {
return marked(desc) return marked(desc)

View file

@ -121,7 +121,8 @@ export default {
compound({ type, key, children }) { compound({ type, key, children }) {
return type === 'keyword' || return type === 'keyword' ||
type === 'map' || type === 'map' ||
type.includes('keyword') type.includes('keyword') ||
type.includes('map')
}, },
divideSetting(key) { divideSetting(key) {
return [':sslopts', ':tlsopts', ':adapter', ':poll_limits', ':queues', ':styling', ':invalidation', ':multi_factor_authentication'].includes(key) return [':sslopts', ':tlsopts', ':adapter', ':poll_limits', ':queues', ':styling', ':invalidation', ':multi_factor_authentication'].includes(key)

View file

@ -25,7 +25,7 @@
</div> </div>
<el-button :size="isDesktop ? 'medium' : 'mini'" icon="el-icon-plus" circle @click="addRowToEditableKeyword"/> <el-button :size="isDesktop ? 'medium' : 'mini'" icon="el-icon-plus" circle @click="addRowToEditableKeyword"/>
</div> </div>
<div v-else :data-search="setting.key || setting.group"> <div v-else-if="editableKeywordWithSelect" :data-search="setting.key || setting.group">
<div v-for="element in data" :key="getId(element)" class="setting-input"> <div v-for="element in data" :key="getId(element)" class="setting-input">
<el-input :value="getKey(element)" placeholder="key" class="name-input" @input="parseEditableKeyword($event, 'key', element)"/> : <el-input :value="getKey(element)" placeholder="key" class="name-input" @input="parseEditableKeyword($event, 'key', element)"/> :
<el-select :value="getValue(element)" multiple filterable allow-create class="value-input" @change="parseEditableKeyword($event, 'value', element)"/> <el-select :value="getValue(element)" multiple filterable allow-create class="value-input" @change="parseEditableKeyword($event, 'value', element)"/>
@ -70,12 +70,16 @@ export default {
}, },
computed: { computed: {
editableKeywordWithInteger() { editableKeywordWithInteger() {
return Array.isArray(this.setting.type) && this.setting.type.includes('keyword') && this.setting.type.includes('integer') return this.setting.type.includes('keyword') && this.setting.type.includes('integer')
},
editableKeywordWithSelect() {
return this.setting.type.includes('map') && this.setting.type.findIndex(el => el.includes('list') && el.includes('string')) !== -1
}, },
editableKeywordWithString() { editableKeywordWithString() {
return Array.isArray(this.setting.type) && this.setting.key !== ':crontab' && ( return this.setting.key !== ':crontab' && (
(this.setting.type.includes('keyword') && this.setting.type.includes('string')) || (this.setting.type.includes('keyword') && this.setting.type.includes('string')) ||
(this.setting.type.includes('tuple') && this.setting.type.includes('list')) (this.setting.type.includes('tuple') && this.setting.type.includes('list')) ||
(this.setting.type.includes('map') && this.setting.type.includes('string'))
) )
}, },
isDesktop() { isDesktop() {