feat(structure): improve type colors and index editing
This commit is contained in:
1 parent
da1094df93
commit
fa7dde7c03
33 files changed
+1631
-132
No files matched your search
@@ -36,6 +36,7 @@ import {
|
||||
X,
|
||||
Pin,
|
||||
Pencil,
|
||||
PencilRuler,
|
||||
Rows3,
|
||||
Hash,
|
||||
SquareDashed,
|
||||
@@ -220,6 +221,8 @@ type DataGridHandle = DataGridColumnLayoutHandle & {
|
||||
openExtractorConfiguration: () => void;
|
||||
showDdl: boolean;
|
||||
toggleDdl: (tab?: TableInfoTab) => void;
|
||||
canOpenTableStructureEditor: boolean;
|
||||
openTableStructureEditor: (tab: TableInfoTab) => void;
|
||||
multiRowTranspose: boolean;
|
||||
setMultiRowTranspose: (value: boolean) => void;
|
||||
exportCsv: () => Promise<void>;
|
||||
@@ -2691,6 +2694,12 @@ defineExpose({
|
||||
</button>
|
||||
<span v-if="showDataColumnsChip && activeDataTabTableMeta" class="inline-flex shrink-0 items-center rounded border border-border bg-muted/30 px-2 py-0.5 font-medium text-muted-foreground tabular-nums"> {{ activeDataTabTableMeta.columns.length }} {{ t("tree.columns") }} </span>
|
||||
<span class="ml-auto" />
|
||||
<LightTooltip v-if="dataGridRef?.canOpenTableStructureEditor" :text="t('contextMenu.editStructure')" side="bottom" nowrap>
|
||||
<Button data-edit-table-structure variant="ghost" size="sm" class="h-5 text-xs px-1.5 shrink-0" :aria-label="t('contextMenu.editStructure')" @click="dataGridRef?.openTableStructureEditor('columns')">
|
||||
<PencilRuler class="h-3.5 w-3.5" />
|
||||
<span v-if="!dataToolbarCompact">{{ t("contextMenu.editStructure") }}</span>
|
||||
</Button>
|
||||
</LightTooltip>
|
||||
<DataGridColumnLayoutPopover v-if="activeTab.result?.columns.length" :grid="dataGridRef" trigger-class="px-1.5" />
|
||||
<Button v-if="activeTab.result && activeDataTabTableMeta && activeTab.connectionId" variant="ghost" size="sm" class="h-5 text-xs px-1.5 shrink-0" :class="{ 'bg-accent': dataGridRef?.showDdl }" :title="dataToolbarCompact ? t('grid.tableInfo') : undefined" @click="dataGridRef?.toggleDdl()"
|
||||
><TableProperties class="h-3.5 w-3.5" /><span v-if="!dataToolbarCompact">{{ t("grid.tableInfo") }}</span></Button
|
||||
|
||||
@@ -27,7 +27,7 @@ const TAB_DRAG_HORIZONTAL_THRESHOLD = 24;
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onUnmounted, ref, watch } from "vue";
|
||||
import { computed, inject, nextTick, onUnmounted, ref, watch } from "vue";
|
||||
import type { CSSProperties } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import {
|
||||
@@ -54,6 +54,7 @@ import {
|
||||
Pencil,
|
||||
Pin,
|
||||
PlugZap,
|
||||
Plus,
|
||||
RotateCcw,
|
||||
RotateCw,
|
||||
Search,
|
||||
@@ -75,6 +76,7 @@ import DatabaseIcon from "@/components/icons/DatabaseIcon.vue";
|
||||
import TabExecutionStatus from "@/components/layout/TabExecutionStatus.vue";
|
||||
import TabModeIcon from "@/components/layout/TabModeIcon.vue";
|
||||
import ReadOnlySessionControl from "@/components/connection/ReadOnlySessionControl.vue";
|
||||
import { EDITOR_TOOLBAR_ACTIONS } from "./editorToolbarActions";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
@@ -127,6 +129,8 @@ const { t } = useI18n();
|
||||
const queryStore = useQueryStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const connectionStore = useConnectionStore();
|
||||
const toolbar = inject(EDITOR_TOOLBAR_ACTIONS, null);
|
||||
const canNewQuery = computed(() => toolbar?.canNewQuery.value ?? false);
|
||||
const { toast } = useToast();
|
||||
const tabsContainerRef = ref<HTMLElement | null>(null);
|
||||
const { hasTabOverflow, scrollThumbLeftPercent, scrollThumbWidthPercent, isScrollbarDragging, updateScrollButtons, onTabsWheel, startScrollbarDrag } = useTabScroll(tabsContainerRef);
|
||||
@@ -1617,6 +1621,14 @@ watch([() => props.specialPageTabs?.settingsActive, () => props.specialPageTabs?
|
||||
>
|
||||
<!-- Compact vertical toolbar: search, tab organization, collapse. -->
|
||||
<div v-if="isVerticalLayout" class="flex h-9 shrink-0 items-center gap-0.5 border-b p-1" :class="isTabBarCollapsed ? 'justify-center' : ''">
|
||||
<Tooltip v-if="canNewQuery">
|
||||
<TooltipTrigger as-child>
|
||||
<button type="button" data-new-query-tab :class="verticalTabToolbarButtonClass" :aria-label="t('toolbar.newQuery')" @click="toolbar?.newQuery(groupId)">
|
||||
<Plus class="h-4 w-4" />
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ t("toolbar.newQuery") }}</TooltipContent>
|
||||
</Tooltip>
|
||||
<div v-if="!isTabBarCollapsed" class="relative min-w-0 flex-1">
|
||||
<Search class="pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input v-model="tabSearchQuery" type="search" :placeholder="t('tabs.searchOpenTabs')" class="h-7 w-full pl-7 text-sm" />
|
||||
@@ -1918,7 +1930,21 @@ watch([() => props.specialPageTabs?.settingsActive, () => props.specialPageTabs?
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="showOverflowControl" class="tab-overflow-control absolute right-0 top-0 z-30 flex h-full items-center">
|
||||
<Tooltip v-if="!isVerticalLayout && canNewQuery">
|
||||
<TooltipTrigger as-child>
|
||||
<button
|
||||
type="button"
|
||||
data-new-query-tab
|
||||
class="mx-0.5 inline-flex h-7 w-7 shrink-0 self-center items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
:aria-label="t('toolbar.newQuery')"
|
||||
@click="toolbar?.newQuery(groupId)"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ t("toolbar.newQuery") }}</TooltipContent>
|
||||
</Tooltip>
|
||||
<div v-if="showOverflowControl" class="tab-overflow-control absolute top-0 z-30 flex h-full items-center" :class="canNewQuery ? 'right-8' : 'right-0'">
|
||||
<Popover v-model:open="tabOverflowOpen">
|
||||
<PopoverTrigger as-child>
|
||||
<button type="button" class="inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background text-foreground/70 hover:border-border hover:text-foreground" :aria-label="t('tabs.openTabs')" :title="t('tabs.openTabs')">
|
||||
|
||||
+20
-1
@@ -7,7 +7,16 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ConnectionConfig, QueryTab } from "@/types/database";
|
||||
|
||||
vi.mock("@/components/editor/QueryEditor.vue", () => ({ default: { render: () => null } }));
|
||||
vi.mock("@/components/grid/DataGrid.vue", () => ({ default: { render: () => null } }));
|
||||
const mocks = vi.hoisted(() => ({ openTableStructureEditor: vi.fn() }));
|
||||
vi.mock("@/components/grid/DataGrid.vue", () => ({
|
||||
__esModule: true,
|
||||
default: {
|
||||
setup(_props: unknown, { expose }: { expose: (value: unknown) => void }) {
|
||||
expose({ canOpenTableStructureEditor: true, openTableStructureEditor: mocks.openTableStructureEditor });
|
||||
return () => null;
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
import ContentArea from "../ContentArea.vue";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
@@ -76,6 +85,16 @@ async function mountDataTab() {
|
||||
}
|
||||
|
||||
describe("table data header navigation", () => {
|
||||
it("opens the columns editor from the header beside the table controls", async () => {
|
||||
const { host, tab } = await mountDataTab();
|
||||
tab.result = { columns: [], rows: [], affected_rows: 0, execution_time_ms: 0 };
|
||||
await vi.waitFor(() => expect(host.querySelector("[data-edit-table-structure]")).not.toBeNull());
|
||||
const button = host.querySelector<HTMLButtonElement>("[data-edit-table-structure]")!;
|
||||
expect(button.closest("[data-grid-root]")).toBeNull();
|
||||
button.click();
|
||||
expect(mocks.openTableStructureEditor).toHaveBeenCalledWith("columns");
|
||||
});
|
||||
|
||||
it.each([false, true])("opens the connection browser, reusing an existing tab: %s", async (alreadyOpen) => {
|
||||
const { host, store, tab } = await mountDataTab();
|
||||
const existingId = alreadyOpen ? store.openDatabaseBrowser(connection.id) : undefined;
|
||||
|
||||
+23
-1
@@ -1,5 +1,5 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { createApp, nextTick } from "vue";
|
||||
import { createApp, nextTick, ref } from "vue";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { createI18n } from "vue-i18n";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
@@ -42,6 +42,7 @@ vi.mock("@/components/icons/DatabaseIcon.vue", () => ({
|
||||
}));
|
||||
|
||||
import EditorGroupTabBar from "../EditorGroupTabBar.vue";
|
||||
import { createNoopEditorToolbarActions, EDITOR_TOOLBAR_ACTIONS, type EditorToolbarActions } from "../editorToolbarActions";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
@@ -64,6 +65,7 @@ function mountBar(
|
||||
activePinia: ReturnType<typeof createPinia>,
|
||||
onActivateTab?: (tabId: string) => void,
|
||||
specialPageTabs?: { settingsOpen: boolean; settingsActive: boolean; driverStoreOpen: boolean; driverStoreActive: boolean; pluginCenterOpen: boolean; pluginCenterActive: boolean; driverUpdateCount: number },
|
||||
toolbarActions?: EditorToolbarActions,
|
||||
): Mounted {
|
||||
const store = useQueryStore();
|
||||
const host = createHost();
|
||||
@@ -78,6 +80,7 @@ function mountBar(
|
||||
// instance the test drives — otherwise drag validation runs against an
|
||||
// empty store and silently early-returns.
|
||||
app.use(activePinia);
|
||||
if (toolbarActions) app.provide(EDITOR_TOOLBAR_ACTIONS, toolbarActions);
|
||||
app.use(
|
||||
createI18n({
|
||||
legacy: false,
|
||||
@@ -167,6 +170,25 @@ describe("EditorGroupTabBar behavior", () => {
|
||||
setActivePinia(pinia);
|
||||
});
|
||||
|
||||
it("opens a new query through the app action for this editor group", async () => {
|
||||
const store = useQueryStore();
|
||||
const id = store.createTab("pg-1", "app", "users", "data", "public");
|
||||
const actions = createNoopEditorToolbarActions();
|
||||
actions.canNewQuery = ref(true);
|
||||
actions.newQuery = vi.fn();
|
||||
const { app, host } = mountBar(store.groups[0].id, [id], id, pinia, undefined, undefined, actions);
|
||||
await settle();
|
||||
const buttons = host.querySelectorAll<HTMLButtonElement>("[data-new-query-tab]");
|
||||
expect(buttons).toHaveLength(1);
|
||||
buttons[0].click();
|
||||
expect(actions.newQuery).toHaveBeenCalledExactlyOnceWith(store.groups[0].id);
|
||||
actions.canNewQuery.value = false;
|
||||
await settle();
|
||||
expect(host.querySelector("[data-new-query-tab]")).toBeNull();
|
||||
app.unmount();
|
||||
host.remove();
|
||||
});
|
||||
|
||||
it("offers duplicate without rename on a data tab", async () => {
|
||||
const store = useQueryStore();
|
||||
const id = store.createTab("pg-1", "app", "users", "data", "public");
|
||||
|
||||
@@ -21,6 +21,8 @@ export interface SpecialPageTabsState {
|
||||
}
|
||||
|
||||
export interface EditorToolbarActions {
|
||||
canNewQuery: Ref<boolean>;
|
||||
newQuery(groupId: string): void;
|
||||
explainMode: Ref<"explain" | "autotrace">;
|
||||
blockDangerousRedisCommands: Ref<boolean>;
|
||||
/** Highlights the database selector of the tab that needs a database choice. */
|
||||
@@ -71,6 +73,8 @@ export function createNoopEditorToolbarActions(): EditorToolbarActions {
|
||||
value: { settingsOpen: false, settingsActive: false, driverStoreOpen: false, driverStoreActive: false, pluginCenterOpen: false, pluginCenterActive: false, driverUpdateCount: 0 },
|
||||
} as Ref<SpecialPageTabsState>;
|
||||
return {
|
||||
canNewQuery: { value: false } as Ref<boolean>,
|
||||
newQuery: noop,
|
||||
explainMode: mode,
|
||||
blockDangerousRedisCommands: flag,
|
||||
databaseRequiredSignalFor: () => 0,
|
||||
|
||||
Reference in new issue
Block a user