Skip to content

Commit

Permalink
fix(ui): fix datetime/date type handling for KV
Browse files Browse the repository at this point in the history
  • Loading branch information
fhussonnois committed Aug 5, 2024
1 parent d058c56 commit 43a0fe4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
18 changes: 9 additions & 9 deletions ui/src/components/namespace/NamespaceKV.vue
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,21 @@
return false;
}
const type = this.kv.type;
let value = this.kv.value;
if (this.kv.type === "BOOLEAN" && !this.kv.value) {
value = "false"
} else if (this.kv.type === "STRING" && !this.kv.value.startsWith("\"")) {
value = `"${value}"`
} else if (this.kv.type === "DATETIME") {
value = this.$moment(this.kv.value).toISOString()
} else if (this.kv.type === "DATE") {
value = this.$moment(this.kv.value).toISOString(true).split("T")[0]
if (["STRING", "DURATION"].includes(type)) {
value = JSON.stringify(value);
} else if (type === "DATETIME") {
value = this.$moment(value).toISOString()
} else if (type === "DATE") {
value = this.$moment(value).toISOString(true).split("T")[0]
}
return this.$store
.dispatch(
"namespace/createKv",
{namespace: this.$route.params.id, ...this.kv, value}
{namespace: this.$route.params.id, ...this.kv, contentType: ["DATE", "DATETIME"].includes(type) ? "text/plain" : "application/json", value}
)
.then(() => {
this.$toast().saved(this.kv.key);
Expand Down
5 changes: 4 additions & 1 deletion ui/src/stores/namespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export default {
.put(
`${apiUrl(this)}/namespaces/${payload.namespace}/kv/${payload.key}`,
payload.value,
{headers: {"Content-Type": "application/json", "ttl": payload.ttl}}
{headers: {
"Content-Type": payload.contentType,
"ttl": payload.ttl
}}
)
.then(() => {
return dispatch("kvsList", {id: payload.namespace})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TypedValue get(
}

@ExecuteOn(TaskExecutors.IO)
@Put(uri = "{key}", consumes = {MediaType.APPLICATION_JSON})
@Put(uri = "{key}", consumes = {MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
@Operation(tags = {"KV"}, summary = "Puts a key-value pair in store")
public void put(
HttpHeaders httpHeaders,
Expand Down

0 comments on commit 43a0fe4

Please sign in to comment.