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

automatically populate the key field based on the flag name #155

Merged
merged 2 commits into from
Oct 7, 2019
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: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ require (
github.com/lib/pq v1.2.0
github.com/markphelps/flipt-grpc-go v0.0.0-20190303144529-3ebb133e62c0
github.com/mattn/go-sqlite3 v1.11.0
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
aaronraff marked this conversation as resolved.
Show resolved Hide resolved
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/phyber/negroni-gzip v0.0.0-20180113114010-ef6356a5d029
github.com/pkg/errors v0.8.1
Expand Down
54 changes: 27 additions & 27 deletions ui/assets_vfsdata.go

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions ui/src/components/Flags/NewFlag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
</ul>
</div>
<form>
<BField label="Name">
<BInput
v-model="flag.name"
placeholder="Flag name"
required
@input="setKeyIfSameAsName"
/>
</BField>
<BField label="Key">
<BInput
v-model="flag.key"
Expand All @@ -23,9 +31,6 @@
@input="formatKey"
/>
</BField>
<BField label="Name">
<BInput v-model="flag.name" placeholder="Flag name" required />
</BField>
<BField label="Description (optional)">
<BInput v-model="flag.description" placeholder="Flag description" />
</BField>
Expand Down Expand Up @@ -79,11 +84,28 @@ export default {
},
methods: {
formatKey() {
this.flag.key = this.flag.key
this.flag.key = this.formatStringAsKey(this.flag.key);
},
formatStringAsKey(str) {
return str
.toLowerCase()
.split(" ")
.join("-");
},
setKeyIfSameAsName() {
// Remove the character that was just added before comparing
let prevName = this.flag.name.slice(0, -1);

// Check if the name and key are currently in sync
// We do this so we don't override a custom key value
if(this.keyIsUndefinedOrEmpty() || this.flag.key === this.formatStringAsKey(prevName)) {
this.flag.key = this.flag.name;
this.formatKey();
}
},
keyIsUndefinedOrEmpty() {
return this.flag.key === undefined || this.flag.key === "";
},
createFlag() {
Api.post("/flags", this.flag)
.then(response => {
Expand Down