Skip to content

Commit

Permalink
Merge pull request #32 from checkr/pw/add-delete-constraints-ui
Browse files Browse the repository at this point in the history
Add ability to delete constraints and also add indicator on flags col…
  • Loading branch information
zhouzhuojie authored Oct 14, 2017
2 parents e9f3287 + 6845d6e commit 6b1455c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
37 changes: 31 additions & 6 deletions browser/flagr-ui/src/components/Flag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<el-checkbox
@change="(e) => selectVariant(e, variant)"
:checked="!!newDistributions[variant.id]"
>
>
</el-checkbox>
<el-tag type="danger">
{{ variant.key }}
Expand Down Expand Up @@ -146,10 +146,20 @@
<h4>Constraints ({{segment.constraints.length}})</h4>
<div class="constraints">
<ol class="constraints-inner" v-if="segment.constraints.length">
<li v-for="constraint in segment.constraints" :key="constraint.id">
<el-tag type="gray">{{ constraint.property }}</el-tag>
<el-tag type="primary">{{ operatorValueToLabelMap[constraint.operator] }}</el-tag>
<el-tag type="gray">{{ constraint.value }}</el-tag>
<li
class="flex-row"
v-for="constraint in segment.constraints"
:key="constraint.id">
<div class="flex-row-left">
<el-tag type="gray">{{ constraint.property }}</el-tag>
<el-tag type="primary">{{ operatorValueToLabelMap[constraint.operator] }}</el-tag>
<el-tag type="gray">{{ constraint.value }}</el-tag>
</div>
<div class="flex-row-right">
<el-button @click="deleteConstraint(segment, constraint)">
<span class="el-icon-delete2"/>
</el-button>
</div>
</li>
</ol>
<div class="card--empty" v-else>
Expand Down Expand Up @@ -404,14 +414,29 @@ export default {
})
},
createConstraint (segment) {
const flagId = this.$route.params.flagId
const {flagId} = this.$route.params
postJson(`${API_URL}/flags/${flagId}/segments/${segment.id}/constraints`, segment.newConstraint)
.then(constraint => {
segment.constraints.push(constraint)
segment.newConstraint = clone(DEFAULT_CONSTRAINT)
this.$message('You created a new constraint')
})
},
deleteConstraint (segment, constraint) {
const {flagId} = this.$route.params
if (!confirm('Are you sure you want to delete this constraint?')) {
return
}
fetch(
`${API_URL}/flags/${flagId}/segments/${segment.id}/constraints/${constraint.id}`,
{method: 'delete'}
).then(() => {
const index = segment.constraints.findIndex(constraint => constraint.id === constraint.id)
segment.constraints.splice(index, 1)
})
},
createSegment () {
const flagId = this.$route.params.flagId
postJson(`${API_URL}/flags/${flagId}/segments`, this.newSegment)
Expand Down
24 changes: 21 additions & 3 deletions browser/flagr-ui/src/components/Flags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@
<span v-if="flags.length">({{ flags.length }})</span>
</h2>
<ul v-if="flags.length">
<li v-for="flag in flags" class="flag" v-bind:class="{new: flag._new}">
<li
v-for="flag in flags" class="flag"
:class="{new: flag._new}">
<router-link
class="flag-link"
class="flag-link flex-row"
:to="{name: 'flag', params: {flagId: flag.id}}">
<el-tag>{{ flag.id }}</el-tag> {{ flag.description }}
<div class="flex-row-left">
<el-tag>{{ flag.id }}</el-tag> {{ flag.description }}
</div>
<div class="flex-row-right">
<span :class="{'flag-enabled-icon': true, enabled: flag.enabled}"></span>
</div>
</router-link>
</li>
</ul>
Expand Down Expand Up @@ -145,6 +152,7 @@ export default {
}
.flag-link {
display: inline-block;
box-sizing: border-box;
padding: 8px 12px;
font-size: 1.1em;
width: 100%;
Expand All @@ -155,6 +163,16 @@ export default {
color: white;
}
}
.flag-enabled-icon {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 5px;
background-color: #ff4949;
&.enabled {
background-color: #13ce66;
}
}
}
}
}
Expand Down

0 comments on commit 6b1455c

Please sign in to comment.