From f4bf5b9c6ad7eb6472a7273d377ba431ff7b8a6a Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 26 Jul 2023 17:44:10 +0200 Subject: [PATCH] Sort projects in seed view by most recent activity Uses the projects activity, fetched from `/projects/${id}/activity` which is an array of commit timestamps. So could suffer from some errors if commits with non current timestamps are being used. Signed-off-by: Sebastian Martinez --- src/views/seeds/router.ts | 6 +++++- tests/visual/seed.spec.ts | 17 ----------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/views/seeds/router.ts b/src/views/seeds/router.ts index c7317a791..508dd96dc 100644 --- a/src/views/seeds/router.ts +++ b/src/views/seeds/router.ts @@ -58,10 +58,14 @@ export async function loadProjects( }; }), ); + // Sorts projects by most recent commit descending. + const sortedProjects = results.sort( + (a, b) => b.activity[0].time - a.activity[0].time, + ); return { total: nodeStats.projects.count, - projects: results, + projects: sortedProjects, }; } diff --git a/tests/visual/seed.spec.ts b/tests/visual/seed.spec.ts index 4223325f1..fcfb9218c 100644 --- a/tests/visual/seed.spec.ts +++ b/tests/visual/seed.spec.ts @@ -1,4 +1,3 @@ -import type { Project } from "@httpd-client"; import { test, expect } from "@tests/support/fixtures.js"; test("seed page", async ({ page }) => { @@ -12,22 +11,6 @@ test("seed page", async ({ page }) => { }; }); - // Repos in heartwood are read from storage with `fs::read_dir` - // which has no deterministic ordering, it depends on - // the filesystem and the operating system. - // - // > The order in which this iterator returns entries is platform and filesystem dependent. - // source: https://doc.rust-lang.org/std/fs/fn.read_dir.html - // - // So we sort the request here, to get a visually persistent listing. - // TODO: If at some point project sorting is introduced we can probably remove this. - await page.route("**/api/v1/projects?page=0&perPage=10", async route => { - const response = await route.fetch(); - const json: Project[] = await response.json(); - json.sort((a, b) => a.name.localeCompare(b.name)); - await route.fulfill({ response, json }); - }); - await page.goto("/seeds/radicle.local", { waitUntil: "networkidle" }); await expect(page).toHaveScreenshot(); });