From 9ee2a4578fbd1f418110a5bf88f392a4eee51c12 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Wed, 24 Jan 2024 16:49:37 +0100 Subject: [PATCH] Add share button --- httpd-client/index.ts | 39 +---- httpd-client/lib/profile.ts | 36 ++++ httpd-client/lib/shared.ts | 34 +++- package-lock.json | 25 ++- package.json | 1 + src/components/IconSmall.svelte | 6 + src/config.json | 1 + src/lib/cache.ts | 21 +++ src/lib/config.ts | 2 + src/lib/projects.ts | 19 +++ src/lib/router.ts | 2 +- src/lib/utils.ts | 13 ++ src/views/projects/Commit.svelte | 21 ++- src/views/projects/Header/ShareButton.svelte | 160 ++++++++++++++++++ src/views/projects/History.svelte | 10 +- src/views/projects/Issue.svelte | 61 ++++--- src/views/projects/Issues.svelte | 12 +- src/views/projects/Patch.svelte | 62 ++++--- src/views/projects/Patches.svelte | 7 + src/views/projects/Share.svelte | 58 +++++++ src/views/projects/Sidebar.svelte | 16 +- src/views/projects/Source.svelte | 10 +- .../projects/Source/ProjectNameHeader.svelte | 8 +- src/views/projects/router.ts | 59 ++++++- tests/e2e/node.spec.ts | 4 +- tests/e2e/project/issues.spec.ts | 5 +- tests/support/fixtures.ts | 3 + 27 files changed, 569 insertions(+), 126 deletions(-) create mode 100644 httpd-client/lib/profile.ts create mode 100644 src/lib/cache.ts create mode 100644 src/views/projects/Header/ShareButton.svelte create mode 100644 src/views/projects/Share.svelte diff --git a/httpd-client/index.ts b/httpd-client/index.ts index ea5983a7a..e461b1d8a 100644 --- a/httpd-client/index.ts +++ b/httpd-client/index.ts @@ -34,12 +34,13 @@ import type { import type { RequestOptions } from "./lib/fetcher.js"; import type { ZodSchema } from "zod"; -import { z, array, boolean, literal, number, object, string, union } from "zod"; +import { z, array, literal, number, object, string, union } from "zod"; import * as project from "./lib/project.js"; +import * as profile from "./lib/profile.js"; import * as session from "./lib/session.js"; import { Fetcher } from "./lib/fetcher.js"; -import { successResponseSchema } from "./lib/shared.js"; +import { nodeConfigSchema, successResponseSchema } from "./lib/shared.js"; export type { BaseUrl, @@ -77,37 +78,7 @@ export type Node = z.infer; const nodeSchema = object({ id: string(), version: string(), - config: object({ - alias: string(), - peers: union([ - object({ type: literal("static") }), - object({ type: literal("dynamic"), target: number() }), - ]), - connect: array(string()), - externalAddresses: array(string()), - listen: array(string()), - network: union([literal("main"), literal("test")]), - relay: boolean(), - limits: object({ - routingMaxSize: number(), - routingMaxAge: number(), - fetchConcurrency: number(), - gossipMaxAge: number(), - maxOpenFiles: number(), - rate: object({ - inbound: object({ - fillRate: number(), - capacity: number(), - }), - outbound: object({ - fillRate: number(), - capacity: number(), - }), - }), - }), - policy: union([literal("allow"), literal("block")]), - scope: union([literal("followed"), literal("all")]), - }).nullable(), + config: nodeConfigSchema.nullable(), state: union([literal("running"), literal("stopped")]), }); @@ -158,6 +129,7 @@ export class HttpdClient { public baseUrl: BaseUrl; public project: project.Client; + public profile: profile.Client; public session: session.Client; public constructor(baseUrl: BaseUrl) { @@ -165,6 +137,7 @@ export class HttpdClient { this.#fetcher = new Fetcher(this.baseUrl); this.project = new project.Client(this.#fetcher); + this.profile = new profile.Client(this.#fetcher); this.session = new session.Client(this.#fetcher); } diff --git a/httpd-client/lib/profile.ts b/httpd-client/lib/profile.ts new file mode 100644 index 000000000..692a13060 --- /dev/null +++ b/httpd-client/lib/profile.ts @@ -0,0 +1,36 @@ +import type { Fetcher, RequestOptions } from "./fetcher.js"; +import type { z } from "zod"; + +import { array, boolean, object, string } from "zod"; +import { nodeConfigSchema } from "./shared.js"; + +const profileSchema = object({ + config: object({ + publicExplorer: string(), + preferredSeeds: array(string()), + cli: object({ hints: boolean() }), + node: nodeConfigSchema, + }), + home: string(), +}); + +export type Profile = z.infer; + +export class Client { + #fetcher: Fetcher; + + public constructor(fetcher: Fetcher) { + this.#fetcher = fetcher; + } + + public async getProfile(options?: RequestOptions): Promise { + return this.#fetcher.fetchOk( + { + method: "GET", + path: `profile`, + options, + }, + profileSchema, + ); + } +} diff --git a/httpd-client/lib/shared.ts b/httpd-client/lib/shared.ts index 34a501ffc..64827daaa 100644 --- a/httpd-client/lib/shared.ts +++ b/httpd-client/lib/shared.ts @@ -1,6 +1,6 @@ import type { ZodSchema } from "zod"; -import { literal, object } from "zod"; +import { array, boolean, literal, number, object, string, union } from "zod"; export interface SuccessResponse { success: true; @@ -9,3 +9,35 @@ export interface SuccessResponse { export const successResponseSchema = object({ success: literal(true), }) satisfies ZodSchema; + +export const nodeConfigSchema = object({ + alias: string(), + peers: union([ + object({ type: literal("static") }), + object({ type: literal("dynamic"), target: number() }), + ]), + listen: array(string()), + connect: array(string()), + externalAddresses: array(string()), + network: union([literal("main"), literal("test")]), + relay: boolean(), + limits: object({ + routingMaxSize: number(), + routingMaxAge: number(), + fetchConcurrency: number(), + gossipMaxAge: number(), + maxOpenFiles: number(), + rate: object({ + inbound: object({ + fillRate: number(), + capacity: number(), + }), + outbound: object({ + fillRate: number(), + capacity: number(), + }), + }), + }), + policy: union([literal("allow"), literal("block")]), + scope: union([literal("followed"), literal("all")]), +}); diff --git a/package-lock.json b/package-lock.json index 3aa6ddf9c..d3e7660f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "hast-util-to-dom": "^4.0.0", "hast-util-to-html": "^9.0.0", "lodash": "^4.17.21", + "lru-cache": "^10.1.0", "marked": "^10.0.0", "marked-katex-extension": "^4.0.4", "marked-linkify-it": "^3.1.6", @@ -3199,15 +3200,11 @@ } }, "node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.1.0.tgz", + "integrity": "sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag==", "engines": { - "node": ">=10" + "node": "14 || >=16.14" } }, "node_modules/magic-string": { @@ -4215,6 +4212,18 @@ "node": ">=10" } }, + "node_modules/semver/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", diff --git a/package.json b/package.json index 56399052a..ec19df51d 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "hast-util-to-dom": "^4.0.0", "hast-util-to-html": "^9.0.0", "lodash": "^4.17.21", + "lru-cache": "^10.1.0", "marked": "^10.0.0", "marked-katex-extension": "^4.0.4", "marked-linkify-it": "^3.1.6", diff --git a/src/components/IconSmall.svelte b/src/components/IconSmall.svelte index 4568f4a55..ce95d6aa5 100644 --- a/src/components/IconSmall.svelte +++ b/src/components/IconSmall.svelte @@ -41,6 +41,7 @@ | "home" | "issue" | "key" + | "link" | "lock" | "logo" | "menu" @@ -351,6 +352,11 @@ d="M7.077 8a.923.923 0 101.846 0 .923.923 0 00-1.846 0z" clip-rule="evenodd"> + {:else if name === "link"} + {:else if name === "logo"} diff --git a/src/config.json b/src/config.json index 12894c7b0..4067b9fc9 100644 --- a/src/config.json +++ b/src/config.json @@ -1,5 +1,6 @@ { "nodes": { + "fallbackPublicExplorer": "https://app.radicle.xyz/nodes/$host/$rid$path", "defaultHttpdPort": 443, "defaultLocalHttpdPort": 8080, "defaultHttpdScheme": "https", diff --git a/src/lib/cache.ts b/src/lib/cache.ts new file mode 100644 index 000000000..4be20b98f --- /dev/null +++ b/src/lib/cache.ts @@ -0,0 +1,21 @@ +import { LRUCache } from "lru-cache"; + +export function cached( + f: (...args: Args) => Promise, + makeKey: (...args: Args) => string, + options?: LRUCache.Options, +): (...args: Args) => Promise { + const cache = new LRUCache(options || { max: 500 }); + return async function (...args: Args): Promise { + const key = makeKey(...args); + const cached = cache.get(key); + + if (cached === undefined) { + const value = await f(...args); + cache.set(key, { value }); + return value; + } else { + return cached.value; + } + }; +} diff --git a/src/lib/config.ts b/src/lib/config.ts index d2815317c..2db2f8c82 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -4,6 +4,7 @@ import configJson from "@app/config.json"; export interface Config { nodes: { + fallbackPublicExplorer: string; defaultHttpdPort: number; defaultLocalHttpdPort: number; defaultNodePort: number; @@ -23,6 +24,7 @@ function getConfig(): Config { if (window.VITEST) { return { nodes: { + fallbackPublicExplorer: "https://app.radicle.xyz/nodes/$host/$rid$path", defaultHttpdPort: 8081, defaultLocalHttpdPort: 8081, defaultHttpdScheme: "http", diff --git a/src/lib/projects.ts b/src/lib/projects.ts index 922672835..4e700786a 100644 --- a/src/lib/projects.ts +++ b/src/lib/projects.ts @@ -2,6 +2,7 @@ import type { BaseUrl, Project } from "@httpd-client"; import { HttpdClient } from "@httpd-client"; import { isFulfilled } from "@app/lib/utils"; +import { cached } from "./cache"; export interface ProjectBaseUrl { project: Project; @@ -23,3 +24,21 @@ export async function getProjectsFromNodes( const results = await Promise.allSettled(projectPromises); return results.filter(isFulfilled).map(r => r.value); } + +export const cacheQueryProject = cached( + queryProject, + (baseUrl: BaseUrl, projectId: string) => + JSON.stringify({ baseUrl, projectId }), + { max: 200, ttl: 60 * 60 * 1000 }, +); + +async function queryProject( + baseUrl: BaseUrl, + projectId: string, +): Promise<"found" | "notFound"> { + const httpd = new HttpdClient(baseUrl); + return await httpd.project + .getById(projectId) + .then<"found">(() => "found") + .catch(() => "notFound"); +} diff --git a/src/lib/router.ts b/src/lib/router.ts index 7b81c037b..93cb7cdd6 100644 --- a/src/lib/router.ts +++ b/src/lib/router.ts @@ -189,7 +189,7 @@ function extractBaseUrl(hostAndPort: string): BaseUrl { } } -function urlToRoute(url: URL): Route | null { +export function urlToRoute(url: URL): Route | null { const segments = url.pathname.substring(1).split("/"); const resource = segments.shift(); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index b21a3e12f..5b8c9b8fa 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -93,6 +93,19 @@ export function formatEditedCaption(lastEdit: Comment["edits"][0]) { } edited ${formatTimestamp(lastEdit.timestamp / 1000)}`; } +// Generates a publicly shareable link. +export function formatPublicExplorer( + publicExplorer: string, + host: string, + rid: string, + fullPath: string, +) { + return publicExplorer + .replace("$host", host) + .replace("$rid", rid) + .replace("$path", fullPath.replace(`/nodes/${host}/${rid}`, "")); +} + // Takes a path, eg. "../images/image.png", and a base from where to start resolving, e.g. "static/images/index.html". // Returns the resolved path. export function canonicalize( diff --git a/src/views/projects/Commit.svelte b/src/views/projects/Commit.svelte index 263f4e699..01860b6db 100644 --- a/src/views/projects/Commit.svelte +++ b/src/views/projects/Commit.svelte @@ -7,10 +7,13 @@ import CommitAuthorship from "@app/views/projects/Commit/CommitAuthorship.svelte"; import InlineMarkdown from "@app/components/InlineMarkdown.svelte"; import Layout from "./Layout.svelte"; + import Share from "./Share.svelte"; export let baseUrl: BaseUrl; export let commit: Commit; export let project: Project; + export let preferredSeeds: string[]; + export let publicExplorer: string; $: header = commit.commit; @@ -20,10 +23,15 @@ background-color: var(--color-background-float); } .header { - padding: 0 1rem 1rem 1rem; + padding: 1rem; border-radius: var(--border-radius-small); border-bottom: 1px solid var(--color-border-hint); } + .title { + display: flex; + justify-content: space-between; + align-items: center; + } .description { font-family: var(--font-family-monospace); white-space: pre-wrap; @@ -35,13 +43,20 @@
- + + + + {formatCommit(header.id)}
{#if header.description} -
{header.description}
{/if} +
{header.description}
+ {/if}
+ import type { ProjectRoute } from "@app/views/projects/router"; + + import { cacheQueryProject } from "@app/lib/projects"; + import { config } from "@app/lib/config"; + import { formatPublicExplorer } from "@app/lib/utils"; + import { routeToPath, urlToRoute } from "@app/lib/router"; + + import Clipboard from "@app/components/Clipboard.svelte"; + import Command from "@app/components/Command.svelte"; + import IconSmall from "@app/components/IconSmall.svelte"; + import Loading from "@app/components/Loading.svelte"; + + export let preferredSeeds: string[]; + export let publicExplorer: string; + + let usedFallbackSeed = false; + + const route = urlToRoute(new URL(window.location.href)) as ProjectRoute; + const seedRoutes = preferredSeeds.reduce((acc, seed) => { + const [, address] = seed.split("@"); + acc.push({ + ...route, + node: { + hostname: address.split(":")[0], + port: config.nodes.defaultHttpdPort, + scheme: config.nodes.defaultHttpdScheme, + }, + }); + return acc; + }, []); + + // Set seed.radicle.garden as fallback seed. + $: if (preferredSeeds.length === 0) { + usedFallbackSeed = true; + seedRoutes.push({ + ...route, + node: { + hostname: "seed.radicle.garden", + port: config.nodes.defaultHttpdPort, + scheme: config.nodes.defaultHttpdScheme, + }, + }); + } + + + + + diff --git a/src/views/projects/History.svelte b/src/views/projects/History.svelte index fe7922a86..13bc07f1c 100644 --- a/src/views/projects/History.svelte +++ b/src/views/projects/History.svelte @@ -31,6 +31,8 @@ export let totalCommitCount: number; export let tree: Tree; export let seeding: boolean; + export let preferredSeeds: string[]; + export let publicExplorer: string; const api = new HttpdClient(baseUrl); @@ -109,7 +111,13 @@ - +
string; const api = new HttpdClient(baseUrl); @@ -477,28 +480,42 @@
- {#if issueState !== "read"} - - {:else if !issue.title} - No title - {:else} -
- -
- {/if} - {#if session && role.isDelegateOrAuthor(session.publicKey, project.delegates, issue.author.id) && issueState === "read"} - (issueState = "edit")}> - - - {/if} +
+ {#if issueState !== "read"} + + {:else if !issue.title} + No title + {:else} +
+ +
+ {/if} + {#if session && role.isDelegateOrAuthor(session.publicKey, project.delegates, issue.author.id) && issueState === "read"} + (issueState = "edit")}> + + + {/if} +
+
+ + {#if session && role.isDelegateOrAuthor(session.publicKey, project.delegates, issue.author.id)} + !isEqual(state, issue.state), + )} + {selectedItem} + state={issue.state} + save={partial(saveStatus, session.id)} /> + {/if} +
{#if issue.state.status === "open"} diff --git a/src/views/projects/Issues.svelte b/src/views/projects/Issues.svelte index 2704f0ebc..7f0763a84 100644 --- a/src/views/projects/Issues.svelte +++ b/src/views/projects/Issues.svelte @@ -20,11 +20,14 @@ import Loading from "@app/components/Loading.svelte"; import Placeholder from "@app/components/Placeholder.svelte"; import Popover from "@app/components/Popover.svelte"; + import Share from "./Share.svelte"; export let baseUrl: BaseUrl; export let issues: Issue[]; export let project: Project; export let state: IssueState["status"]; + export let preferredSeeds: string[]; + export let publicExplorer: string; let loading = false; let page = 0; @@ -143,8 +146,9 @@ - {#if $httpdStore.state === "authenticated" && isLocal(baseUrl.hostname)} -
+
+ + {#if $httpdStore.state === "authenticated" && isLocal(baseUrl.hostname)} -
- {/if} + {/if} +
diff --git a/src/views/projects/Patch.svelte b/src/views/projects/Patch.svelte index 8b428bb9c..d6f214ac5 100644 --- a/src/views/projects/Patch.svelte +++ b/src/views/projects/Patch.svelte @@ -77,12 +77,15 @@ import Radio from "@app/components/Radio.svelte"; import RevisionComponent from "@app/views/projects/Cob/Revision.svelte"; import TextInput from "@app/components/TextInput.svelte"; + import Share from "./Share.svelte"; export let baseUrl: BaseUrl; export let patch: Patch; export let rawPath: (commit?: string) => string; export let project: Project; export let view: PatchView; + export let preferredSeeds: string[]; + export let publicExplorer: string; $: api = new HttpdClient(baseUrl); @@ -661,27 +664,37 @@
- {#if patchState !== "read"} - - {:else if !patch.title} - No title - {:else} -
- -
- {/if} - {#if session && role.isDelegateOrAuthor(session.publicKey, project.delegates, patch.author.id) && patchState === "read"} - (patchState = "edit")}> - - +
+ {#if patchState !== "read"} + + {:else if !patch.title} + No title + {:else} +
+ +
+ {/if} + {#if session && role.isDelegateOrAuthor(session.publicKey, project.delegates, patch.author.id) && patchState === "read"} + (patchState = "edit")}> + + + {/if} +
+ + {#if session && role.isDelegateOrAuthor(session.publicKey, project.delegates, patch.author.id) && view.name === "activity"} + !isEqual(state, patch.state))} + {selectedItem} + state={patch.state} + save={partial(saveStatus, session.id)} /> {/if}
@@ -778,13 +791,6 @@
- {#if session && role.isDelegateOrAuthor(session.publicKey, project.delegates, patch.author.id) && view.name === "activity"} - !isEqual(state, patch.state))} - {selectedItem} - state={patch.state} - save={partial(saveStatus, session.id)} /> - {/if} {#if view.name === "changes"}
+ +
+ +
diff --git a/src/views/projects/Share.svelte b/src/views/projects/Share.svelte new file mode 100644 index 000000000..37926150d --- /dev/null +++ b/src/views/projects/Share.svelte @@ -0,0 +1,58 @@ + + +{#if $httpdStore.state !== "stopped" && isLocal(baseUrl.hostname)} + + + + +{:else} + +{/if} diff --git a/src/views/projects/Sidebar.svelte b/src/views/projects/Sidebar.svelte index f693d3fcf..8878b708f 100644 --- a/src/views/projects/Sidebar.svelte +++ b/src/views/projects/Sidebar.svelte @@ -2,9 +2,8 @@ import type { ActiveTab } from "./Header.svelte"; import type { BaseUrl, Project } from "@httpd-client"; - import { ResponseError } from "@httpd-client/lib/fetcher"; - - import { api, httpdStore } from "@app/lib/httpd"; + import { cacheQueryProject } from "@app/lib/projects"; + import { httpdStore } from "@app/lib/httpd"; import { isLocal } from "@app/lib/utils"; import { onMount } from "svelte"; @@ -43,7 +42,7 @@ httpdStore.subscribe(async () => { if ($httpdStore.state !== "stopped" && !queryingLocalProject) { - await detectLocalProject(); + await cacheQueryProject(baseUrl, project.id); } }); @@ -64,14 +63,7 @@ async function detectLocalProject(): Promise { queryingLocalProject = true; - localProject = await api.project - .getById(project.id) - .then<"found">(() => "found") - .catch((error: unknown) => - error instanceof ResponseError && error.status === 404 - ? "notFound" - : undefined, - ); + localProject = await cacheQueryProject(baseUrl, project.id); queryingLocalProject = false; } diff --git a/src/views/projects/Source.svelte b/src/views/projects/Source.svelte index 26062aa46..4510bad3a 100644 --- a/src/views/projects/Source.svelte +++ b/src/views/projects/Source.svelte @@ -25,6 +25,8 @@ export let revision: string | undefined; export let tree: Tree; export let seeding: boolean; + export let preferredSeeds: string[]; + export let publicExplorer: string; let mobileFileTree = false; @@ -111,7 +113,13 @@ - +
+ string; blobResult: BlobResult; seeding: boolean; + preferredSeeds: string[]; + publicExplorer: string; }; } | { @@ -132,6 +135,8 @@ export type ProjectLoadedRoute = commitHeaders: CommitHeader[]; totalCommitCount: number; seeding: boolean; + preferredSeeds: string[]; + publicExplorer: string; }; } | { @@ -140,6 +145,8 @@ export type ProjectLoadedRoute = baseUrl: BaseUrl; project: Project; commit: Commit; + preferredSeeds: string[]; + publicExplorer: string; }; } | { @@ -149,6 +156,8 @@ export type ProjectLoadedRoute = project: Project; rawPath: (commit?: string) => string; issue: Issue; + preferredSeeds: string[]; + publicExplorer: string; }; } | { @@ -158,6 +167,8 @@ export type ProjectLoadedRoute = project: Project; issues: Issue[]; state: IssueState["status"]; + preferredSeeds: string[]; + publicExplorer: string; }; } | { @@ -175,6 +186,8 @@ export type ProjectLoadedRoute = project: Project; patches: Patch[]; state: PatchState["status"]; + preferredSeeds: string[]; + publicExplorer: string; }; } | { @@ -185,6 +198,8 @@ export type ProjectLoadedRoute = rawPath: (commit?: string) => string; patch: Patch; view: PatchView; + preferredSeeds: string[]; + publicExplorer: string; }; }; @@ -269,7 +284,8 @@ export async function loadProjectRoute( } else if (route.resource === "project.history") { return await loadHistoryView(route); } else if (route.resource === "project.commit") { - const [project, commit] = await Promise.all([ + const [profile, project, commit] = await Promise.all([ + api.profile.getProfile().catch(() => undefined), api.project.getById(route.project), api.project.getCommitBySha(route.project, route.commit), ]); @@ -280,10 +296,15 @@ export async function loadProjectRoute( baseUrl: route.node, project, commit, + preferredSeeds: profile?.config.preferredSeeds || [], + publicExplorer: + profile?.config.publicExplorer || + config.nodes.fallbackPublicExplorer, }, }; } else if (route.resource === "project.issue") { - const [project, issue] = await Promise.all([ + const [profile, project, issue] = await Promise.all([ + api.profile.getProfile().catch(() => undefined), api.project.getById(route.project), api.project.getIssueById(route.project, route.issue), ]); @@ -294,6 +315,10 @@ export async function loadProjectRoute( project, rawPath, issue, + preferredSeeds: profile?.config.preferredSeeds || [], + publicExplorer: + profile?.config.publicExplorer || + config.nodes.fallbackPublicExplorer, }, }; } else if (route.resource === "project.patch") { @@ -355,7 +380,8 @@ async function loadPatchesView( const searchParams = new URLSearchParams(route.search || ""); const state = (searchParams.get("state") as PatchState["status"]) || "open"; - const [project, patches] = await Promise.all([ + const [profile, project, patches] = await Promise.all([ + api.profile.getProfile().catch(() => undefined), api.project.getById(route.project), api.project.getAllPatches(route.project, { state, @@ -371,6 +397,9 @@ async function loadPatchesView( patches, state, project, + preferredSeeds: profile?.config.preferredSeeds || [], + publicExplorer: + profile?.config.publicExplorer || config.nodes.fallbackPublicExplorer, }, }; } @@ -381,7 +410,8 @@ async function loadIssuesView( const api = new HttpdClient(route.node); const state = route.state || "open"; - const [project, issues] = await Promise.all([ + const [profile, project, issues] = await Promise.all([ + api.profile.getProfile().catch(() => undefined), api.project.getById(route.project), api.project.getAllIssues(route.project, { state, @@ -398,6 +428,9 @@ async function loadIssuesView( issues, state, project, + preferredSeeds: profile?.config.preferredSeeds || [], + publicExplorer: + profile?.config.publicExplorer || config.nodes.fallbackPublicExplorer, }, }; } @@ -411,7 +444,8 @@ async function loadTreeView( route.project }${commit ? `/${commit}` : ""}`; - const [project, peers, branchMap, seeding] = await Promise.all([ + const [profile, project, peers, branchMap, seeding] = await Promise.all([ + api.profile.getProfile().catch(() => undefined), api.project.getById(route.project), api.project.getAllRemotes(route.project), getPeerBranches(api, route.project, route.peer), @@ -453,6 +487,9 @@ async function loadTreeView( path, blobResult, seeding, + preferredSeeds: profile?.config.preferredSeeds || [], + publicExplorer: + profile?.config.publicExplorer || config.nodes.fallbackPublicExplorer, }, }; } @@ -502,7 +539,8 @@ async function loadHistoryView( ): Promise { const api = new HttpdClient(route.node); - const [project, peers, branchMap] = await Promise.all([ + const [profile, project, peers, branchMap] = await Promise.all([ + api.profile.getProfile().catch(() => undefined), api.project.getById(route.project), api.project.getAllRemotes(route.project), getPeerBranches(api, route.project, route.peer), @@ -546,6 +584,9 @@ async function loadHistoryView( commitHeaders: commitsResponse.commits.map(c => c.commit), totalCommitCount: commitsResponse.stats.commits, seeding, + preferredSeeds: profile?.config.preferredSeeds || [], + publicExplorer: + profile?.config.publicExplorer || config.nodes.fallbackPublicExplorer, }, }; } @@ -558,7 +599,8 @@ async function loadPatchView( `${route.node.scheme}://${route.node.hostname}:${route.node.port}/raw/${ route.project }${commit ? `/${commit}` : ""}`; - const [project, patch] = await Promise.all([ + const [profile, project, patch] = await Promise.all([ + api.profile.getProfile().catch(() => undefined), api.project.getById(route.project), api.project.getPatchById(route.project, route.patch), ]); @@ -615,6 +657,9 @@ async function loadPatchView( rawPath, patch, view, + preferredSeeds: profile?.config.preferredSeeds || [], + publicExplorer: + profile?.config.publicExplorer || config.nodes.fallbackPublicExplorer, }, }; } diff --git a/tests/e2e/node.spec.ts b/tests/e2e/node.spec.ts index 2efd380ac..625493075 100644 --- a/tests/e2e/node.spec.ts +++ b/tests/e2e/node.spec.ts @@ -60,8 +60,8 @@ test("seeding projects", async ({ page, authenticatedPeer }) => { await page.goto(authenticatedPeer.ridUrl(rid)); await page.getByRole("button", { name: "Seeding" }).click(); - await expect(page.getByRole("button", { name: "Seed" })).toBeVisible(); + await expect(page.getByRole("button", { name: "Seed 1" })).toBeVisible(); - await page.getByRole("button", { name: "Seed" }).click(); + await page.getByRole("button", { name: "Seed 1" }).click(); await expect(page.getByRole("button", { name: "Seeding" })).toBeVisible(); }); diff --git a/tests/e2e/project/issues.spec.ts b/tests/e2e/project/issues.spec.ts index 1ae3ba692..e1cf308e4 100644 --- a/tests/e2e/project/issues.spec.ts +++ b/tests/e2e/project/issues.spec.ts @@ -49,7 +49,10 @@ test("issue counters", async ({ page, authenticatedPeer }) => { await page .getByRole("link", { name: "First issue to test counters" }) .click(); - await page.getByRole("button", { name: "Close issue as solved" }).click(); + await page + .getByRole("button", { name: "Close issue as solved" }) + .first() + .click(); await expect(page.getByRole("button", { name: "Issues 1" })).toBeVisible(); }); diff --git a/tests/support/fixtures.ts b/tests/support/fixtures.ts index f6e7e2b8c..95337e603 100644 --- a/tests/support/fixtures.ts +++ b/tests/support/fixtures.ts @@ -71,6 +71,8 @@ export const test = base.extend<{ await page.addInitScript(() => { window.APP_CONFIG = { nodes: { + fallbackPublicExplorer: + "https://app.radicle.xyz/nodes/$host/$rid$path", defaultHttpdPort: 8081, defaultLocalHttpdPort: 8081, defaultHttpdScheme: "http", @@ -196,6 +198,7 @@ function log(text: string, label: string, outputLog: Stream.Writable) { export function appConfigWithFixture(defaultLocalHttpdPort = 8081) { window.APP_CONFIG = { nodes: { + fallbackPublicExplorer: "https://app.radicle.xyz/nodes/$host/$rid$path", defaultHttpdPort: 8081, defaultLocalHttpdPort: defaultLocalHttpdPort, defaultHttpdScheme: "http",