diff --git a/apps/web/src/lab/sources-integrations-fixture.ts b/apps/web/src/lab/sources-integrations-fixture.ts index f6302d3263..bd32709a22 100644 --- a/apps/web/src/lab/sources-integrations-fixture.ts +++ b/apps/web/src/lab/sources-integrations-fixture.ts @@ -1,6 +1,6 @@ -import { CloudflareIntegrationStatus } from "@maple/domain/http" +import { CloudflareIntegrationStatus, GithubIntegrationStatus } from "@maple/domain/http" import { V2PlanetScaleIntegration, V2PlanetScaleOrganizationList } from "@maple/domain/http/v2" -import { Result, Schema, Array as Arr } from "effect" +import { Result, Schema, Array as Arr, String as Str } from "effect" import type { PageContext } from "../page/contract" import { Message as IntegrationsMessage } from "../page/integrations/message" import type { Model as IntegrationsModel } from "../page/integrations/model" @@ -12,11 +12,29 @@ import { init as newInit, update as newUpdate } from "../page/sources/new/update import { AppRoute } from "../route" import type * as Policy from "@maple/domain/policy" -// `/lab/sources?page=cloudflare|planetscale` (the connect flow one step after Connect) and -// `cloudflare-card|planetscale-card` (the connected integration's card), over fixture statuses. +// `/lab/sources?page=cloudflare|planetscale|github` (the connect flow one step after Connect), +// `-live` (its Go live step) and `cloudflare-card|planetscale-card` (the connected +// integration's card), over fixture statuses. -export const INTEGRATION_PAGES = ["cloudflare", "planetscale", "cloudflare-card", "planetscale-card"] as const +export const INTEGRATION_PAGES = [ + "cloudflare", + "planetscale", + "github", + "cloudflare-live", + "planetscale-live", + "github-live", + "cloudflare-card", + "planetscale-card", +] as const export type IntegrationLabPage = (typeof INTEGRATION_PAGES)[number] +type LabIntegration = "cloudflare" | "planetscale" | "github" + +const integrationOf = (page: IntegrationLabPage): LabIntegration => + Str.startsWith("cloudflare")(page) + ? "cloudflare" + : Str.startsWith("planetscale")(page) + ? "planetscale" + : "github" const NOW = Date.UTC(2026, 10, 6, 12) @@ -87,25 +105,78 @@ const PLANETSCALE = Schema.decodeSync(V2PlanetScaleIntegration)({ expires_at: null, }) +const REPOS = [ + "hazel", + "maple-ui-parity", + "terraform-provider-maple", + "changesets", + "maple-render", + "maple-cost", + "maple", + "effect-orm", + "pulumi-maple", + "maple-portal", + "trace-capture", + "gtm", +] + +/** Every granted repository synced. */ +const GITHUB = Schema.decodeSync(GithubIntegrationStatus)({ + connected: true, + state: "connected", + accountLogin: "acme", + accountType: "organization", + repositorySelection: "all", + ciTracesEnabled: true, + repositoryDiscovery: null, + repositories: Arr.map(REPOS, (name, index) => ({ + id: `0199a005-0000-7000-8000-${Str.padStart(12, "0")(String(index))}`, + fullName: `acme/${name}`, + htmlUrl: `https://github.com/acme/${name}`, + isPrivate: false, + status: "active", + syncStatus: "ready", + lastSyncedAt: null, + lastSyncError: null, + trackedBranch: "main", + branches: [{ name: "main", isDefault: true }], + prReviewEnabled: index < 3, + })), +}) + const ORGANIZATIONS = Schema.decodeSync(V2PlanetScaleOrganizationList)({ object: "planetscale_integration.organization_list", organizations: [{ id: "org_1", name: "acme" }], }) -const isCloudflare = (page: IntegrationLabPage) => page === "cloudflare" || page === "cloudflare-card" - -/** The statuses as the hub reads them, then PlanetScale's organization list. */ -const loaded = (model: IntegrationsModel, page: IntegrationLabPage): ReadonlyArray => [ - IntegrationsMessage.CompletedReadClock({ nowMs: NOW }), - isCloudflare(page) - ? IntegrationsMessage.CompletedLoadCloudflare({ +/** The status as the hub reads it. */ +const statusLoaded = (model: IntegrationsModel, integration: LabIntegration): IntegrationsMessage => { + switch (integration) { + case "cloudflare": + return IntegrationsMessage.CompletedLoadCloudflare({ key: model.statuses.cloudflare.key ?? "", result: Result.succeed(CLOUDFLARE), }) - : IntegrationsMessage.CompletedLoadPlanetscale({ + case "planetscale": + return IntegrationsMessage.CompletedLoadPlanetscale({ key: model.statuses.planetscale.key ?? "", result: Result.succeed(PLANETSCALE), - }), + }) + case "github": + return IntegrationsMessage.CompletedLoadGithub({ + key: model.statuses.github.key ?? "", + result: Result.succeed(GITHUB), + }) + } +} + +/** The clock and the status, then PlanetScale's organization list. */ +const loaded = ( + model: IntegrationsModel, + integration: LabIntegration, +): ReadonlyArray => [ + IntegrationsMessage.CompletedReadClock({ nowMs: NOW }), + statusLoaded(model, integration), ] const organizationsLoaded = (model: IntegrationsModel): IntegrationsMessage => @@ -120,15 +191,13 @@ const organizationsLoaded = (model: IntegrationsModel): IntegrationsMessage => export const integrationCardModel = (page: IntegrationLabPage, context: PageContext): IntegrationsModel => { const step = (model: IntegrationsModel, message: IntegrationsMessage) => integrationsUpdate(model, message, context).model - const entered = integrationsInit( - { search: { integration: isCloudflare(page) ? "cloudflare" : "planetscale" } }, - context, - ).model - const withStatus = Arr.reduce(loaded(entered, page), entered, step) - return isCloudflare(page) ? withStatus : step(withStatus, organizationsLoaded(withStatus)) + const integration = integrationOf(page) + const entered = integrationsInit({ search: { integration } }, context).model + const withStatus = Arr.reduce(loaded(entered, integration), entered, step) + return integration === "planetscale" ? step(withStatus, organizationsLoaded(withStatus)) : withStatus } -/** The connect flow, one Continue past Connect. */ +/** The connect flow, one Continue past Connect, or on through to Go live. */ export const integrationFlowModel = ( page: IntegrationLabPage, context: PageContext, @@ -137,14 +206,15 @@ export const integrationFlowModel = ( const step = (model: NewModel, message: NewMessage) => newUpdate(model, message, context).model const inner = (model: NewModel, message: IntegrationsMessage) => step(model, NewMessage.GotIntegrationsMessage({ message })) - const entered = newInit( - AppRoute.SourcesNew({ search: { integration: isCloudflare(page) ? "cloudflare" : "planetscale" } }), - context, - ).model + const integration = integrationOf(page) + const entered = newInit(AppRoute.SourcesNew({ search: { integration } }), context).model const granted = step(entered, NewMessage.CompletedReadGrants({ grants })) - const withStatus = Arr.reduce(loaded(granted.integrations, page), granted, inner) - const ready = isCloudflare(page) - ? withStatus - : inner(withStatus, organizationsLoaded(withStatus.integrations)) - return Arr.reduce([NewMessage.ClickedContinue(), NewMessage.CompletedScrollToTop()], ready, step) + const withStatus = Arr.reduce(loaded(granted.integrations, integration), granted, inner) + const ready = + integration === "planetscale" + ? inner(withStatus, organizationsLoaded(withStatus.integrations)) + : withStatus + const next = [NewMessage.ClickedContinue(), NewMessage.CompletedScrollToTop()] + const once = Arr.reduce(next, ready, step) + return Str.endsWith("-live")(page) && once.stage !== "live" ? Arr.reduce(next, once, step) : once } diff --git a/apps/web/src/page/integrations/view-flow-github.ts b/apps/web/src/page/integrations/view-flow-github.ts index 85ca45869c..85f288f86c 100644 --- a/apps/web/src/page/integrations/view-flow-github.ts +++ b/apps/web/src/page/integrations/view-flow-github.ts @@ -6,7 +6,7 @@ import { button } from "@maple/views/ui/button" import { badge } from "@maple/views/ui/display" import { icon } from "@maple/views/ui/icon" import { meter } from "@maple/views/ui/meter" -import { columnHead, dataTable, dataTableEmpty } from "../kit/data-table" +import { columnHead, dataTable } from "../kit/data-table" import { type CheckRow, flowColumns, @@ -23,7 +23,12 @@ import { activeRepos, githubReach } from "./flow-github" import { Message } from "./message" import type { Model } from "./model" import { githubStatusOf } from "./update-github" -import { githubDeactivated, githubInstallationPicker, githubReconnectButton } from "./view-github" +import { + githubDeactivated, + githubFeatures, + githubInstallationPicker, + githubReconnectButton, +} from "./view-github" import { SYNC_PRESENTATION } from "./view-github-repos" import { typography, typographyClass } from "@maple/views/ui/typography" import { hstack, vstack } from "@maple/views/ui/stack" @@ -78,7 +83,11 @@ const showsUpRail = (h: H): Html => }, { icon: "LayersIcon", title: "Traces", detail: "Spans with a commit SHA link to GitHub" }, { icon: "PullRequestIcon", title: "Code review", detail: "Rules, models and analytics" }, - { icon: "GearIcon", title: "Source page", detail: "Edit data, tracked branches, Disconnect" }, + { + icon: "GearIcon", + title: "Connection tab", + detail: "On the source page: these switches, tracked branches, Disconnect", + }, ], trust: "Large repos can take a few minutes to backfill. Nothing here needs you to stay.", docs: DOCS_HREF === undefined ? null : { label: "Docs", href: DOCS_HREF }, @@ -297,45 +306,43 @@ const repoTable = (h: H, repos: ReadonlyArray): Html => columnHead(h, { label: "Tracked branch", width: "w-36" }), columnHead(h, { label: "Status", width: "w-28", align: "right" }), ], - repos.length === 0 - ? [dataTableEmpty(h, ["No repositories granted yet"])] - : Arr.map(repos, (repo) => { - const presentation = SYNC_PRESENTATION[repo.syncStatus] - return hstack( + Arr.map(repos, (repo) => { + const presentation = SYNC_PRESENTATION[repo.syncStatus] + return hstack( + h, + { + gap: "4", + className: typographyClass({ + size: "sm", + className: stripClass("row"), + }), + }, + [ + h.span([h.Class("w-0 min-w-48 flex-1 truncate")], [repo.fullName]), + h.span( + [h.Class("w-36 shrink-0 truncate font-mono text-xs text-muted-foreground")], + [repo.trackedBranch ?? EMPTY_VALUE], + ), + hstack( h, { - gap: "4", - className: typographyClass({ - size: "sm", - className: stripClass("row"), - }), + as: "span", + inline: true, + gap: "1", + justify: "end", + className: cn("w-28 shrink-0 text-xs", presentation.tone), }, [ - h.span([h.Class("w-0 min-w-48 flex-1 truncate")], [repo.fullName]), - h.span( - [h.Class("w-36 shrink-0 truncate font-mono text-xs text-muted-foreground")], - [repo.trackedBranch ?? EMPTY_VALUE], - ), - h.span( - [ - h.Class( - cn( - "inline-flex w-28 shrink-0 items-center justify-end gap-1 text-xs", - presentation.tone, - ), - ), - ], - [ - icon(h, presentation.icon, { - size: 12, - className: presentation.spin ? "animate-spin" : undefined, - }), - presentation.label, - ], - ), + icon(h, presentation.icon, { + size: 12, + className: presentation.spin ? "animate-spin" : undefined, + }), + presentation.label, ], - ) - }), + ), + ], + ) + }), ) const liveStep = (h: H, model: Model): Html => { @@ -344,6 +351,7 @@ const liveStep = (h: H, model: Model): Html => { const discovery = status?.repositoryDiscovery const isDiscovering = discovery?._tag === "Pending" const discoveryFailed = discovery?._tag === "Failed" + const unsynced = Arr.filter(repos, (repo) => repo.syncStatus !== "ready") const isLive = status !== null && status.connected && @@ -354,11 +362,7 @@ const liveStep = (h: H, model: Model): Html => { return flowColumns( h, [ - savedBanner( - h, - "Saved as a source. Safe to leave; sync keeps running.", - "Nothing to apply on GitHub", - ), + savedBanner(h, "Saved as a source. Safe to leave; sync keeps running."), liveChecklist(h, { title: isLive ? "GitHub is live" : "Going live", rows: @@ -376,7 +380,18 @@ const liveStep = (h: H, model: Model): Html => { : status !== null && !status.connected && !isDiscovering ? [installButton(h, model, "Reconnect GitHub")] : []), - ...(repos.length > 0 || (!isDiscovering && !discoveryFailed) ? [repoTable(h, repos)] : []), + // Once everything synced the checklist says so; the table only lists what still needs a look. + ...(unsynced.length > 0 ? [repoTable(h, unsynced)] : []), + ...(status !== null && status.connected && !isDiscovering && !discoveryFailed + ? [ + stepCard(h, { title: "What Maple does with it" }, [ + githubFeatures(h, model, status), + typography(h, { size: "xs", tone: "muted", as: "p" }, [ + "Change these any time on the source's Connection tab.", + ]), + ]), + ] + : []), ], showsUpRail(h), ) diff --git a/apps/web/src/page/integrations/view-github.ts b/apps/web/src/page/integrations/view-github.ts index 3c484e4af3..7e241c8185 100644 --- a/apps/web/src/page/integrations/view-github.ts +++ b/apps/web/src/page/integrations/view-github.ts @@ -137,7 +137,7 @@ export const githubInstallationPicker = (h: H, model: Model): ReadonlyArray { +export const githubFeatures = (h: H, model: Model, status: GithubIntegrationStatus): Html => { const [ciTraces, prReview] = INTEGRATION_FEATURES.github const active = Arr.filter(status.repositories, (repo) => repo.status === "active") const reviewed = Arr.filter(active, (repo) => repo.prReviewEnabled).length diff --git a/apps/web/src/page/sources/new/github-flow.scene.test.ts b/apps/web/src/page/sources/new/github-flow.scene.test.ts index 71f134e111..2c8b1696f0 100644 --- a/apps/web/src/page/sources/new/github-flow.scene.test.ts +++ b/apps/web/src/page/sources/new/github-flow.scene.test.ts @@ -586,6 +586,10 @@ describe("github connect flow", () => { Command.resolve(ScrollToTop, Message.CompletedScrollToTop()), expectView(role("listitem", { name: "Live (done)" })).toExist(), expectView(text("GitHub is live")).toExist(), + // Synced repos are not listed again, the switches are, and the saved source has no Cancel. + expectView(text("Tracked branch")).toBeAbsent(), + expectView(role("switch", { name: /CI traces/i })).toExist(), + expectView(role("link", { name: "Cancel" })).toBeAbsent(), ) scene( { update: pageUpdate, view }, diff --git a/apps/web/src/page/sources/new/view.ts b/apps/web/src/page/sources/new/view.ts index 9fe1b587d7..6bd5e87dab 100644 --- a/apps/web/src/page/sources/new/view.ts +++ b/apps/web/src/page/sources/new/view.ts @@ -113,7 +113,11 @@ export const view = Submodel.defineView((model, // A member has no steps to take, so no trail either. isRefused(model) ? { title: titleOf(model), actions: cancel(h) } - : { titleContent: titleContent(h, model), actions: cancel(h) }, + : // On Go live the source exists already, so there is nothing left to cancel. + { + titleContent: titleContent(h, model), + actions: model.integration !== null && model.stage === "live" ? undefined : cancel(h), + }, [pageBody(h, model, inputs.context.timeZone)], ), )