fix(linear): clarify workspace hierarchy and align setup controls

This commit is contained in:
Xubin Ren committed 2026-09-26 19:19:21 +08:00
1 parent 8cf2521e9e
commit a6da05164d
3 files changed
+120 -58

No files matched your search

@@ -476,7 +476,13 @@ describe("Linear channel UI", () => {
renderSettingsView({ initialSection: "channels" }); renderSettingsView({ initialSection: "channels" });
fireEvent.click(await screen.findByRole("button", { name: "View Linear settings" })); fireEvent.click(await screen.findByRole("button", { name: "View Linear settings" }));
expect(await screen.findByText("Example workspace")).toBeVisible(); expect(await screen.findByText("Example workspace")).toBeVisible();
expect(screen.getByText(/app:assignable/)).toBeVisible(); const workspace = screen.getByRole("article", { name: "Example workspace" });
expect(within(workspace).getByRole("heading", { name: "Example workspace", level: 5 })).toBeVisible();
expect(within(workspace).getByRole("button", { name: "Member access" })).toBeVisible();
expect(screen.queryByText(/app:assignable/)).not.toBeInTheDocument();
fireEvent.click(within(workspace).getByRole("button", { name: "Authorized" }));
expect(await screen.findByRole("tooltip")).toHaveTextContent("read, write, app:mentionable, app:assignable");
fireEvent.keyDown(document, { key: "Escape" });
fireEvent.click(screen.getByRole("button", { name: "Disconnect" })); fireEvent.click(screen.getByRole("button", { name: "Disconnect" }));
fireEvent.click(screen.getByRole("button", { name: "Disconnect workspace" })); fireEvent.click(screen.getByRole("button", { name: "Disconnect workspace" }));
@@ -490,6 +496,46 @@ describe("Linear channel UI", () => {
); );
}); });
it("keeps member access inside its own workspace card and leaves other cards collapsed", async () => {
mockFeature({ ...savedFeature(), enabled: true, running: true, runtime_status: "running" });
requestMutationMock.mockImplementation(async (_method, params) => {
if (params.operation === "members") return {
session_id: "", status: "members", organization_id: params.organization_id,
legacy_allow_all: false,
members: [{ id: "u1", name: "Xubin", teams: ["nanobot"], allowed: true }],
};
return { session_id: "", status: "inspected", installations: [
{ organization_id: "org-1", organization_name: "nanobot", authorization_status: "authorized" },
{ organization_id: "org-2", organization_name: "Design workspace", authorization_status: "authorized" },
] };
});
renderSettingsView({ initialSection: "channels" });
fireEvent.click(await screen.findByRole("button", { name: "View Linear settings" }));
const workspace = await screen.findByRole("article", { name: "nanobot" });
const other = screen.getByRole("article", { name: "Design workspace" });
fireEvent.click(within(workspace).getByRole("button", { name: "Member access" }));
expect(await within(workspace).findByRole("switch", { name: "Allow Xubin to use nanobot" })).toBeVisible();
expect(within(other).getByRole("button", { name: "Member access" })).toHaveAttribute("aria-expanded", "false");
expect(within(other).queryByRole("switch")).not.toBeInTheDocument();
expect(requestMutationMock).toHaveBeenCalledWith("settings.channel.connect.start", {
channel: "linear", operation: "members", organization_id: "org-1",
}, 150_000);
expect(requestMutationMock.mock.calls.some(([, params]) => params.operation === "member_access")).toBe(false);
});
it("keeps missing authorization scopes visible without opening a tooltip", async () => {
mockFeature({ ...savedFeature(), enabled: true, running: true, runtime_status: "running" });
requestMutationMock.mockResolvedValue({ session_id: "", status: "inspected", installations: [{
organization_id: "org-1", organization_name: "nanobot", authorization_status: "missing_scopes",
scopes: ["read"], missing_scopes: ["write", "app:mentionable"],
}] });
renderSettingsView({ initialSection: "channels" });
fireEvent.click(await screen.findByRole("button", { name: "View Linear settings" }));
const workspace = await screen.findByRole("article", { name: "nanobot" });
expect(within(workspace).getByText("Reconnect to grant: write, app:mentionable")).toBeVisible();
expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
});
it("prevents disconnecting a workspace while its status is refreshing", async () => { it("prevents disconnecting a workspace while its status is refreshing", async () => {
const running = { const running = {
...savedFeature(), enabled: true, running: true, runtime_status: "running" as const, ...savedFeature(), enabled: true, running: true, runtime_status: "running" as const,
@@ -68,14 +68,14 @@ export function LinearMemberAccess({ organizationId, configScope = "", disabled
} }
return ( return (
<section className="w-full border-t border-border/50 pt-1"> <section className="w-full border-t border-border/50 bg-settings-surface">
<button type="button" aria-expanded={expanded} aria-controls={panelId} <button type="button" aria-expanded={expanded} aria-controls={panelId}
disabled={disabled} onMouseEnter={prefetch} onFocus={prefetch} disabled={disabled} onMouseEnter={prefetch} onFocus={prefetch}
className="settings-list-inset flex min-h-12 w-full items-center justify-between gap-3 rounded-xl text-start text-[13px] font-medium settings-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50" className="settings-list-inset flex min-h-12 w-full items-center justify-between gap-3 py-2 text-start text-[12px] font-medium settings-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:opacity-50"
onClick={() => setExpanded(!expanded)}> onClick={() => setExpanded(!expanded)}>
<span>{tx("members.title", "Member access")}</span> <span className="shrink-0">{tx("members.title", "Member access")}</span>
<span className="flex items-center gap-2"> <span className="flex min-w-0 items-center gap-2">
<span role="status" aria-live="polite" className="text-[12px] font-normal text-muted-foreground"> <span role="status" aria-live="polite" className="text-end text-[11px] font-normal text-muted-foreground">
{loading ? payload {loading ? payload
? tx("members.refreshing", "Checking for updates…") ? tx("members.refreshing", "Checking for updates…")
: tx("members.loading", "Finding your teammates…") : tx("members.loading", "Finding your teammates…")
+68 -52
View File
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react"; import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
import { Check, ChevronDown, ExternalLink, Loader2, RefreshCw, Unplug } from "lucide-react"; import { AlertCircle, Building2, Check, ChevronDown, ExternalLink, Info, Loader2, RefreshCw, Unplug } from "lucide-react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { channelTranslator } from "@/channel-plugins/i18n"; import { channelTranslator } from "@/channel-plugins/i18n";
@@ -29,6 +29,7 @@ import {
} from "@/components/ui/alert-dialog"; } from "@/components/ui/alert-dialog";
import { channelValidationStatusClass } from "@/components/settings/channels/ChannelValidationProgress"; import { channelValidationStatusClass } from "@/components/settings/channels/ChannelValidationProgress";
import { useAutoSave } from "@/components/settings/shared/useAutoSave"; import { useAutoSave } from "@/components/settings/shared/useAutoSave";
import { SettingsHint } from "@/components/settings/shared/SettingsHint";
import { configureChannel, disableNanobotFeature } from "@/lib/api"; import { configureChannel, disableNanobotFeature } from "@/lib/api";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { useClient } from "@/providers/ClientProvider"; import { useClient } from "@/providers/ClientProvider";
@@ -253,29 +254,25 @@ export function LinearPanel({
event.preventDefault(); event.preventDefault();
void saveSettings(); void saveSettings();
}}> }}>
<div className="flex flex-wrap items-center justify-between gap-3 pe-20"> <div className="flex min-h-10 flex-wrap items-center justify-between gap-3 pe-20">
<ChannelLogo feature={feature} showBrandLogos={showBrandLogos} /> <ChannelLogo feature={feature} showBrandLogos={showBrandLogos} />
<h3 className="sr-only">{displayName}</h3> <h3 className="sr-only">{displayName}</h3>
<span role="status" aria-live="polite" aria-atomic="true"
className="min-w-0 flex-1 truncate text-[11px] text-muted-foreground">
{saving ? t("settings.actions.saving", { defaultValue: "Saving" })
: saved ? t("settings.channels.savedSettings", { defaultValue: "Settings saved." }) : ""}
</span>
{feature.runtime_status === "running" ? ( {feature.runtime_status === "running" ? (
<span role="status" className={cn( <span role="status" className={cn(
"ms-auto inline-flex shrink-0 items-center gap-1.5 rounded-full px-2.5 py-1 text-[11.5px] font-medium", "ms-auto inline-flex h-8 shrink-0 items-center gap-1.5 rounded-full px-2.5 text-[11.5px] font-medium leading-none",
channelValidationStatusClass("connected"), channelValidationStatusClass("connected"),
)}> )}>
<Check className="h-3.5 w-3.5" aria-hidden /> <Check className="h-3.5 w-3.5" aria-hidden />
{tx("custom.channelRunning", "Channel running")} {tx("custom.channelRunning", "Channel running")}
</span> </span>
) : null} ) : null}
<span role="status" aria-live="polite" aria-atomic="true" className={cn(
"ms-auto inline-flex items-center gap-1.5 text-[11px] text-muted-foreground",
!saving && !saved && "sr-only",
)}>
{saving ? <><Loader2 className="h-3 w-3 animate-spin motion-reduce:animate-none" aria-hidden />
{t("settings.actions.saving", { defaultValue: "Saving" })}</> : saved ? <>
<Check className="h-3 w-3" aria-hidden />
{t("settings.channels.savedSettings", { defaultValue: "Settings saved." })}</> : null}
</span>
<button type="button" <button type="button"
className="inline-flex min-h-8 items-center gap-1.5 rounded px-1 text-[12px] text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-offset-2" className="inline-flex h-8 shrink-0 items-center gap-1.5 rounded px-1 text-[12px] leading-none text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-offset-2"
aria-expanded={advancedOpen} aria-controls={advancedPanelId} aria-expanded={advancedOpen} aria-controls={advancedPanelId}
onClick={() => setAdvancedOpen((current) => !current)}> onClick={() => setAdvancedOpen((current) => !current)}>
{t("settings.channels.advanced", { defaultValue: "Advanced" })} {t("settings.channels.advanced", { defaultValue: "Advanced" })}
@@ -309,7 +306,7 @@ export function LinearPanel({
</h4> </h4>
<Button type="button" variant="ghost" size="sm" <Button type="button" variant="ghost" size="sm"
disabled={loadingInstallations || disconnectingId !== null} disabled={loadingInstallations || disconnectingId !== null}
className="min-h-10 gap-2 rounded-full text-[12px]" className="h-8 gap-2 rounded-full text-[12px] text-muted-foreground"
onClick={() => void loadInstallations()}> onClick={() => void loadInstallations()}>
<RefreshCw className={cn("h-3.5 w-3.5", loadingInstallations && "animate-spin motion-reduce:animate-none")} aria-hidden /> <RefreshCw className={cn("h-3.5 w-3.5", loadingInstallations && "animate-spin motion-reduce:animate-none")} aria-hidden />
{tx("custom.refreshWorkspaces", "Refresh workspaces")} {tx("custom.refreshWorkspaces", "Refresh workspaces")}
@@ -328,46 +325,65 @@ export function LinearPanel({
const confirming = disconnectConfirmId === installation.organization_id; const confirming = disconnectConfirmId === installation.organization_id;
const disconnecting = disconnectingId === installation.organization_id; const disconnecting = disconnectingId === installation.organization_id;
const name = installation.organization_name || installation.organization_id; const name = installation.organization_name || installation.organization_id;
const needsAuthorization = installation.authorization_status === "missing_scopes"
|| installation.authorization_status === "refresh_required";
const authorizationLabel = (
<span className="inline-flex items-center gap-1.5 text-[11px] leading-4 text-muted-foreground">
{needsAuthorization
? <AlertCircle className="h-3 w-3 shrink-0" aria-hidden />
: <Check className="h-3 w-3 shrink-0" aria-hidden />}
{installation.authorization_status === "missing_scopes"
? tx("custom.missingScopes", "Reconnect to grant: {{scopes}}", {
scopes: installation.missing_scopes?.join(", ") || "required scopes",
})
: installation.authorization_status === "refresh_required"
? tx("custom.refreshRequired", "Authorization refresh required")
: tx("custom.authorized", "Authorized")}
{installation.scopes?.length ? <Info className="h-3 w-3 shrink-0" aria-hidden /> : null}
</span>
);
return ( return (
<article key={installation.organization_id} <article key={installation.organization_id} aria-label={name}
className="flex flex-wrap items-center justify-between gap-3 rounded-control bg-muted/45 px-3 py-2.5"> className="overflow-hidden rounded-panel border border-border/70 bg-background">
<div className="min-w-0"> <header className="flex flex-wrap items-center justify-between gap-3 p-4">
<p className="truncate text-[12.5px] font-medium text-foreground">{name}</p> <div className="flex min-w-0 flex-1 items-center gap-3">
<p className="mt-0.5 text-[11px] leading-4 text-muted-foreground"> <span className="flex h-9 w-9 shrink-0 items-center justify-center rounded-control bg-muted text-muted-foreground">
{installation.authorization_status === "missing_scopes" <Building2 className="h-4 w-4" aria-hidden />
? tx( </span>
"custom.missingScopes", <div className="min-w-0">
"Reconnect to grant: {{scopes}}", <h5 className="truncate text-[14px] font-semibold text-foreground" title={name}>{name}</h5>
{ scopes: installation.missing_scopes?.join(", ") || "required scopes" }, <div className="mt-1">
) {installation.scopes?.length ? (
: installation.authorization_status === "refresh_required" <SettingsHint description={installation.scopes.join(", ")}>
? tx("custom.refreshRequired", "Authorization refresh required") {authorizationLabel}
: tx("custom.authorized", "Authorized")} </SettingsHint>
{installation.scopes?.length ? ` · ${installation.scopes.join(", ")}` : ""} ) : authorizationLabel}
</p> </div>
</div> </div>
<div className="flex flex-wrap items-center gap-2"> </div>
{confirming ? ( <div className="ms-auto flex flex-wrap items-center gap-2">
<Button type="button" variant="ghost" size="sm" {confirming ? (
disabled={loadingInstallations || disconnecting} <Button type="button" variant="ghost" size="sm"
className="min-h-10 rounded-full text-[12px]" disabled={loadingInstallations || disconnecting}
onClick={() => setDisconnectConfirmId(null)}> className="h-8 rounded-full text-[12px]"
{t("settings.actions.cancel", { defaultValue: "Cancel" })} onClick={() => setDisconnectConfirmId(null)}>
{t("settings.actions.cancel", { defaultValue: "Cancel" })}
</Button>
) : null}
<Button type="button" variant={confirming ? "destructive" : "ghost"} size="sm"
disabled={loadingInstallations || disconnectingId !== null}
className={cn("h-8 gap-2 rounded-full text-[12px]", !confirming && "text-muted-foreground")}
onClick={() => confirming
? void disconnectWorkspace(installation)
: setDisconnectConfirmId(installation.organization_id)}>
{disconnecting ? <Loader2 className="h-3.5 w-3.5 animate-spin motion-reduce:animate-none" aria-hidden />
: <Unplug className="h-3.5 w-3.5" aria-hidden />}
{confirming
? tx("custom.confirmDisconnect", "Disconnect workspace")
: tx("custom.disconnect", "Disconnect")}
</Button> </Button>
) : null} </div>
<Button type="button" variant={confirming ? "destructive" : "outline"} size="sm" </header>
disabled={loadingInstallations || disconnectingId !== null}
className="min-h-10 gap-2 rounded-full text-[12px]"
onClick={() => confirming
? void disconnectWorkspace(installation)
: setDisconnectConfirmId(installation.organization_id)}>
{disconnecting ? <Loader2 className="h-3.5 w-3.5 animate-spin motion-reduce:animate-none" aria-hidden />
: <Unplug className="h-3.5 w-3.5" aria-hidden />}
{confirming
? tx("custom.confirmDisconnect", "Disconnect workspace")
: tx("custom.disconnect", "Disconnect")}
</Button>
</div>
<LinearMemberAccess organizationId={installation.organization_id} <LinearMemberAccess organizationId={installation.organization_id}
configScope={JSON.stringify([ configScope={JSON.stringify([
feature.config_values?.["channels.linear.clientId"], feature.config_values?.["channels.linear.clientId"],