Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions packages/web-ui/src/pages/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {useConnectionCapabilities} from '@/hooks/useConnectionCapabilities';
import {useAvailableUpdates} from '@/hooks/useAvailableUpdates';
import {UpdateBadge} from '@/components/ui/UpdateBadge';
import {UpdateTooltip} from '@/components/ui/UpdateTooltip';
import {Chip} from '@/components/ui/Chip';
import type {DeprecationInfo} from '@/types/plugins';

type SettingsTab =
| 'general'
Expand Down Expand Up @@ -159,7 +161,10 @@ export const Settings = () => {
[refreshDrivers],
);

const pluginSettingItems = new Map<string, {id: string; name: string}>();
const pluginSettingItems = new Map<
string,
{id: string; name: string; deprecated?: DeprecationInfo}
>();

for (const driver of allDrivers) {
const hasSettings = (driver.settings?.length ?? 0) > 0;
Expand All @@ -168,6 +173,7 @@ export const Settings = () => {
pluginSettingItems.set(driver.id, {
id: driver.id,
name: driver.name,
deprecated: driver.deprecated,
});
}

Expand Down Expand Up @@ -259,19 +265,44 @@ export const Settings = () => {
<div className="pl-4 space-y-0.5">
{pluginTabs.map((plugin) => {
const pluginTabId = `plugin:${plugin.id}` as const;
const deprecation = plugin.deprecated;
const deprecatedTitle = deprecation
? deprecation.removal_date
? t('settings.plugins.deprecatedTooltipDate', {
replacement: deprecation.replacement_id ?? '',
date: deprecation.removal_date,
})
: t('settings.plugins.deprecatedTooltip', {
replacement: deprecation.replacement_id ?? '',
})
: undefined;
return (
<button
key={plugin.id}
onClick={() => setRequestedTab(pluginTabId)}
className={clsx(
'w-full px-3 py-1.5 rounded-lg text-xs text-left transition-colors truncate',
'w-full px-3 py-1.5 rounded-lg text-xs text-left transition-colors',
deprecation
? 'flex items-center gap-1.5'
: 'truncate',
activeTab === pluginTabId
? 'bg-surface-secondary text-primary'
: 'text-muted hover:text-primary hover:bg-surface-secondary/50',
)}
title={plugin.name}
title={deprecatedTitle ?? plugin.name}
>
{plugin.name}
{deprecation ? (
<>
<span className="truncate">
{plugin.name}
</span>
<Chip tone="warning" size="sm">
{t('settings.plugins.deprecated')}
</Chip>
</>
) : (
plugin.name
)}
</button>
);
})}
Expand Down
92 changes: 82 additions & 10 deletions packages/web-ui/tests/pages/Settings.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {StrictMode} from 'react';
import {act, fireEvent, render, screen, waitFor, within} from '@testing-library/react';
import {MemoryRouter, Route, Routes, useSearchParams} from 'react-router-dom';
import {beforeEach, describe, expect, it, vi} from 'vitest';
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
import {createInstance} from 'i18next';
import en from '@/i18n/locales/en.json';
import itLocale from '@/i18n/locales/it.json';
Expand Down Expand Up @@ -34,17 +34,25 @@ vi.mock('@/hooks/useUpdate', () => ({useUpdate: vi.fn()}));
vi.mock('@/hooks/useSettings', () => ({
useSettings: () => ({settings: {}, isLoading: false, updateSetting: vi.fn()}),
}));
const driversMock = vi.hoisted(() => {
const defaultDrivers = [
{
id: 'mysql',
name: 'MySQL',
is_builtin: true,
settings: [{key: 'pool'}],
},
];
return {
defaultDrivers,
allDrivers: defaultDrivers as Array<Record<string, unknown>>,
installedPlugins: [] as Array<Record<string, unknown>>,
};
});
vi.mock('@/hooks/useDrivers', () => ({
useDrivers: () => ({
allDrivers: [
{
id: 'mysql',
name: 'MySQL',
is_builtin: true,
settings: [{key: 'pool'}],
},
],
installedPlugins: [],
allDrivers: driversMock.allDrivers,
installedPlugins: driversMock.installedPlugins,
refresh: vi.fn(),
}),
}));
Expand Down Expand Up @@ -380,3 +388,67 @@ describe('managed connections', () => {
expect(screen.getByText('SshTab')).toBeInTheDocument();
});
});

describe('plugin sidebar with a deprecated built-in driver', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(usePluginRegistry).mockReturnValue({
plugins: [],
updates: [],
loading: false,
error: null,
refresh: vi.fn(),
});
vi.mocked(useUpdate).mockReturnValue({
updateInfo: null,
availableUpdate: null,
isChecking: false,
isDownloading: false,
downloadProgress: 0,
checkForUpdates: vi.fn(),
downloadAndInstall: vi.fn(),
dismissUpdate: vi.fn(),
error: null,
isUpToDate: true,
installationSource: null,
});
driversMock.allDrivers = [
...driversMock.defaultDrivers,
{
id: 'postgres',
name: 'PostgreSQL',
is_builtin: true,
settings: [{key: 'pool'}],
deprecated: {replacement_id: 'postgresql', removal_date: '2026-10-05'},
},
{id: 'postgresql', name: 'PostgreSQL', is_builtin: false, settings: []},
];
driversMock.installedPlugins = [{id: 'postgresql', name: 'PostgreSQL'}];
});

afterEach(() => {
driversMock.allDrivers = driversMock.defaultDrivers;
driversMock.installedPlugins = [];
});

it('marks the deprecated built-in entry so it can be told apart from its plugin replacement', () => {
renderApp();

const entries = screen.getAllByRole('button', {name: /^PostgreSQL/});
expect(entries).toHaveLength(2);
const [builtin, replacement] = entries;
expect(builtin).toHaveTextContent('Deprecato');
expect(builtin).toHaveAttribute(
'title',
expect.stringContaining('viene sostituito dal plugin postgresql'),
);
expect(replacement).toHaveAccessibleName('PostgreSQL');
expect(replacement).not.toHaveTextContent('Deprecato');
});

it('leaves non-deprecated entries unchanged', () => {
renderApp();

expect(screen.getByRole('button', {name: 'MySQL'})).not.toHaveTextContent('Deprecato');
});
});