Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed input text to json-editor in flag variant form #258

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion browser/flagr-ui/src/components/DebugConsole.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default {
}
</script>

<style lang="less">
<style lang="less" scoped>
yosyad marked this conversation as resolved.
Show resolved Hide resolved
.json-editor {
margin-top: 3px;
.jsoneditor {
Expand Down
44 changes: 34 additions & 10 deletions browser/flagr-ui/src/components/Flag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@
</el-input>
</el-col>
<el-col :span="12">
<el-input
size="small"
placeholder="{}"
v-model="variant.attachmentStr">
<template slot="prepend">Attachment </template>
</el-input>
<vue-json-editor
yosyad marked this conversation as resolved.
Show resolved Hide resolved
v-model="variant.attachment"
:showBtns="false"
:ref="'json-editor-' + variant.id"
yosyad marked this conversation as resolved.
Show resolved Hide resolved
class="json-editor"
></vue-json-editor>
</el-col>
</el-row>
</el-form>
Expand Down Expand Up @@ -505,6 +505,7 @@ import Spinner from '@/components/Spinner'
import DebugConsole from '@/components/DebugConsole'
import FlagHistory from '@/components/FlagHistory'
import MarkdownEditor from '@/components/MarkdownEditor.vue'
import vueJsonEditor from 'vue-json-editor'
import {operators} from '@/../config/operators.json'

const OPERATOR_VALUE_TO_LABEL_MAP = operators.reduce((acc, el) => {
Expand Down Expand Up @@ -549,7 +550,9 @@ function processSegment (segment) {
}

function processVariant (variant) {
variant.attachmentStr = JSON.stringify(variant.attachment)
if (typeof variant.attachment === 'string') {
variant.attachment = JSON.parse(variant.attachment)
}
}

export default {
Expand All @@ -559,10 +562,12 @@ export default {
debugConsole: DebugConsole,
flagHistory: FlagHistory,
draggable: draggable,
MarkdownEditor
MarkdownEditor,
vueJsonEditor
},
data () {
return {
refsIntervalId: false,
yosyad marked this conversation as resolved.
Show resolved Hide resolved
loaded: false,
dialogDeleteFlagVisible: false,
dialogEditDistributionOpen: false,
Expand Down Expand Up @@ -714,7 +719,6 @@ export default {
}, handleErr.bind(this))
},
putVariant (variant) {
variant.attachment = JSON.parse(variant.attachmentStr)
Axios.put(
`${API_URL}/flags/${this.flagId}/variants/${variant.id}`,
variant
Expand Down Expand Up @@ -835,15 +839,29 @@ export default {
},
toggleShowMdEditor () {
this.showMdEditor = !this.showMdEditor
},
setJsonEdiorModeWhenMounted () {
yosyad marked this conversation as resolved.
Show resolved Hide resolved
if (!this.$refs) {
return
}

const jsonEditorRefs = Object.keys(this.$refs).filter(key => key.startsWith('json-editor'))

jsonEditorRefs.forEach(ref => {
this.$refs[ref][0].editor.setMode('code')
})

clearInterval(this.refsIntervalId)
}
},
mounted () {
this.fetchFlag()
this.refsIntervalId = setInterval(this.setJsonEdiorModeWhenMounted, 50)
yosyad marked this conversation as resolved.
Show resolved Hide resolved
}
}
</script>

<style lang="less">
<style lang="less" scoped>
yosyad marked this conversation as resolved.
Show resolved Hide resolved
h5 {
padding: 0;
margin: 10px 0 5px;
Expand Down Expand Up @@ -959,4 +977,10 @@ ol.constraints-inner {
}
}

.json-editor {
.jsoneditor {
height: 200px;
}
}

</style>