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

Empty string constraint fixes #193

Merged
merged 12 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
markphelps committed Nov 26, 2019
commit 782ee48ffeefbcd0f741b5dbbc56e1484ed1d2f1
7 changes: 7 additions & 0 deletions config/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ db:
url: file:flipt.db
migrations:
path: ./config/migrations

ui:
enabled: false

cors:
enabled: true
allowed_origins: "*"
4 changes: 4 additions & 0 deletions server/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func (s *Server) CreateConstraint(ctx context.Context, req *flipt.CreateConstrai
return nil, emptyFieldError("operator")
}

// TODO: test for empty value if operator ! [EMPTY, NOT_EMPTY, PRESENT, NOT_PRESENT]

return s.SegmentStore.CreateConstraint(ctx, req)
}

Expand All @@ -106,6 +108,8 @@ func (s *Server) UpdateConstraint(ctx context.Context, req *flipt.UpdateConstrai
return nil, emptyFieldError("operator")
}

// TODO: test for empty value if operator ! [EMPTY, NOT_EMPTY, PRESENT, NOT_PRESENT]

return s.SegmentStore.UpdateConstraint(ctx, req)
}

Expand Down
4 changes: 2 additions & 2 deletions storage/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,6 @@ func validate(c constraint) error {
}

func matchesString(c constraint, v string) bool {
value := c.Value

switch c.Operator {
case opEmpty:
return len(strings.TrimSpace(v)) == 0
Expand All @@ -434,6 +432,8 @@ func matchesString(c constraint, v string) bool {
return false
}

value := c.Value

switch c.Operator {
case opEQ:
return value == v
Expand Down
29 changes: 26 additions & 3 deletions ui/src/components/Segments/Segment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@
</BSelect>
</b-field>
<b-field v-show="hasValue(newConstraint.operator)" label="Value">
<b-input v-model="newConstraint.value" placeholder="Value" />
<b-input
v-model="newConstraint.value"
placeholder="Value"
required
/>
</b-field>
<div class="field is-grouped">
<div class="control">
Expand Down Expand Up @@ -248,6 +252,7 @@
<b-input
v-model="selectedConstraint.value"
placeholder="Value"
required
/>
</b-field>
<div class="field is-grouped">
Expand Down Expand Up @@ -396,10 +401,28 @@ export default {
return this.segment.key && this.segment.name;
},
canAddConstraint() {
return this.newConstraint.property && this.newConstraint.type;
let valid =
this.newConstraint.property &&
this.newConstraint.type &&
this.newConstraint.operator;

if (this.hasValue(this.newConstraint.operator)) {
return valid && this.newConstraint.value;
}

return valid;
},
canUpdateConstraint() {
return this.selectedConstraint.property && this.selectedConstraint.type;
let valid =
this.selectedConstraint.property &&
this.selectedConstraint.type &&
this.selectedConstraint.operator;

if (this.hasValue(this.selectedConstraint.operator)) {
return valid && this.selectedConstraint.value;
}

return valid;
}
},
mounted() {
Expand Down
7 changes: 6 additions & 1 deletion ui/src/services/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import axios from "axios";

let host =
process.env.NODE_ENV === "production"
? window.location.host
: "localhost:8080";

export const Api = axios.create({
baseURL: "//" + window.location.host + "/api/v1/"
baseURL: "//" + host + "/api/v1/"
});