feat(redis): add command-line query result mode

Closes #10099
This commit is contained in:
t8y2 committed 2026-09-27 12:36:33 +00:00
1 parent add378d643
commit 9c23e3198b
19 files changed
+488 -41

No files matched your search

@@ -2026,7 +2026,7 @@ async function runRedisCommand(command: string) {
const entryId = appendCommandHistory({ prompt, command, output: "", error: false });
try {
const result = await api.redisExecuteCommand(props.connectionId, commandDb.value, command, !props.blockDangerousRedisCommands);
updateCommandHistory(entryId, { output: formatRedisConsoleValue(result.value), error: false });
updateCommandHistory(entryId, { output: formatRedisConsoleValue(result.value, command), error: false });
// The db this command ran on — capture before nextRedisCommandDb() advances it.
const executedDb = commandDb.value;
commandDb.value = nextRedisCommandDb(commandDb.value, command, result.value);
@@ -0,0 +1,37 @@
// @vitest-environment happy-dom
import { createApp, h, nextTick } from "vue";
import { createI18n } from "vue-i18n";
import { afterEach, describe, expect, it } from "vitest";
import RedisQueryConsoleOutput from "@/components/redis/RedisQueryConsoleOutput.vue";
import { redisCommandResultToQueryResult } from "@/lib/redis/redisQueryResult";
import type { QueryResult } from "@/types/database";
const mounted: Array<{ unmount: () => void; host: HTMLElement }> = [];
afterEach(() => {
for (const { unmount, host } of mounted.splice(0)) {
unmount();
host.remove();
}
});
describe("RedisQueryConsoleOutput", () => {
it("renders every command result and keeps failures visually distinct", async () => {
const results: QueryResult[] = [
{ ...redisCommandResultToQueryResult("PONG", 1, "PING"), sourceStatement: "PING" },
{ ...redisCommandResultToQueryResult(["one", "two"], 1, "LRANGE items 0 -1"), sourceStatement: "LRANGE items 0 -1" },
{ columns: ["Error"], rows: [["ERR unknown command"]], affected_rows: 0, execution_time_ms: 0, execution_error: true, sourceStatement: "NOPE" },
];
const host = document.createElement("div");
document.body.appendChild(host);
const app = createApp({ render: () => h(RedisQueryConsoleOutput, { results }) });
app.use(createI18n({ legacy: false, locale: "en", messages: { en: { redis: { commandLine: "Command line", commandEmptyResult: "No output" } } } }));
app.mount(host);
mounted.push({ unmount: () => app.unmount(), host });
await nextTick();
expect([...host.querySelectorAll("div.flex.min-w-0")].map((node) => node.textContent?.trim())).toEqual(["redis>PING", "redis>LRANGE items 0 -1", "redis>NOPE"]);
expect([...host.querySelectorAll("pre")].map((node) => node.textContent)).toEqual(["PONG", '1) "one"\n2) "two"', "(error) ERR unknown command"]);
expect(host.querySelectorAll("pre")[2]?.className).toContain("text-[#ff6b6b]");
});
});
@@ -0,0 +1,39 @@
<script setup lang="ts">
import { computed } from "vue";
import { Loader2 } from "@lucide/vue";
import { useI18n } from "vue-i18n";
import { redisQueryResultsToConsoleEntries } from "@/lib/redis/redisQueryResult";
import type { QueryResult } from "@/types/database";
const props = withDefaults(
defineProps<{
result?: QueryResult;
results?: QueryResult[];
loading?: boolean;
}>(),
{ loading: false },
);
const { t } = useI18n();
const entries = computed(() => redisQueryResultsToConsoleEntries(props.results?.length ? props.results : props.result ? [props.result] : []));
</script>
<template>
<div data-redis-query-console role="region" class="dbx-editor-font-family flex min-h-0 flex-1 flex-col bg-[#171b21] text-[13px] leading-5 text-slate-200" :aria-label="t('redis.commandLine')">
<div class="min-h-0 flex-1 overflow-auto px-4 py-4">
<div v-for="(entry, index) in entries" :key="`${index}:${entry.command}`" class="mb-4 last:mb-0">
<div v-if="entry.command" class="flex min-w-0 items-start gap-2 whitespace-pre-wrap break-words">
<span class="shrink-0 text-[#d7ba7d]">redis&gt;</span>
<span class="min-w-0 text-slate-200">{{ entry.command }}</span>
</div>
<pre data-native-clipboard class="m-0 whitespace-pre-wrap break-words" :class="entry.error ? 'text-[#ff6b6b]' : 'text-slate-300'">{{ entry.output }}</pre>
</div>
<div v-if="loading && entries.length === 0" class="flex h-full items-center justify-center text-slate-400">
<Loader2 class="h-4 w-4 animate-spin" />
</div>
<div v-else-if="entries.length === 0" class="flex h-full items-center justify-center text-slate-400">
{{ t("redis.commandEmptyResult") }}
</div>
</div>
</div>
</template>