Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

6.1 KB
Raw Blame
<script setup lang="ts">
import { computed } from "vue";
import { BarChart3, ListChecks, MessageSquareText, Network, SquareTerminal } from "@lucide/vue";
import { useI18n } from "vue-i18n";
import { Button } from "@/components/ui/button";
import LightTooltip from "@/components/ui/LightTooltip.vue";
import type { RedisResultViewMode } from "@/types/database";

type OutputView = "result" | "graph" | "summary" | "explain" | "chart" | "messages" | "profile";
type PrimaryResultView = Exclude<OutputView, "explain" | "profile">;

const props = withDefaults(
  defineProps<{
    activeView: OutputView;
    canShowResult: boolean;
    canShowSummary: boolean;
    canShowChart: boolean;
    canShowGraph?: boolean;
    canShowMessages: boolean;
    canShowRedisConsole?: boolean;
    resultMode?: RedisResultViewMode;
    messageCount?: number;
    compact?: boolean;
  }>(),
  { compact: false, messageCount: 0, canShowRedisConsole: false, resultMode: "grid" },
);

const emit = defineEmits<{
  selectView: [view: PrimaryResultView];
  selectResultMode: [mode: RedisResultViewMode];
}>();

const { t } = useI18n();

const messagesTooltip = computed(() => (props.messageCount > 0 ? `${t("tabs.messages")} (${props.messageCount})` : t("tabs.messages")));
const effectiveResultMode = computed<RedisResultViewMode>(() => (props.canShowRedisConsole ? props.resultMode : "grid"));

function selectView(view: PrimaryResultView) {
  if (props.activeView === view) return;
  emit("selectView", view);
}

function selectResultMode(mode: RedisResultViewMode) {
  if (props.activeView === "result" && effectiveResultMode.value === mode) return;
  if (props.canShowRedisConsole && props.resultMode !== mode) emit("selectResultMode", mode);
  if (props.activeView !== "result") emit("selectView", "result");
}
</script>

<template>
  <div data-query-result-view-switcher class="flex shrink-0 items-center gap-1 px-1">
    <Button
      size="sm"
      :variant="activeView === 'result' && effectiveResultMode === 'grid' ? 'secondary' : 'ghost'"
      class="h-5 shrink-0 px-2 text-xs leading-none"
      :disabled="!canShowResult"
      :aria-pressed="activeView === 'result' && effectiveResultMode === 'grid'"
      @click="canShowRedisConsole ? selectResultMode('grid') : selectView('result')"
    >
      <span class="inline-flex h-4 items-center leading-none">{{ t("tabs.tableData") }}</span>
    </Button>

    <LightTooltip v-if="canShowGraph" :text="t('graph.title')" :disabled="!compact" side="bottom" :delay="0" :close-delay="0" nowrap>
      <Button size="sm" :variant="activeView === 'graph' ? 'secondary' : 'ghost'" class="h-5 shrink-0 px-2 text-xs leading-none" :class="compact ? 'w-6 px-0' : 'gap-1'" :title="t('graph.title')" :aria-label="t('graph.title')" :aria-pressed="activeView === 'graph'" @click="selectView('graph')">
        <Network class="h-3.5 w-3.5" />
        <span v-if="!compact">{{ t("graph.title") }}</span>
      </Button>
    </LightTooltip>

    <LightTooltip v-if="canShowRedisConsole" :text="t('redis.commandLine')" :disabled="!compact" side="bottom" :delay="0" :close-delay="0" nowrap>
      <Button
        size="sm"
        :variant="activeView === 'result' && effectiveResultMode === 'console' ? 'secondary' : 'ghost'"
        class="h-5 shrink-0 text-xs leading-none"
        :class="compact ? 'w-6 gap-0 px-0' : 'gap-1 px-2'"
        :title="t('redis.commandLine')"
        :aria-label="t('redis.commandLine')"
        :aria-pressed="activeView === 'result' && effectiveResultMode === 'console'"
        @click="selectResultMode('console')"
      >
        <SquareTerminal class="block h-3.5 w-3.5 self-center" />
        <span v-if="!compact" class="inline-flex h-4 items-center leading-none">{{ t("redis.commandLine") }}</span>
      </Button>
    </LightTooltip>

    <LightTooltip :text="t('tabs.executionSummary')" :disabled="!compact" side="bottom" :delay="0" :close-delay="0" nowrap>
      <Button
        size="sm"
        :variant="activeView === 'summary' ? 'secondary' : 'ghost'"
        class="h-5 shrink-0 text-xs leading-none"
        :class="compact ? 'w-6 gap-0 px-0' : 'gap-1 px-2'"
        :title="t('tabs.executionSummary')"
        :aria-label="t('tabs.executionSummary')"
        :aria-pressed="activeView === 'summary'"
        :disabled="!canShowSummary"
        @click="selectView('summary')"
      >
        <ListChecks class="block h-3.5 w-3.5 self-center" />
        <span v-if="!compact" class="inline-flex h-4 items-center leading-none">{{ t("tabs.executionSummary") }}</span>
      </Button>
    </LightTooltip>

    <LightTooltip :text="t('chart.title')" :disabled="!compact" side="bottom" :delay="0" :close-delay="0" nowrap>
      <Button
        size="sm"
        :variant="activeView === 'chart' ? 'secondary' : 'ghost'"
        class="h-5 shrink-0 text-xs leading-none"
        :class="compact ? 'w-6 gap-0 px-0' : 'gap-1 px-2'"
        :title="t('chart.title')"
        :aria-label="t('chart.title')"
        :aria-pressed="activeView === 'chart'"
        :disabled="!canShowChart"
        @click="selectView('chart')"
      >
        <BarChart3 class="block h-3.5 w-3.5 self-center" />
        <span v-if="!compact" class="inline-flex h-4 items-center leading-none">{{ t("chart.title") }}</span>
      </Button>
    </LightTooltip>

    <LightTooltip :text="messagesTooltip" :disabled="!compact" side="bottom" :delay="0" :close-delay="0" nowrap>
      <Button
        size="sm"
        :variant="activeView === 'messages' ? 'secondary' : 'ghost'"
        class="h-5 shrink-0 text-xs leading-none"
        :class="compact ? 'w-6 gap-0 px-0' : 'gap-1 px-2'"
        :title="messagesTooltip"
        :aria-label="messagesTooltip"
        :aria-pressed="activeView === 'messages'"
        :disabled="!canShowMessages"
        @click="selectView('messages')"
      >
        <MessageSquareText class="block h-3.5 w-3.5 self-center" />
        <span v-if="!compact" class="inline-flex h-4 items-center leading-none">{{ t("tabs.messages") }}</span>
        <span v-if="!compact && messageCount > 0" class="inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-muted px-1 text-[10px] leading-none tabular-nums text-muted-foreground">{{ messageCount }}</span>
      </Button>
    </LightTooltip>
  </div>
</template>