Skip to content

Commit d135c5c

Browse files
committed
Fix KV browser
1 parent 98575a6 commit d135c5c

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

src/app/modules/kv/components/kv-data-browser.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
} @else { @for (item of items; track item.key) {
3232
<tr class="hover:bg-gray-50 dark:hover:bg-gray-800">
3333
<td class="px-4 py-3 font-mono text-sm">{{ item.key }}</td>
34-
<td class="px-4 py-3 text-sm text-gray-600 dark:text-gray-400 max-w-md truncate">
35-
{{ truncate(item.value) }}
34+
<td class="px-4 py-3 text-sm text-gray-600 dark:text-gray-400 max-w-md truncate font-mono">
35+
{{ formatValue(item.value) }}
3636
</td>
3737
<td class="px-4 py-3 text-sm text-gray-500">{{ formatDate(item.expiresAt) }}</td>
3838
<td class="px-4 py-3 text-right">

src/app/modules/kv/components/kv-data-browser.component.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export class KvDataBrowserComponent implements OnInit {
8080
}
8181

8282
openEdit(item: KvDataItem) {
83-
this.editingItem = { key: item.key, value: item.value, expiresIn: null, isNew: false };
83+
const valueStr = typeof item.value === 'string' ? item.value : JSON.stringify(item.value, null, 2);
84+
this.editingItem = { key: item.key, value: valueStr, expiresIn: null, isNew: false };
8485
}
8586

8687
closeEdit() {
@@ -90,10 +91,19 @@ export class KvDataBrowserComponent implements OnInit {
9091
save() {
9192
if (!this.editingItem) return;
9293

94+
// Try to parse as JSON, fallback to string
95+
let value: unknown = this.editingItem.value;
96+
97+
try {
98+
value = JSON.parse(this.editingItem.value);
99+
} catch {
100+
// Keep as string if not valid JSON
101+
}
102+
93103
this.kvDataService.put(
94104
this.namespaceId,
95105
this.editingItem.key,
96-
this.editingItem.value,
106+
value,
97107
this.editingItem.expiresIn ?? undefined
98108
).subscribe({
99109
next: () => {
@@ -130,9 +140,12 @@ export class KvDataBrowserComponent implements OnInit {
130140
});
131141
}
132142

133-
truncate(value: string, maxLength = 100): string {
134-
if (value.length <= maxLength) return value;
135-
return value.slice(0, maxLength) + '...';
143+
formatValue(value: unknown, maxLength = 100): string {
144+
const str = typeof value === 'string' ? value : JSON.stringify(value);
145+
146+
if (str.length <= maxLength) return str;
147+
148+
return str.slice(0, maxLength) + '...';
136149
}
137150

138151
formatDate(date: string | null): string {

src/app/services/kv-data.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Observable } from 'rxjs';
44

55
export interface KvDataItem {
66
key: string;
7-
value: string;
7+
value: unknown;
88
expiresAt: string | null;
99
createdAt: string;
1010
updatedAt: string;
@@ -46,7 +46,7 @@ export class KvDataService {
4646
put(
4747
namespaceId: string,
4848
key: string,
49-
value: string,
49+
value: unknown,
5050
expiresIn?: number
5151
): Observable<KvDataItem> {
5252
return this.http.put<KvDataItem>(

0 commit comments

Comments
 (0)