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
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function MoveWorkspaceToCloudDialog({
machineSize: selection.machineSize,
onStage: (stage) =>
progress.setStage(stage === "saving" ? "saving" : "creating"),
onBegun: progress.begun,
signal: progress.signal,
})
.then(({ toWorkspaceId, skipped }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from "@superset/ui/select";
import { useMemo, useState } from "react";
import { useKnownHosts } from "renderer/hooks/known-hosts/useKnownHosts";
import { useHostWorkspaces } from "renderer/routes/_authenticated/providers/HostWorkspacesProvider";
import { useCloudWorkspaces } from "renderer/hooks/useCloudWorkspaces";
import { useLocalHostService } from "renderer/routes/_authenticated/providers/LocalHostServiceProvider";
import { useMoveWorkspaceToComputer } from "../../../../hooks/useMoveWorkspaceToComputer";
import type { MovableWorkspace } from "../../../../hooks/useWorkspaceMoveDirections";
Expand All @@ -40,7 +40,7 @@ export function MoveWorkspaceToComputerDialog({
const { t } = useLingui();
const { machineId } = useLocalHostService();
const { hosts } = useKnownHosts();
const { cache } = useHostWorkspaces();
const { workspaces: cloudWorkspaces = [] } = useCloudWorkspaces();
const moveWorkspaceToComputer = useMoveWorkspaceToComputer(workspace);
const reportSkipped = useReportSkippedChats();

Expand All @@ -50,7 +50,7 @@ export function MoveWorkspaceToComputerDialog({
(host) =>
host.machineId !== workspace.hostId &&
host.machineId !== machineId &&
!cache.isSandboxHost(host.machineId),
!cloudWorkspaces.some((row) => row.id === host.machineId),
)
.map((host) => ({
hostId: host.machineId,
Expand All @@ -63,7 +63,7 @@ export function MoveWorkspaceToComputerDialog({
? [{ hostId: machineId, label: null, online: true }]
: [];
return [...thisComputer, ...others];
}, [hosts, workspace.hostId, cache, machineId]);
}, [hosts, workspace.hostId, cloudWorkspaces, machineId]);
const [picked, setPicked] = useState<string | null>(null);
const destination =
computers.find((computer) => computer.hostId === picked) ??
Expand All @@ -87,6 +87,7 @@ export function MoveWorkspaceToComputerDialog({
void moveWorkspaceToComputer({
destination: { hostId: destination.hostId, name: destination.label },
onStage: progress.setStage,
onBegun: progress.begun,
signal: progress.signal,
})
.then(({ toWorkspaceId, skipped }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { plural } from "@lingui/core/macro";
import type { I18n } from "@lingui/core";
import { msg, plural } from "@lingui/core/macro";
import { Trans, useLingui } from "@lingui/react/macro";
import { Button } from "@superset/ui/button";
import { Progress } from "@superset/ui/progress";
Expand All @@ -21,14 +22,18 @@ const ENDED = new Set([
const CANCELLABLE = new Set(["saving"]);

export function WorkspaceMoveToast({ moveId }: { moveId: string }) {
const { t } = useLingui();
const { t, i18n } = useLingui();
const move = useWorkspaceMoveProgressStore((state) => state.moves[moveId]);
const remove = useWorkspaceMoveProgressStore((state) => state.remove);
if (!move) return null;
const ended = ENDED.has(move.stage);
const { name, destination } = move;
// Chats that did not arrive show their own reason in their pane.
const failure =
move.stage === "failed" ? describeMoveError(move.error) : null;
move.stage === "failed" && move.failedDuring !== "moving-chats"
? describeMoveError(move.error)
: null;
const retry = failure ? move.retry : null;

const title =
move.stage === "failed"
Expand Down Expand Up @@ -62,11 +67,11 @@ export function WorkspaceMoveToast({ moveId }: { moveId: string }) {
</button>
</div>
<p className="mt-1 text-xs text-muted-foreground" aria-live="polite">
{failure ? failure.reason : describe(move, t)}
{failure ? failure.reason : describe(move, i18n)}
</p>
{move.stage === "failed" && (
{failure && (
<p className="mt-1 text-xs text-muted-foreground">
{describeOutcome(move, t)}
{describeOutcome(move, i18n)}
</p>
)}
{failure?.details && (
Expand All @@ -80,16 +85,15 @@ export function WorkspaceMoveToast({ moveId }: { moveId: string }) {
{!ended && (
<Progress className="mt-3 h-1.5" value={progressPercent(move)} />
)}
{((move.cancel && CANCELLABLE.has(move.stage)) ||
(move.retry && move.stage === "failed")) && (
{((move.cancel && CANCELLABLE.has(move.stage)) || retry) && (
<div className="mt-3 flex justify-end gap-2">
{move.cancel && CANCELLABLE.has(move.stage) && (
<Button size="sm" variant="outline" onClick={move.cancel}>
<Trans>Cancel move</Trans>
</Button>
)}
{move.retry && move.stage === "failed" && (
<Button size="sm" onClick={move.retry}>
{retry && (
<Button size="sm" onClick={retry}>
<Trans>Try again</Trans>
</Button>
)}
Expand All @@ -99,71 +103,73 @@ export function WorkspaceMoveToast({ moveId }: { moveId: string }) {
);
}

function describeChatCount(
done: number,
total: number,
t: ReturnType<typeof useLingui>["t"],
): string {
return t({
message: plural(total, {
one: `${done} of # chat moved`,
other: `${done} of # chats moved`,
}),
});
}

function describeOutcome(
move: WorkspaceMoveProgress,
t: ReturnType<typeof useLingui>["t"],
): string {
function describeOutcome(move: WorkspaceMoveProgress, i18n: I18n): string {
const { name } = move;
if (move.failedDuring === "moving-chats") {
return t({
message: "Chats that didn't move are still in the original workspace.",
});
}
if (move.failedDuring === "creating") {
return t({
message: `${name} is unchanged. If an agent was working, it was stopped.`,
});
return i18n._(
msg({
message: `${name} is unchanged. If an agent was working, it was stopped.`,
}),
);
}
return t({ message: `${name} is unchanged.` });
return i18n._(
msg({
message: `${name} is unchanged. If an agent was working, it may have been stopped.`,
}),
);
}

function describe(
move: WorkspaceMoveProgress,
t: ReturnType<typeof useLingui>["t"],
): string {
function describe(move: WorkspaceMoveProgress, i18n: I18n): string {
const chats = move.chats;
switch (move.stage) {
case "saving":
return t({ message: "Saving its work and its chats…" });
return i18n._(msg({ message: "Saving its work and its chats…" }));
case "creating":
return t({ message: "Setting up the new workspace…" });
case "moving-chats":
return i18n._(msg({ message: "Setting up the new workspace…" }));
case "moving-chats": {
if (!chats || chats.total === 0) {
return t({ message: "Finishing the move…" });
return i18n._(msg({ message: "Finishing the move…" }));
}
return describeChatCount(chats.ready + chats.failed, chats.total, t);
const done = chats.ready + chats.failed;
return i18n._(
msg({
message: plural(chats.total, {
one: `${done} of # chat moved`,
other: `${done} of # chats moved`,
}),
}),
);
}
case "ready":
return t({ message: "Everything moved." });
return i18n._(msg({ message: "Everything moved." }));
case "partial":
return t({
message: plural(chats?.failed ?? 0, {
one: "# chat could not move. Open it to try again.",
other: "# chats could not move. Open them to try again.",
return i18n._(
msg({
message: plural(chats?.failed ?? 0, {
one: "# chat could not move. Open it to try again.",
other: "# chats could not move. Open them to try again.",
}),
}),
});
);
case "cancelled":
return t({
message: `${move.name} stays where it was. If an agent was working, it may have been stopped.`,
});
return i18n._(
msg({
message: `${move.name} stays where it was. If an agent was working, it may have been stopped.`,
}),
);
case "unverified":
return t({
message:
"Open the new workspace to see each chat. A chat that didn't move is still in the original workspace.",
});
return i18n._(
msg({
message:
"Open the new workspace to see each chat. A chat that didn't move is still in the original workspace.",
}),
);
case "failed":
return describeMoveError(move.error).reason;
return i18n._(
msg({
message:
"Its chats didn't move and are still in the original workspace. Open the new workspace to see why and try again.",
}),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ export function useMoveWorkspaceToCloud(workspace: MovableWorkspace) {
environment,
machineSize,
onStage,
onBegun,
signal,
}: {
environment: { id: string; repositoryFullName: string | null };
machineSize: MachineSize;
onStage: (stage: MoveToCloudStage) => void;
onBegun?: (workspaceMoveId: string) => void;
signal?: AbortSignal;
}) => {
if (!organizationId) throw new Error(t`No active organization`);
Expand All @@ -72,6 +74,7 @@ export function useMoveWorkspaceToCloud(workspace: MovableWorkspace) {
fromWorkspaceId: workspace.id,
fromHostId: workspace.hostId,
});
onBegun?.(workspaceMoveId);
const source = getHostServiceClientByUrl(activeHostUrl);
const leaving: { chats: string[] } = { chats: [] };
const { prepared, created } = await keepMoveAlive({
Expand Down Expand Up @@ -105,7 +108,7 @@ export function useMoveWorkspaceToCloud(workspace: MovableWorkspace) {
return { prepared, created };
},
}).catch(async (error: unknown) => {
await abandonWorkspaceMove(workspaceMoveId, error);
await abandonWorkspaceMove(workspaceMoveId, error, signal?.aborted);
await releaseSourceChats(source, leaving.chats);
throw error;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { plural } from "@lingui/core/macro";
import { useLingui } from "@lingui/react/macro";
import { toast } from "@superset/ui/sonner";
import { useNavigate } from "@tanstack/react-router";
import { useCallback } from "react";
import { useHostProjects } from "renderer/hooks/host-projects/useHostProjects";
import { resolveHostUrl } from "renderer/hooks/host-service/useHostTargetUrl";
import { useCloudWorkspaces } from "renderer/hooks/useCloudWorkspaces";
import { useRelayUrl } from "renderer/hooks/useRelayUrl";
import { cloudTrpcClient } from "renderer/lib/cloud-trpc";
import {
getHostServiceClientByUrl,
type HostServiceClient,
} from "renderer/lib/host-service-client";
import { useCollections } from "renderer/routes/_authenticated/providers/CollectionsProvider";
import { useHostWorkspaces } from "renderer/routes/_authenticated/providers/HostWorkspacesProvider";
import { useLocalHostService } from "renderer/routes/_authenticated/providers/LocalHostServiceProvider";
import { requestSandboxAccess } from "renderer/routes/_authenticated/utils/requestSandboxAccess";
import { useWorkspaceCreates } from "renderer/stores/workspace-creates";
Expand Down Expand Up @@ -41,7 +39,7 @@ export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
const { activeHostUrl, machineId, activeOrganizationId } =
useLocalHostService();
const relayUrl = useRelayUrl();
const { cache } = useHostWorkspaces();
const { workspaces: cloudWorkspaces = [] } = useCloudWorkspaces();
const { projects } = useHostProjects();
const { submit } = useWorkspaceCreates();
const collections = useCollections();
Expand All @@ -50,10 +48,12 @@ export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
async ({
destination,
onStage,
onBegun,
signal,
}: {
destination: MoveDestination;
onStage: (stage: MoveToComputerStage) => void;
onBegun?: (workspaceMoveId: string) => void;
signal?: AbortSignal;
}) => {
const hostUrlOf = (hostId: string) => {
Expand All @@ -70,7 +70,7 @@ export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
return url;
};
const destinationUrl = hostUrlOf(destination.hostId);
const fromCloud = cache.isSandboxHost(workspace.hostId);
const fromCloud = cloudWorkspaces.some((row) => row.id === workspace.id);
const requireProject = (repositoryName: string) => {
const repository = repositoryName.toLowerCase();
const found = projects.find(
Expand Down Expand Up @@ -99,6 +99,7 @@ export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
...(fromCloud ? {} : { fromHostId: workspace.hostId }),
toHostId: destination.hostId,
});
onBegun?.(workspaceMoveId);
const target = getHostServiceClientByUrl(destinationUrl);
const leaving: { source: HostServiceClient | null; chats: string[] } = {
source: null,
Expand Down Expand Up @@ -169,7 +170,7 @@ export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
return { prepared, project, created, moves, skipped };
},
}).catch(async (error: unknown) => {
await abandonWorkspaceMove(workspaceMoveId, error);
await abandonWorkspaceMove(workspaceMoveId, error, signal?.aborted);
if (leaving.source) {
await releaseSourceChats(leaving.source, leaving.chats);
}
Expand Down Expand Up @@ -205,31 +206,15 @@ export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
error,
);
});
// Each chat's pane shows how far its move got, and a retry.
// Each chat's pane shows how far its move got, its failure and a retry.
void (async () => {
let failed = 0;
for (const { moveId } of moves) {
await runMoveOnComputer({ moveId, host: target }).catch(
(error: unknown) => {
failed += 1;
(error: unknown) =>
console.warn(
`[workspace-move] move ${moveId} to the computer failed`,
error,
);
},
);
}
if (failed > 0) {
toast.error(
t({
message: plural(failed, {
one: "# chat couldn't move to the computer",
other: "# chats couldn't move to the computer",
}),
}),
{
description: t`They are still in the original workspace. Open each one to try again.`,
},
),
);
}
})();
Expand All @@ -248,7 +233,7 @@ export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
machineId,
activeOrganizationId,
relayUrl,
cache,
cloudWorkspaces,
projects,
submit,
navigate,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useResumeMovesToThisComputer } from "./useResumeMovesToThisComputer";
Loading
Loading