Skip to content

Commit

Permalink
Merge pull request #50 from checkr/pw/add-delete-variant-ui
Browse files Browse the repository at this point in the history
Add ability to delete variant. Halt user if the variant is currently …
  • Loading branch information
lucidrains authored Oct 21, 2017
2 parents 1244247 + 1da9d25 commit db56d3e
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions browser/flagr-ui/src/components/Flag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
<el-button slot="append" size="small" @click="putVariant(variant)">
Save
</el-button>
<el-button @click="deleteVariant(variant)" type="danger" size="mini">
<span class="el-icon-delete2"/>
</el-button>
</div>
</div>

Expand Down Expand Up @@ -489,6 +492,29 @@ export default {
this.flag.variants.push(variant)
})
},
deleteVariant (variant) {
const {flagId} = this.$route.params
const isVariantInUse = this.flag.segments.some(segment => (
segment.distributions.some(distribution => distribution.variantID === variant.id)
))
if (isVariantInUse) {
alert('This variant is being used by a segment distribution. Please remove the segment or edit the distribution in order to remove this variant.')
return
}
if (!confirm(`Are you sure you want to delete variant #${variant.id} [${variant.key}]`)) {
return
}
fetch(
`${API_URL}/flags/${flagId}/variants/${variant.id}`,
{method: 'delete'}
).then(() => {
this.fetchFlag()
})
},
putVariant (variant) {
const flagId = this.$route.params.flagId
variant.attachment = JSON.parse(variant.attachmentStr)
Expand Down Expand Up @@ -557,17 +583,19 @@ export default {
this.$message('You created a new segment')
this.dialogCreateSegmentOpen = false
})
},
fetchFlag () {
const flagId = this.$route.params.flagId
getJson(`${API_URL}/flags/${flagId}`).then(flag => {
flag.segments.forEach(segment => processSegment(segment))
flag.variants.forEach(variant => processVariant(variant))
this.flag = flag
this.loaded = true
})
}
},
created () {
const flagId = this.$route.params.flagId
getJson(`${API_URL}/flags/${flagId}`).then(flag => {
flag.segments.forEach(segment => processSegment(segment))
flag.variants.forEach(variant => processVariant(variant))
this.flag = flag
this.loaded = true
})
this.fetchFlag()
}
}
</script>
Expand Down

0 comments on commit db56d3e

Please sign in to comment.