diff --git a/frontend/src/components/TabManager.recent.test.ts b/frontend/src/components/TabManager.recent.test.ts index 9ebf1db6..f359472b 100644 --- a/frontend/src/components/TabManager.recent.test.ts +++ b/frontend/src/components/TabManager.recent.test.ts @@ -1,9 +1,12 @@ +import React from 'react'; +import { renderToStaticMarkup } from 'react-dom/server'; import { describe, expect, it } from 'vitest'; import { buildPinnedTableShortcuts, buildRecentConnectionShortcuts, buildRecentSQLFileShortcuts, + RecentConnectionShortcutItem, } from './TabManager'; import type { ExternalSQLDirectory, SavedConnection } from '../types'; @@ -20,6 +23,38 @@ const connection = (id: string, type: string): SavedConnection => ({ }); describe('recent workbench shortcuts', () => { + it('renders recent connections with the same database identity as the sidebar tree', () => { + const mysqlConnection = connection('mysql-1', 'mysql'); + const customizedConnection: SavedConnection = { + ...connection('customized-1', 'mysql'), + iconType: 'postgres', + iconColor: '#2f855a', + }; + const [mysqlShortcut, customizedShortcut] = buildRecentConnectionShortcuts([ + mysqlConnection, + customizedConnection, + ], [ + { connectionId: 'mysql-1', dbName: 'orders', openedAt: 2 }, + { connectionId: 'customized-1', dbName: 'reporting', openedAt: 1 }, + ]); + + const mysqlMarkup = renderToStaticMarkup(React.createElement(RecentConnectionShortcutItem, { + shortcut: mysqlShortcut, + onOpen: () => undefined, + })); + const customizedMarkup = renderToStaticMarkup(React.createElement(RecentConnectionShortcutItem, { + shortcut: customizedShortcut, + onOpen: () => undefined, + })); + + expect(mysqlMarkup).toContain('data-db-icon-frame="true"'); + expect(mysqlMarkup).toContain('/db-icons/mysql.svg'); + expect(customizedMarkup).toContain('/db-icons/postgres.svg'); + expect(customizedMarkup).toContain('#2f855a'); + expect(mysqlMarkup).not.toContain('anticon-database'); + expect(customizedMarkup).not.toContain('anticon-database'); + }); + it('only offers connections that can open the SQL query editor', () => { const shortcuts = buildRecentConnectionShortcuts([ connection('redis-1', 'redis'), diff --git a/frontend/src/components/TabManager.tsx b/frontend/src/components/TabManager.tsx index d6fa8efb..aacc273e 100644 --- a/frontend/src/components/TabManager.tsx +++ b/frontend/src/components/TabManager.tsx @@ -54,6 +54,8 @@ import { useWorkbenchTabs } from '../hooks/useWorkbenchTabs'; import { resolveConnectionEnvironmentPresentation } from '../utils/connectionEnvironment'; import { createSidebarResizeAwareFrameScheduler } from '../utils/sidebarResizeLifecycle'; import { QUERY_TAB_RENAME_REQUEST_EVENT } from '../utils/queryTabTitle'; +import { getDbIcon } from './DatabaseIcons'; +import { resolveConnectionAccentColor, resolveConnectionIconType } from '../utils/connectionVisual'; const getTabKindLabel = (tab: TabData): string => { if (tab.type === 'query') return t('tab_manager.kind_badge.query'); @@ -117,7 +119,7 @@ export const resolveV2WorkbenchTabWidth = (availableWidth: number, tabCount: num ); }; -type RecentConnectionShortcut = { +export type RecentConnectionShortcut = { connection: SavedConnection; dbName?: string; }; @@ -172,6 +174,28 @@ export const buildRecentConnectionShortcuts = ( return result; }; +export const RecentConnectionShortcutItem: React.FC<{ + shortcut: RecentConnectionShortcut; + onOpen: (shortcut: RecentConnectionShortcut) => void; +}> = ({ shortcut, onOpen }) => ( + +); + export const buildPinnedTableShortcuts = ( connections: SavedConnection[], pinnedTableKeys: string[], @@ -1573,19 +1597,11 @@ const TabManager: React.FC = React.memo(({ onF {recentConnectionShortcuts.length > 0 ? (
{recentConnectionShortcuts.map((shortcut) => ( - + shortcut={shortcut} + onOpen={handleOpenRecentConnection} + /> ))}
) : (