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

Support constraint editing - putConstraint #57

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all 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 .fsw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ triggers:
- './pkg'
- './swagger_gen'
- '!**/*_test.go'
cmd: make build && make run
cmd: make build && make run | jq .
shell: true
delay: 1000ms
stop_timeout: 500ms
Expand Down
12 changes: 2 additions & 10 deletions browser/flagr-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,8 @@
</template>

<script>
import {
Menu,
MenuItem
} from 'element-ui'

export default {
name: 'app',
components: {
'el-menu': Menu,
'el-menu-item': MenuItem
}
name: 'app'
}
</script>

Expand Down Expand Up @@ -150,6 +141,7 @@ ul {
border: 1px solid #ccc;
border-radius: 3px;
width: 100%;
margin-bottom: 12px;
}
}

Expand Down
175 changes: 102 additions & 73 deletions browser/flagr-ui/src/components/Flag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,22 @@
</div>
<div class="flex-row-right">
<el-button size="small" @click="putFlag(flag)">
Save
Save Flag
</el-button>
</div>
</div>
<el-row :gutter="20" class="flag-content">
<el-row :gutter="10" class="flag-content">
<el-col :span="17">
<el-input
size="small"
placeholder="Key"
v-model="flag.description">
<template slot="prepend">Flag Description</template>
</el-input>
</el-col>
<el-col :span="7">
<el-switch
size="small"
v-model="flag.dataRecordsEnabled"
on-color="#74E5E0"
:on-value="true"
Expand All @@ -155,7 +157,7 @@
</div>
<div class="flex-row-right">
<el-button slot="append" size="small" @click="putVariant(variant)">
Save
Save Variant
</el-button>
<el-button @click="deleteVariant(variant)" size="small">
<span class="el-icon-delete2"/>
Expand Down Expand Up @@ -225,23 +227,25 @@
</div>
<div class="flex-row-right">
<el-button slot="append" size="small" @click="putSegment(segment)">
Save
Save Segment
</el-button>
<el-button @click="deleteSegment(segment)" size="small">
<span class="el-icon-delete2"/>
</el-button>
</div>
</div>
<el-row :gutter="20" class="id-row">
<el-col :span="12">
<el-col :span="17">
<el-input
size="small"
placeholder="Description"
v-model="segment.description">
<template slot="prepend">Description</template>
</el-input>
</el-col>
<el-col :span="12">
<el-col :span="7">
<el-input
size="small"
placeholder="0"
v-model="segment.rolloutPercent"
:min="0"
Expand All @@ -252,72 +256,102 @@
</el-input>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12" class="segment-constraints">
<h4>Constraints</h4>
<el-row>
<el-col :span="24">
<h4>Constraints (match ALL of them)</h4>
<div class="constraints">
<ol class="constraints-inner" v-if="segment.constraints.length">
<li
class="flex-row"
<div class="constraints-inner" v-if="segment.constraints.length">
<div
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-tooltip :content="constraint.value" placement="top">
<el-tag type="gray" class="truncate">{{ constraint.value }}</el-tag>
</el-tooltip>
</div>
<div class="flex-row-right">
<el-button @click="deleteConstraint(segment, constraint)" size="mini">
<span class="el-icon-delete2"/>
</el-button>
</div>
</li>
</ol>
<el-row :gutter="3" class="segment-constraint">
<el-col :span="20">
<el-input
size="small"
placeholder="Property"
v-model="constraint.property">
<template slot="prepend">Property</template>
</el-input>
</el-col>
<el-col :span="4">
<el-select size="small" v-model="constraint.operator" placeholder="operator">
<el-option
v-for="item in operatorOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-col>
<el-col :span="20">
<el-input
size="small"
placeholder='Value, e.g. "CA", ["CA", "NY"]'
v-model="constraint.value">
<template slot="prepend">Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template>
</el-input>
</el-col>
<el-col :span="2">
<el-button class="width--full" @click="putConstraint(segment, constraint)" size="small">
<span class="el-icon-check"/>
</el-button>
</el-col>
<el-col :span="2">
<el-button class="width--full" @click="deleteConstraint(segment, constraint)" size="small">
<span class="el-icon-delete2"/>
</el-button>
</el-col>
</el-row>
</div>
</div>
<div class="card--empty" v-else>
<span>No constraints for this segment yet</span>
</div>
<div>
<div class="flex-row equal-width constraints-inputs-container">
<div>
<el-row :gutter="3" class="segment-constraint">
<el-col :span="5">
<el-input
size="small"
placeholder="Property"
v-model="segment.newConstraint.property">
v-model="segment.newConstraint.property">
</el-input>
</div>
<div>
<el-select v-model="segment.newConstraint.operator" placeholder="operator">
</el-col>
<el-col :span="4">
<el-select size="small" v-model="segment.newConstraint.operator" placeholder="operator">
<el-option
v-for="item in operatorOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</div>
<div>
</el-col>
<el-col :span="11">
<el-input
placeholder="Value"
v-model="segment.newConstraint.value">
size="small"
placeholder='Value, e.g. "CA", ["CA", "NY"]'
v-model="segment.newConstraint.value">
</el-input>
</div>
</div>
<el-button
class="width--full"
:disabled="!segment.newConstraint.property || !segment.newConstraint.value"
@click.prevent="() => createConstraint(segment)">
Create Constraint
</el-button>
</el-col>
<el-col :span="4">
<el-button
class="width--full"
size="small"
:disabled="!segment.newConstraint.property || !segment.newConstraint.value"
@click.prevent="() => createConstraint(segment)">
<span class="el-icon-plus"/>
</el-button>
</el-col>
</el-row>
</div>
</div>
</el-col>
<el-col :span="12" class="segment-distributions">
<el-col :span="24" class="segment-distributions">
<h4>Distribution</h4>
<ul class="segment-distributions-inner" v-if="segment.distributions.length">
<li v-for="distribution in segment.distributions" :key="distribution.id">
<el-tag type="gray">{{ distribution.variantKey }}</el-tag>
<span>{{ distribution.percent }} %</span>
<span size="small">{{ distribution.percent }}%</span>
</li>
</ul>
<div class="card--empty" v-else>
Expand Down Expand Up @@ -356,7 +390,6 @@ import constants from '@/constants'
import helpers from '@/helpers/helpers'
import Spinner from '@/components/Spinner'
import clone from 'lodash.clone'
import { Button, Dialog, Slider, Checkbox, Tag, Breadcrumb, BreadcrumbItem, Switch } from 'element-ui'
import {operators} from '@/../config/operators.json'

const OPERATOR_VALUE_TO_LABEL_MAP = operators.reduce((acc, el) => {
Expand Down Expand Up @@ -406,15 +439,7 @@ function processVariant (variant) {
export default {
name: 'flag',
components: {
spinner: Spinner,
'el-button': Button,
'el-dialog': Dialog,
'el-slider': Slider,
'el-checkbox': Checkbox,
'el-tag': Tag,
'el-breadcrumb': Breadcrumb,
'el-breadcrumb-item': BreadcrumbItem,
'el-switch': Switch
spinner: Spinner
},
data () {
return {
Expand Down Expand Up @@ -580,6 +605,18 @@ export default {
this.$message.error(err.body.message)
})
},
putConstraint (segment, constraint) {
const {flagId} = this.$route.params

this.$http.put(
`${API_URL}/flags/${flagId}/segments/${segment.id}/constraints/${constraint.id}`,
constraint
).then(() => {
this.$message.success('constraint updated')
}, err => {
this.$message.error(err.body.message)
})
},
deleteConstraint (segment, constraint) {
const {flagId} = this.$route.params

Expand Down Expand Up @@ -690,16 +727,11 @@ h2 {
background-color: #ddd;
}
}
}

.segment-constraints {
padding-right: 10px;
}

.segment-distributions {
padding-left: 10px;
.edit-distribution-button {
margin-top: 5px;
.segment-constraint {
margin-bottom: 12px;
padding: 1px;
background-color: #f6f6f6;
border-radius: 5px;
}
}

Expand All @@ -713,7 +745,6 @@ ol.constraints-inner {
padding: 3px 0;
.el-tag {
font-size: 0.7em;
vertical-align: middle;
}
}
}
Expand All @@ -732,6 +763,10 @@ ol.constraints-inner {
margin-top: 10px;
}

.edit-distribution-button {
margin-top: 5px;
}

.edit-distribution-choose-variants {
padding: 10px 0;
}
Expand All @@ -752,12 +787,6 @@ ol.constraints-inner {
margin-bottom: 8px;
}

.truncate {
max-width: 200px;
overflow-x: hidden;
text-overflow: ellipsis;
}

.flag-content{
margin-top: 8px;
}
Expand Down
9 changes: 1 addition & 8 deletions browser/flagr-ui/src/components/Flags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<script>
import constants from '@/constants'
import Spinner from '@/components/Spinner'
import { Tag, Button, Input, Alert, Breadcrumb, BreadcrumbItem } from 'element-ui'

const {
API_URL
Expand All @@ -61,13 +60,7 @@ const {
export default {
name: 'flags',
components: {
spinner: Spinner,
'el-tag': Tag,
'el-input': Input,
'el-button': Button,
'el-alert': Alert,
'el-breadcrumb': Breadcrumb,
'el-breadcrumb-item': BreadcrumbItem
spinner: Spinner
},
data () {
return {
Expand Down
2 changes: 2 additions & 0 deletions pkg/repo/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
_ "github.com/jinzhu/gorm/dialects/mysql" // mysql driver
_ "github.com/jinzhu/gorm/dialects/postgres" // postgres driver
_ "github.com/jinzhu/gorm/dialects/sqlite" // sqlite driver
"github.com/sirupsen/logrus"

"github.com/checkr/flagr/pkg/config"
"github.com/checkr/flagr/pkg/entity"
Expand All @@ -33,6 +34,7 @@ func GetDB() *gorm.DB {
if err != nil {
panic(err)
}
db.SetLogger(logrus.StandardLogger())
db.AutoMigrate(autoMigrateTables...)
singletonDB = db
})
Expand Down