refactor(linear): keep workspace API types inside channel
This commit is contained in:
1 parent
c5f78bbd5c
commit
2dac0d330c
5 files changed
+38
-30
No files matched your search
@@ -29,11 +29,12 @@ 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 { configureChannel, disableNanobotFeature, startChannelConnect } from "@/lib/api";
|
import { configureChannel, disableNanobotFeature } from "@/lib/api";
|
||||||
import type { ChannelInstallationSummary } from "@/lib/types";
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { useClient } from "@/providers/ClientProvider";
|
import { useClient } from "@/providers/ClientProvider";
|
||||||
|
|
||||||
|
import { manageLinearWorkspace } from "./api";
|
||||||
|
import type { LinearInstallationSummary } from "./types";
|
||||||
import { LinearConnectFlow } from "./LinearConnectFlow";
|
import { LinearConnectFlow } from "./LinearConnectFlow";
|
||||||
import { linearManifestUrl } from "./manifest";
|
import { linearManifestUrl } from "./manifest";
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ export function LinearPanel({
|
|||||||
const [notice, setNotice] = useState<string | null>(null);
|
const [notice, setNotice] = useState<string | null>(null);
|
||||||
const [saved, setSaved] = useState(false);
|
const [saved, setSaved] = useState(false);
|
||||||
const [publicUrlPromptOpen, setPublicUrlPromptOpen] = useState(false);
|
const [publicUrlPromptOpen, setPublicUrlPromptOpen] = useState(false);
|
||||||
const [installations, setInstallations] = useState<ChannelInstallationSummary[]>([]);
|
const [installations, setInstallations] = useState<LinearInstallationSummary[]>([]);
|
||||||
const [loadingInstallations, setLoadingInstallations] = useState(false);
|
const [loadingInstallations, setLoadingInstallations] = useState(false);
|
||||||
const [disconnectingId, setDisconnectingId] = useState<string | null>(null);
|
const [disconnectingId, setDisconnectingId] = useState<string | null>(null);
|
||||||
const [disconnectConfirmId, setDisconnectConfirmId] = useState<string | null>(null);
|
const [disconnectConfirmId, setDisconnectConfirmId] = useState<string | null>(null);
|
||||||
@@ -122,7 +123,7 @@ export function LinearPanel({
|
|||||||
setWorkspaceNotice(null);
|
setWorkspaceNotice(null);
|
||||||
setWorkspaceError(null);
|
setWorkspaceError(null);
|
||||||
try {
|
try {
|
||||||
const payload = await startChannelConnect(client, "linear", { operation: "inspect" });
|
const payload = await manageLinearWorkspace(client, { operation: "inspect" });
|
||||||
setInstallations(payload.installations ?? []);
|
setInstallations(payload.installations ?? []);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setWorkspaceError((err as Error).message);
|
setWorkspaceError((err as Error).message);
|
||||||
@@ -135,12 +136,12 @@ export function LinearPanel({
|
|||||||
if (feature.runtime_status === "running") void loadInstallations();
|
if (feature.runtime_status === "running") void loadInstallations();
|
||||||
}, [feature.runtime_status, loadInstallations]);
|
}, [feature.runtime_status, loadInstallations]);
|
||||||
|
|
||||||
const disconnectWorkspace = async (installation: ChannelInstallationSummary) => {
|
const disconnectWorkspace = async (installation: LinearInstallationSummary) => {
|
||||||
setDisconnectingId(installation.organization_id);
|
setDisconnectingId(installation.organization_id);
|
||||||
setWorkspaceNotice(null);
|
setWorkspaceNotice(null);
|
||||||
setWorkspaceError(null);
|
setWorkspaceError(null);
|
||||||
try {
|
try {
|
||||||
const payload = await startChannelConnect(client, "linear", {
|
const payload = await manageLinearWorkspace(client, {
|
||||||
operation: "disconnect",
|
operation: "disconnect",
|
||||||
organization_id: installation.organization_id,
|
organization_id: installation.organization_id,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { startChannelConnect, type WebUIMutationTransport } from "@/lib/api";
|
||||||
|
|
||||||
|
import type { LinearWorkspacePayload } from "./types";
|
||||||
|
|
||||||
|
export function manageLinearWorkspace(
|
||||||
|
transport: WebUIMutationTransport,
|
||||||
|
params: { operation: "inspect" } | { operation: "disconnect"; organization_id: string },
|
||||||
|
): Promise<LinearWorkspacePayload> {
|
||||||
|
return startChannelConnect<LinearWorkspacePayload>(transport, "linear", params);
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
export interface LinearInstallationSummary {
|
||||||
|
organization_id: string;
|
||||||
|
organization_name?: string;
|
||||||
|
scopes?: string[];
|
||||||
|
authorization_status?: "authorized" | "refresh_required" | "missing_scopes";
|
||||||
|
missing_scopes?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LinearWorkspacePayload {
|
||||||
|
session_id: string;
|
||||||
|
status: "inspected" | "disconnected";
|
||||||
|
message?: string;
|
||||||
|
organization_id?: string;
|
||||||
|
installations: LinearInstallationSummary[];
|
||||||
|
webhook_url?: string;
|
||||||
|
redirect_uri?: string;
|
||||||
|
}
|
||||||
@@ -815,12 +815,12 @@ export async function runPairingAction(
|
|||||||
return mutation<PairingPayload>(transport, `settings.pairing.${action}`, { code });
|
return mutation<PairingPayload>(transport, `settings.pairing.${action}`, { code });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startChannelConnect(
|
export async function startChannelConnect<T = ChannelConnectPayload>(
|
||||||
transport: WebUIMutationTransport,
|
transport: WebUIMutationTransport,
|
||||||
channel: string,
|
channel: string,
|
||||||
params: Readonly<Record<string, string | boolean>> = {},
|
params: Readonly<Record<string, string | boolean>> = {},
|
||||||
): Promise<ChannelConnectPayload> {
|
): Promise<T> {
|
||||||
return mutation<ChannelConnectPayload>(
|
return mutation<T>(
|
||||||
transport,
|
transport,
|
||||||
"settings.channel.connect.start",
|
"settings.channel.connect.start",
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-21
@@ -1212,22 +1212,7 @@ export interface McpPresetsPayload {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChannelConnectStatus =
|
type ChannelConnectStatus = "pending" | "succeeded" | "expired" | "cancelled" | "failed";
|
||||||
| "pending"
|
|
||||||
| "succeeded"
|
|
||||||
| "expired"
|
|
||||||
| "cancelled"
|
|
||||||
| "failed"
|
|
||||||
| "inspected"
|
|
||||||
| "disconnected";
|
|
||||||
|
|
||||||
export interface ChannelInstallationSummary {
|
|
||||||
organization_id: string;
|
|
||||||
organization_name?: string;
|
|
||||||
scopes?: string[];
|
|
||||||
authorization_status?: "authorized" | "refresh_required" | "missing_scopes";
|
|
||||||
missing_scopes?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChannelConnectPayload {
|
export interface ChannelConnectPayload {
|
||||||
session_id: string;
|
session_id: string;
|
||||||
@@ -1237,11 +1222,6 @@ export interface ChannelConnectPayload {
|
|||||||
qr_url?: string;
|
qr_url?: string;
|
||||||
interval_ms?: number;
|
interval_ms?: number;
|
||||||
expires_at_ms?: number;
|
expires_at_ms?: number;
|
||||||
organization_id?: string;
|
|
||||||
organization_name?: string;
|
|
||||||
installations?: ChannelInstallationSummary[];
|
|
||||||
webhook_url?: string;
|
|
||||||
redirect_uri?: string;
|
|
||||||
nanobot_features?: NanobotFeaturesPayload;
|
nanobot_features?: NanobotFeaturesPayload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user