Skip to content

Commit 6ddc629

Browse files
committed
feat(editor): show active database and update window title
1 parent 6037e00 commit 6ddc629

5 files changed

Lines changed: 83 additions & 9 deletions

File tree

src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@
579579
"noValidQueries": "No valid queries found",
580580
"queryFailed": "Query failed.",
581581
"newVisualQuery": "New Visual Query",
582+
"activeDatabase": "Active database",
582583
"tabSwitcher": {
583584
"title": "Open Tabs",
584585
"hint": "Ctrl+Tab",

src/i18n/locales/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@
572572
"noValidQueries": "No se encontraron consultas válidas",
573573
"queryFailed": "La consulta falló.",
574574
"newVisualQuery": "Nueva Consulta Visual",
575+
"activeDatabase": "Base de datos activa",
575576
"tabSwitcher": {
576577
"title": "Pestañas Abiertas",
577578
"hint": "Ctrl+Tab",

src/i18n/locales/it.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@
579579
"noValidQueries": "Nessuna query valida trovata",
580580
"queryFailed": "Esecuzione query fallita.",
581581
"newVisualQuery": "Nuova Query Visuale",
582+
"activeDatabase": "Database attivo",
582583
"tabSwitcher": {
583584
"title": "Tab Aperte",
584585
"hint": "Ctrl+Tab",

src/i18n/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@
579579
"noValidQueries": "未找到有效查询",
580580
"queryFailed": "查询失败。",
581581
"newVisualQuery": "新建可视化查询",
582+
"activeDatabase": "当前数据库",
582583
"tabSwitcher": {
583584
"title": "打开的标签",
584585
"hint": "Ctrl+Tab",

src/pages/Editor.tsx

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const CHEVRON_SELECT_STYLE: React.CSSProperties = {
9898

9999
export const Editor = () => {
100100
const { t } = useTranslation();
101-
const { activeConnectionId, tables, views, activeDriver, activeSchema, activeCapabilities } = useDatabase();
101+
const { activeConnectionId, tables, views, activeDriver, activeSchema, activeCapabilities, selectedDatabases, activeConnectionName, activeDatabaseName } = useDatabase();
102102
const { explorerConnectionId } = useConnectionLayoutContext();
103103
const { settings } = useSettings();
104104
const { saveQuery } = useSavedQueries();
@@ -210,6 +210,7 @@ export const Editor = () => {
210210
useState(false);
211211
const [isTabSwitcherOpen, setIsTabSwitcherOpen] = useState(false);
212212
const [isRunDropdownOpen, setIsRunDropdownOpen] = useState(false);
213+
const [isDbDropdownOpen, setIsDbDropdownOpen] = useState(false);
213214
const [isAiModalOpen, setIsAiModalOpen] = useState(false);
214215
const [isAiExplainModalOpen, setIsAiExplainModalOpen] = useState(false);
215216
const [isEditingPage, setIsEditingPage] = useState(false);
@@ -226,9 +227,33 @@ export const Editor = () => {
226227
const activeTabType = activeTab?.type;
227228
const activeTabQuery = activeTab?.query;
228229
const isTableTab = activeTab?.type === "table";
230+
const isMultiDb = isMultiDatabaseCapable(activeCapabilities) && selectedDatabases.length > 1;
229231
const isEditorOpen =
230232
!isTableTab && (activeTab?.isEditorOpen ?? activeTab?.type !== "table");
231233

234+
// Update window title when the active tab changes
235+
useEffect(() => {
236+
const updateTitle = async () => {
237+
try {
238+
let title = 'tabularis';
239+
if (activeConnectionName && activeDatabaseName) {
240+
const schemaSuffix = activeSchema && activeCapabilities?.schemas === true ? `/${activeSchema}` : '';
241+
let dbDisplay: string;
242+
if (isMultiDb) {
243+
dbDisplay = activeTab?.schema ?? selectedDatabases[0] ?? activeDatabaseName;
244+
} else {
245+
dbDisplay = activeDatabaseName;
246+
}
247+
title = `tabularis - ${activeConnectionName} (${dbDisplay}${schemaSuffix})`;
248+
}
249+
await invoke('set_window_title', { title });
250+
} catch (e) {
251+
console.error('Failed to update window title', e);
252+
}
253+
};
254+
updateTitle();
255+
}, [activeTabId, activeTab?.schema, activeConnectionName, activeDatabaseName, activeSchema, activeCapabilities, isMultiDb, selectedDatabases]);
256+
232257
// Define updateActiveTab first to be used in handleQueryChange
233258
const updateActiveTab = useCallback(
234259
(partial: Partial<Tab>) => {
@@ -1677,7 +1702,14 @@ export const Editor = () => {
16771702
) : (
16781703
<FileCode size={12} className="text-green-500 shrink-0" />
16791704
)}
1680-
<span className="truncate flex-1">{tab.title}</span>
1705+
<span className="truncate flex-1 flex items-center gap-1">
1706+
<span className="truncate">{tab.title}</span>
1707+
{tab.type === "console" && isMultiDb && (
1708+
<span className="text-muted shrink-0">
1709+
({tab.schema || selectedDatabases[0]})
1710+
</span>
1711+
)}
1712+
</span>
16811713
<button
16821714
onClick={(e) => {
16831715
e.stopPropagation();
@@ -1699,7 +1731,7 @@ export const Editor = () => {
16991731
))}
17001732
</div>
17011733
<button
1702-
onClick={() => addTab({ type: "console" })}
1734+
onClick={() => addTab({ type: "console", ...(isMultiDb ? { schema: selectedDatabases[0] } : {}) })}
17031735
className="flex items-center justify-center w-9 h-full text-muted hover:text-white hover:bg-surface-secondary border-l border-default transition-colors shrink-0"
17041736
title={t("editor.newConsole")}
17051737
>
@@ -1813,7 +1845,6 @@ export const Editor = () => {
18131845
</button>
18141846
)}
18151847

1816-
18171848
<div className="relative ml-auto">
18181849
<button
18191850
onClick={() => setExportMenuOpen(!exportMenuOpen)}
@@ -1845,11 +1876,50 @@ export const Editor = () => {
18451876
</>
18461877
)}
18471878
</div>
1848-
<span className="text-xs text-muted ml-2">
1849-
{activeConnectionId
1850-
? t("editor.connected")
1851-
: t("editor.disconnected")}
1852-
</span>
1879+
{!isTableTab && isMultiDb && activeTab.type !== "query_builder" ? (
1880+
<div className="relative ml-2">
1881+
<button
1882+
onClick={() => setIsDbDropdownOpen((v) => !v)}
1883+
className="flex items-center gap-1.5 px-2 py-1 bg-surface-secondary border border-strong rounded text-xs text-primary hover:bg-surface transition-colors h-[30px]"
1884+
title={t("editor.activeDatabase")}
1885+
>
1886+
<Database size={12} className="text-muted shrink-0" />
1887+
<span className="max-w-[120px] truncate">{activeTab.schema || selectedDatabases[0]}</span>
1888+
<ChevronDown size={12} className="text-muted shrink-0" />
1889+
</button>
1890+
{isDbDropdownOpen && (
1891+
<>
1892+
<div className="fixed inset-0 z-40" onClick={() => setIsDbDropdownOpen(false)} />
1893+
<div className="absolute top-full right-0 mt-1 min-w-[140px] bg-surface-secondary border border-strong rounded shadow-xl z-50 flex flex-col py-1">
1894+
{selectedDatabases.map((db) => (
1895+
<button
1896+
key={db}
1897+
onClick={() => {
1898+
updateActiveTab({ schema: db });
1899+
setIsDbDropdownOpen(false);
1900+
}}
1901+
className={clsx(
1902+
"text-left px-3 py-1.5 text-xs hover:bg-surface transition-colors flex items-center gap-2",
1903+
(activeTab.schema || selectedDatabases[0]) === db
1904+
? "text-white font-medium"
1905+
: "text-secondary",
1906+
)}
1907+
>
1908+
<Database size={11} className="text-muted shrink-0" />
1909+
{db}
1910+
</button>
1911+
))}
1912+
</div>
1913+
</>
1914+
)}
1915+
</div>
1916+
) : (
1917+
<span className="text-xs text-muted ml-2">
1918+
{activeConnectionId
1919+
? t("editor.connected")
1920+
: t("editor.disconnected")}
1921+
</span>
1922+
)}
18531923
</div>
18541924

18551925
{/* Render all non-table tabs to prevent Monaco remounting */}

0 commit comments

Comments
 (0)