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
150 changes: 93 additions & 57 deletions dashboard/e2e/hybrid.spec.ts

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions dashboard/e2e/knowledge-app-choice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import path from "node:path";
// - "Use Coderhelm's app" shows one "Sign in with <app>" button and the
// choice's one line: no token steps and no form fields;
// - a key stays behind "Use a key instead";
// - "Use my own app" without the install's own app shows the token steps;
// - fully private, without the install's own app, shows the token steps;
// - there is no per-tool switch: the one Other apps choice lives in Settings;
// - when Coderhelm's app isn't ready yet, it says so, still with no form.
// Every call is answered here; nothing reaches a real backend.

Expand All @@ -26,6 +27,7 @@ interface State {
function hybridStatus(s: State) {
const row = (id: string, name: string) => ({ id, name, mode: "hosted", through_coderhelm: "The sign-in only.", stays_with_you: "Every page Coderhelm reads.", uses_coderhelm: s.coderhelm.has(id) });
return {
apps_mode: s.coderhelm.size > 0 ? "coderhelm" : "private",
available: true,
hosted_url: "https://app.coderhelm.com",
registered: true,
Expand Down Expand Up @@ -101,7 +103,7 @@ async function shot(page: Page, name: string) {
for (const kind of ["notion", "confluence"] as const) {
const label = LABEL[kind];

test.describe(`${label}: the app choice decides what the dialog asks for`, () => {
test.describe(`${label}: the install's Other apps choice decides what the dialog asks for`, () => {
test(`Coderhelm's app: one sign-in button, no token steps or fields`, async ({ page }) => {
await mockApi(page, { coderhelm: new Set([kind]), brokerReady: true, puts: [] });
await page.goto("/knowledge/");
Expand All @@ -119,7 +121,7 @@ for (const kind of ["notion", "confluence"] as const) {
await expect(step.getByTestId("token-path")).toBeVisible();
});

test(`my own app (none set up): the token steps, and no sign-in button`, async ({ page }) => {
test(`fully private (no own app set up): the token steps, and no sign-in button`, async ({ page }) => {
await mockApi(page, { coderhelm: new Set(), brokerReady: true, puts: [] });
await page.goto("/knowledge/");
await page.getByTestId(`start-${kind}`).click();
Expand All @@ -131,18 +133,17 @@ for (const kind of ["notion", "confluence"] as const) {
await shot(page, `${kind}-own`);
});

test(`switching to Coderhelm's app swaps the form for the sign-in button`, async ({ page }) => {
test(`no per-tool switch here: the dialog says which app and links to the one choice`, async ({ page }) => {
const s: State = { coderhelm: new Set(), brokerReady: true, puts: [] };
await mockApi(page, s);
await page.goto("/knowledge/");
await page.getByTestId(`start-${kind}`).click();
const step = page.getByTestId("connect-step");
await expect(step.getByTestId("token-path")).toBeVisible();
await step.getByRole("button", { name: "Use Coderhelm's app (easiest)" }).click();
await expect(step).toHaveAttribute("data-state", "sign-in");
await expect(step.getByTestId("connect-button")).toHaveText(`Sign in with ${label}`);
await expect(step.getByTestId("token-path")).toHaveCount(0);
expect(s.puts).toContainEqual({ apps: { [kind]: "coderhelm" } });
const choice = step.getByTestId("hybrid-app-choice");
await expect(choice).toContainText(`This install is fully private, so ${label} uses your team's own app.`);
await expect(choice.getByRole("button")).toHaveCount(0);
await expect(choice.getByRole("link", { name: "Change it for every tool in Settings, Version and updates, Hybrid" })).toHaveAttribute("href", /\/settings\/system\/?#hybrid/);
expect(s.puts).toEqual([]);
});

test(`Coderhelm's app not ready yet: says so, still no form`, async ({ page }) => {
Expand Down
37 changes: 28 additions & 9 deletions dashboard/src/components/hybrid-app-choice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Link from "next/link";
import { useState } from "react";
import { HYBRID_HREF, appChoice, canUseCoderhelm, useHybrid } from "@/lib/hybrid";
import { HYBRID_HREF, appsModeOf, canUseCoderhelm, useHybrid } from "@/lib/hybrid";
import { Segmented } from "./segmented";
import { useToast } from "./toast";
import { linkButton } from "./ui";
Expand All @@ -24,10 +24,12 @@ export function useHybridChoice(id: string): Choice | null {
}

/**
* On a self-hosted install: whether this integration uses Coderhelm's app
* (easiest) or the install's own (fully private). Reads and saves the same
* settings as Settings, then System, Hybrid. Shows nothing on the hosted
* service, on an install without hybrid, or where there is no choice.
* On a self-hosted install: which app this integration uses. GitHub has its
* own choice, made here or in Settings, then System, Hybrid. Every other
* tool follows the install's one Other apps choice (Coderhelm's apps or
* fully private), so it only says which, with a link to change it. Shows
* nothing on the hosted service, on an install without hybrid, or where
* Coderhelm has no app for it.
*/
export function HybridAppChoice({
id,
Expand All @@ -38,7 +40,7 @@ export function HybridAppChoice({
id: string;
name: string;
className?: string;
/** After the choice is saved (what the dialog offers depends on it). */
/** After GitHub's choice is saved. */
onChanged?: (next: Choice) => void;
}) {
const hybrid = useHybrid();
Expand All @@ -63,13 +65,30 @@ export function HybridAppChoice({
const integration = s.integrations.find((i) => i.id === id);
// Not hosted, or Coderhelm's app for it isn't set up: there is no choice.
if (id !== "github" && !canUseCoderhelm(integration)) return null;
const value: Choice = id === "github" ? (s.github.mode === "hosted" ? "coderhelm" : "own") : integration?.uses_coderhelm ? "coderhelm" : "own";

if (id !== "github") {
const value: Choice = integration?.uses_coderhelm ? "coderhelm" : "own";
const text = integration?.own_app
? `${name} uses your own app, set up on this install.`
: appsModeOf(s) === "coderhelm"
? `${name} signs in through Coderhelm's app, like every tool on this install.`
: `This install is fully private, so ${name} uses your team's own app.`;
return (
<div className={box} data-testid="hybrid-app-choice" data-state={value}>
<p className="text-sm text-zinc-300">
{text}{" "}
<Link href={HYBRID_HREF} className={`${linkButton} text-sm`}>Change it for every tool in Settings, Version and updates, Hybrid</Link>
</p>
</div>
);
}

const value: Choice = s.github.mode === "hosted" ? "coderhelm" : "own";
const change = async (next: Choice) => {
if (next === value || busy) return;
setBusy(true);
try {
await hybrid.save(id === "github" ? { github_mode: next === "coderhelm" ? "hosted" : "own" } : appChoice(id, next === "coderhelm"));
await hybrid.save({ github_mode: next === "coderhelm" ? "hosted" : "own" });
toast(next === "coderhelm" ? `${name} now uses Coderhelm's app` : `${name} now uses your own app`);
onChanged?.(next);
} catch (e) {
Expand All @@ -82,7 +101,7 @@ export function HybridAppChoice({
const note =
value === "coderhelm"
? integration?.through_coderhelm || "Events reach your install through Coderhelm."
: integration?.stays_with_you || "Everything goes straight to your install. Nothing passes through Coderhelm.";
: "Everything goes straight to your install. Nothing passes through Coderhelm.";

return (
<div className={box} data-testid="hybrid-app-choice" data-state={value}>
Expand Down
122 changes: 62 additions & 60 deletions dashboard/src/components/hybrid-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import Link from "next/link";
import { useEffect, useId, useRef, useState, type ReactNode } from "react";
import { api, type HybridCheck, type HybridGithubLink, type HybridIntegration, type HybridNameCheck, type HybridStatus } from "@/lib/api";
import { GITHUB_OUTCOMES, NAME_CODES, TRUST_MODEL_URL, appChoice, cleanName, useHybrid, type HybridState } from "@/lib/hybrid";
import { api, type HybridAppsMode, type HybridCheck, type HybridGithubLink, type HybridNameCheck, type HybridStatus } from "@/lib/api";
import { APPS_MODES, GITHUB_OUTCOMES, NAME_CODES, TRUST_MODEL_URL, appTools, appsModeOf, appsModePatch, cleanName, useHybrid, type HybridState } from "@/lib/hybrid";
import { Callout } from "./callout";
import { CopyButton } from "./copy-button";
import { useConfirm } from "./confirm-dialog";
Expand Down Expand Up @@ -686,75 +686,77 @@ function GithubLinkCard({ link, hybrid }: { link: HybridGithubLink; hybrid: Hybr
);
}

// ── Other integrations ─────────────────────────────────────────────
// ── Other apps ─────────────────────────────────────────────────────

/**
* One choice for the whole install: Coderhelm's apps for every tool the
* catalog has one for (new ones included), or fully private. The tools are
* the gateway's catalog, never a list kept here.
*/
function IntegrationsRow({ hybrid, s }: RowProps) {
const list = (s.integrations ?? []).filter((i) => i.id !== "github");
if (list.length === 0) return null;
const { busy, act } = useAct();
const tools = appTools(s);
const others = (s.integrations ?? []).filter((i) => i.id !== "github" && !tools.includes(i));
if (tools.length === 0 && others.length === 0) return null;
const mode = appsModeOf(s);
const current = APPS_MODES.find((m) => m.value === mode) ?? APPS_MODES[0];
const direct = others.filter((i) => i.mode === "direct");
const included = others.filter((i) => i.mode === "included");
const unavailable = others.filter((i) => i.mode === "unavailable");
return (
<div className={row} id="hybrid-integrations" data-testid="hybrid-integrations">
<div className={row} id="hybrid-integrations" data-testid="hybrid-integrations" data-apps-mode={mode}>
<RowHeading title="Other apps">
<p>For each tool, use Coderhelm&apos;s app, or create your own so nothing passes through Coderhelm.</p>
<p>One choice for every tool Coderhelm has an app for, now and later. GitHub has its own choice above.</p>
</RowHeading>
<ul className="mt-3 divide-y divide-zinc-800 overflow-hidden rounded-lg border border-zinc-800">
{list.map((i) => (
<IntegrationItem key={i.id} i={i} hybrid={hybrid} s={s} />
))}
</ul>
</div>
);
}

function IntegrationItem({ i, hybrid, s }: { i: HybridIntegration } & RowProps) {
const { busy, act } = useAct();
const value = i.uses_coderhelm ? "coderhelm" : "own";
const notOffered = i.mode === "hosted" && i.offered === false;
return (
<li className="min-w-0 px-4 py-4" data-testid={`hybrid-integration-${i.id}`} data-mode={i.mode}>
<div className="flex min-w-0 flex-wrap items-center justify-between gap-x-4 gap-y-2">
<p className="text-sm font-medium text-zinc-100">{i.name}</p>
{notOffered ? (
<Chip tone="muted">Coderhelm&apos;s app isn&apos;t set up yet</Chip>
) : i.mode === "hosted" ? (
<Segmented<"coderhelm" | "own">
label={`Which ${i.name} app to use`}
value={value}
disabled={!!busy}
onChange={(v) =>
void act("set", () => hybrid.save(appChoice(i.id, v === "coderhelm")), v === "coderhelm" ? `${i.name} uses Coderhelm's app` : `${i.name} uses your own app`)
}
options={[
{ value: "coderhelm", label: "Use Coderhelm's app (easiest)" },
{ value: "own", label: "Use my own app (fully private)" },
]}
/>
) : i.mode === "direct" ? (
<Chip tone="success">Works from your install, no app needed</Chip>
) : i.mode === "included" ? (
<Chip tone="success">On through Coderhelm&apos;s app</Chip>
) : (
<Chip tone="muted">Not available</Chip>
)}
</div>
{notOffered && <p className="mt-1 text-sm text-zinc-400">Use your own {i.name} app for now.</p>}
{(i.mode === "hosted" || i.mode === "included") && !notOffered && (i.through_coderhelm || i.stays_with_you) && (
<dl className="mt-2 grid min-w-0 gap-x-4 gap-y-1 text-sm sm:grid-cols-2">
{i.through_coderhelm && (
<div className={`min-w-0 ${value === "coderhelm" || i.mode === "included" ? "" : "opacity-60"}`}>
<dt className="text-zinc-300">Through Coderhelm</dt>
<dd className="text-zinc-400">{i.through_coderhelm}</dd>
{tools.length > 0 && (
<>
<div className="mt-3">
<Segmented<HybridAppsMode>
label="Other apps"
value={mode}
disabled={!!busy}
onChange={(v) =>
void act("apps", () => hybrid.save(appsModePatch(s, v)), v === "coderhelm" ? "Other apps use Coderhelm's apps" : "Other apps are fully private")
}
options={APPS_MODES.map(({ value, label }) => ({ value, label }))}
/>
</div>
<p className="mt-2 max-w-prose text-sm text-zinc-400" data-testid="hybrid-apps-line">{current.line}</p>
<ul className="mt-3 flex min-w-0 flex-wrap gap-2" aria-label="Tools this covers" data-testid="hybrid-apps-tools">
{tools.map((i) => (
<li key={i.id} data-testid={`hybrid-integration-${i.id}`} data-mode={i.mode} data-uses-coderhelm={String(i.uses_coderhelm)}>
<Chip tone={i.uses_coderhelm ? "success" : "neutral"}>
{i.name}
{i.own_app ? ", your own app" : i.offered === false && mode === "coderhelm" ? ", not ready yet" : ""}
</Chip>
</li>
))}
</ul>
</>
)}
{(direct.length > 0 || included.length > 0 || unavailable.length > 0) && (
<dl className="mt-4 grid min-w-0 gap-y-1 text-sm">
{direct.length > 0 && (
<div className="min-w-0" data-testid="hybrid-apps-direct">
<dt className="inline text-zinc-300">No app needed: </dt>
<dd className="inline text-zinc-400">{direct.map((i) => i.name).join("; ")}</dd>
</div>
)}
{included.length > 0 && (
<div className="min-w-0" data-testid="hybrid-apps-included">
<dt className="inline text-zinc-300">Always through Coderhelm&apos;s app: </dt>
<dd className="inline text-zinc-400">{included.map((i) => i.name).join("; ")}</dd>
</div>
)}
{i.stays_with_you && (
<div className="min-w-0">
<dt className="text-zinc-300">Stays with you</dt>
<dd className="text-zinc-400">{i.stays_with_you}</dd>
{unavailable.length > 0 && (
<div className="min-w-0" data-testid="hybrid-apps-unavailable">
<dt className="inline text-zinc-300">Not through Coderhelm: </dt>
<dd className="inline text-zinc-400">{unavailable.map((i) => i.name).join("; ")}</dd>
</div>
)}
</dl>
)}
{i.mode === "unavailable" && i.reason && <p className="mt-1 text-sm text-zinc-400">{i.reason}</p>}
</li>
</div>
);
}

Expand Down
13 changes: 10 additions & 3 deletions dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4950,6 +4950,8 @@ export interface HybridIntegration {
uses_coderhelm: boolean;
/** False when Coderhelm's own app for it isn't set up, so it can't be chosen now. Missing from older gateways. */
offered?: boolean;
/** Tools under Other apps: the install has its own app for it, which it uses either way. Missing from older gateways. */
own_app?: boolean;
}

export interface HybridCheck {
Expand All @@ -4970,6 +4972,8 @@ export interface HybridStatus {
name: { name: string; hostname: string; code: string } | null;
github: { mode: "own" | "hosted"; links: HybridGithubLink[]; app_slug: string | null };
integrations: HybridIntegration[];
/** Other apps, for the whole install. Missing from older gateways (then read from `integrations`). */
apps_mode?: HybridAppsMode;
sharing: { enabled: boolean; payloads: boolean };
/** Jira through Coderhelm: a hosted team's site linked to this install (absent on an older install). */
jira?: { enabled: boolean; link: HybridJiraLink | null; synced: boolean };
Expand Down Expand Up @@ -5001,11 +5005,14 @@ export interface HybridNameCheck {
error: string | null;
}

/** Other apps: every tool on Coderhelm's app (new ones included), or none. */
export type HybridAppsMode = "coderhelm" | "private";

export interface HybridSettingsPatch {
github_mode?: "own" | "hosted";
/** The hosted-app integrations among jira, notion, confluence, google_drive (github follows github_mode). Older installs; newer ones take `apps`. */
integrations?: string[];
/** Other apps, per tool (jira, notion, confluence, google_drive): only the tools named change. A tool nobody chose uses Coderhelm's app. */
/** Other apps, for the whole install. */
apps_mode?: HybridAppsMode;
/** The same choice per tool, for a gateway from before `apps_mode` (it ignores `apps_mode`; a newer one ignores this). */
apps?: Record<string, "coderhelm" | "own">;
sharing?: { enabled: boolean; payloads: boolean };
/** Settings, Integrations, Jira: link a hosted team's Jira site through Coderhelm. */
Expand Down
Loading
Loading