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
16 changes: 14 additions & 2 deletions admin/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import {ArrowUpFromDot, Download, ExternalLink, Plug, RefreshCw, Search, Trash,
import {IconButton} from "../components/IconButton.tsx";
import * as Dialog from "@radix-ui/react-dialog";

// Direction a sort starts in when it is picked from the dropdown: names run
// A to Z, while versions and dates start with the highest/newest first. The
// toggle button next to the dropdown still flips it.
const defaultSortDir: Record<SearchParams['sortBy'], SearchParams['sortDir']> = {
'name': 'asc',
'version': 'desc',
'last-updated': 'desc',
}

export const HomePage = () => {
const pluginsSocket = useStore(state => state.pluginsSocket)
const [plugins, setPlugins] = useState<PluginDef[]>([])
Expand Down Expand Up @@ -52,9 +61,12 @@ export const HomePage = () => {
return [...plugins].sort((a, b) => {
const dir = searchParams.sortDir === 'asc' ? 1 : -1
if (searchParams.sortBy === 'version') {
return a.version.localeCompare(b.version) * dir
// numeric so 10.0.0 sorts above 9.0.0
return (a.version ?? '').localeCompare(b.version ?? '', undefined, {numeric: true}) * dir
}
if (searchParams.sortBy === 'last-updated') {
// Plugins with no publish date go last whichever way the list runs.
if (!a.time || !b.time) return (a.time ? 0 : 1) - (b.time ? 0 : 1)
return a.time.localeCompare(b.time) * dir
}
return a.name.localeCompare(b.name) * dir
Expand Down Expand Up @@ -368,7 +380,7 @@ export const HomePage = () => {
setSearchParams({
...searchParams,
sortBy,
sortDir: 'asc',
sortDir: defaultSortDir[sortBy],
})
}}
>
Expand Down
88 changes: 81 additions & 7 deletions src/tests/frontend-new/admin-spec/admin_plugin_catalog.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect, test} from "@playwright/test";
import {expect, Page, test} from "@playwright/test";
import {loginToAdmin} from "../helper/adminhelper";

// #8246: the admin catalog used to offer every package in the plugin feed,
Expand All @@ -8,13 +8,13 @@ import {loginToAdmin} from "../helper/adminhelper";
// deliberately paired: the catalog must drop the broken plugin *and* keep
// listing the healthy ones, because a filter that empties the catalog would
// be a worse bug than the one it fixes.
test.beforeEach(async ({page}) => {
await loginToAdmin(page, 'admin', 'changeme1');
await page.goto('http://localhost:9001/admin/plugins');
await page.waitForSelector('.pm-search-input');
});

test.describe('Plugin catalog hygiene', () => {
test.beforeEach(async ({page}) => {
await loginToAdmin(page, 'admin', 'changeme1');
await page.goto('http://localhost:9001/admin/plugins');
await page.waitForSelector('.pm-search-input');
});

test('does not offer ep_adminpads2, which breaks the admin UI', async ({page}) => {
const pluginTable = page.locator('table tbody').first();
await expect(pluginTable).not.toBeEmpty({timeout: 60000});
Expand All @@ -37,3 +37,77 @@ test.describe('Plugin catalog hygiene', () => {
.toContainText('ep_align', {timeout: 60000});
});
});

// Picking a sort field starts it in the direction people expect: names A to Z,
// versions and "Last updated" highest/newest first. The live feed changes
// daily, so the search results are replaced with a fixture on the socket.
const NS = '/pluginfw/installer';
const PREFIX = `42${NS},`;

const sortFixture = [
{name: 'ep_sort_b', description: 'b', version: '9.0.0', time: '2026-01-15'},
{name: 'ep_sort_a', description: 'a', version: '10.0.0', time: '2026-11-20'},
{name: 'ep_sort_d', description: 'd', version: '11.0.0', time: ''},
{name: 'ep_sort_c', description: 'c', version: '2.0.0', time: '2025-06-01'},
];

const useSortFixture = async (page: Page) => {
await page.routeWebSocket(/\/socket\.io\//, (ws) => {
const server = ws.connectToServer();
ws.onMessage((msg) => server.send(msg));
server.onMessage((msg) => {
if (typeof msg === 'string' && msg.startsWith(PREFIX)) {
const m = /^(\d*)(\[[\s\S]*)$/.exec(msg.slice(PREFIX.length));
const payload = m && JSON.parse(m[2]);
if (payload && payload[0] === 'results:search') {
payload[1].results = sortFixture;
ws.send(`${PREFIX}${m![1]}${JSON.stringify(payload)}`);
return;
}
}
ws.send(msg);
});
});
};

const names = (page: Page) => page.locator('table tbody tr').evaluateAll(
(rows) => rows.map((r) => (r.textContent || '').match(/ep_sort_[a-z]/)?.[0]));

test.describe('Plugin catalog sorting', () => {
test.beforeEach(async ({page}) => {
await useSortFixture(page);
await loginToAdmin(page, 'admin', 'changeme1');
await page.goto('http://localhost:9001/admin/plugins');
await page.waitForSelector('.pm-search-input');
await expect(page.locator('table tbody tr')).toHaveCount(sortFixture.length, {timeout: 30000});
});

test('name sorts A to Z by default', async ({page}) => {
await expect.poll(() => names(page))
.toEqual(['ep_sort_a', 'ep_sort_b', 'ep_sort_c', 'ep_sort_d']);
await expect(page.locator('.pm-sort-dir')).toHaveText('↑');
});

test('last updated shows newest first, undated last, and the toggle reverses it', async ({page}) => {
await page.locator('select.pm-select').selectOption('last-updated');
await expect(page.locator('.pm-sort-dir')).toHaveText('↓');
await expect(page.locator('.pm-sort-dir')).toHaveAttribute('title', 'Sort descending');
await expect.poll(() => names(page))
.toEqual(['ep_sort_a', 'ep_sort_b', 'ep_sort_c', 'ep_sort_d']);

await page.locator('.pm-sort-dir').click();
await expect(page.locator('.pm-sort-dir')).toHaveText('↑');
await expect.poll(() => names(page))
.toEqual(['ep_sort_c', 'ep_sort_b', 'ep_sort_a', 'ep_sort_d']);
});

test('version shows highest first, compared numerically', async ({page}) => {
await page.locator('select.pm-select').selectOption('version');
await expect(page.locator('.pm-sort-dir')).toHaveText('↓');
await expect.poll(() => names(page))
.toEqual(['ep_sort_d', 'ep_sort_a', 'ep_sort_b', 'ep_sort_c']);

await page.locator('select.pm-select').selectOption('name');
await expect(page.locator('.pm-sort-dir')).toHaveText('↑');
});
});
Loading