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 @@ -28,7 +28,7 @@ import {
import { useMoveWorkspaceToCloud } from "../../../../hooks/useMoveWorkspaceToCloud";
import type { MovableWorkspace } from "../../../../hooks/useWorkspaceMoveDirections";
import { startWorkspaceMoveProgress } from "../../../../utils/startWorkspaceMoveProgress";
import { useReportSkippedChats } from "../../hooks/useReportSkippedChats";
import { navigateToV2Workspace } from "../../../../utils/workspace-navigation";

interface MoveWorkspaceToCloudDialogProps {
open: boolean;
Expand All @@ -49,7 +49,6 @@ export function MoveWorkspaceToCloudDialog({
const organizationId = useActiveOrganizationId();
const [isCreatingEnvironment, setIsCreatingEnvironment] = useState(false);
const moveWorkspaceToCloud = useMoveWorkspaceToCloud(workspace);
const reportSkipped = useReportSkippedChats();
const projectId = workspace.projectId;

const { projects } = useHostProjects();
Expand Down Expand Up @@ -95,6 +94,8 @@ export function MoveWorkspaceToCloudDialog({
const progress = startWorkspaceMoveProgress({
name: workspace.name,
destination: t({ message: "the cloud" }),
toCloud: true,
sourceWorkspaceId: workspace.id,
retry: move,
});
onOpenChange(false);
Expand All @@ -109,10 +110,12 @@ export function MoveWorkspaceToCloudDialog({
onBegun: progress.begun,
signal: progress.signal,
})
.then(({ toWorkspaceId, skipped }) => {
progress.follow(toWorkspaceId);
reportSkipped(skipped);
})
.then(({ toWorkspaceId, stayed }) =>
progress.follow(toWorkspaceId, {
stayed,
open: () => void navigateToV2Workspace(toWorkspaceId, navigate),
}),
)
.catch((error: unknown) =>
progress.fail(
isMissingProcedureError(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import {
SelectTrigger,
SelectValue,
} from "@superset/ui/select";
import { useNavigate } from "@tanstack/react-router";
import { useMemo, useState } from "react";
import { useKnownHosts } from "renderer/hooks/known-hosts/useKnownHosts";
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";
import { startWorkspaceMoveProgress } from "../../../../utils/startWorkspaceMoveProgress";
import { useReportSkippedChats } from "../../hooks/useReportSkippedChats";
import { navigateToV2Workspace } from "../../../../utils/workspace-navigation";

interface MoveWorkspaceToComputerDialogProps {
open: boolean;
Expand All @@ -38,11 +39,11 @@ export function MoveWorkspaceToComputerDialog({
workspace,
}: MoveWorkspaceToComputerDialogProps) {
const { t } = useLingui();
const navigate = useNavigate();
const { machineId } = useLocalHostService();
const { hosts } = useKnownHosts();
const { workspaces: cloudWorkspaces = [] } = useCloudWorkspaces();
const moveWorkspaceToComputer = useMoveWorkspaceToComputer(workspace);
const reportSkipped = useReportSkippedChats();

const computers = useMemo(() => {
const others = hosts
Expand Down Expand Up @@ -81,6 +82,8 @@ export function MoveWorkspaceToComputerDialog({
const progress = startWorkspaceMoveProgress({
name: workspace.name,
destination: destination.label ?? t({ message: "this computer" }),
toCloud: false,
sourceWorkspaceId: workspace.id,
retry: move,
});
onOpenChange(false);
Expand All @@ -90,10 +93,12 @@ export function MoveWorkspaceToComputerDialog({
onBegun: progress.begun,
signal: progress.signal,
})
.then(({ toWorkspaceId, skipped }) => {
progress.follow(toWorkspaceId);
reportSkipped(skipped);
})
.then(({ toWorkspaceId, stayed }) =>
progress.follow(toWorkspaceId, {
stayed,
open: () => void navigateToV2Workspace(toWorkspaceId, navigate),
}),
)
.catch((error: unknown) =>
progress.fail(
isMissingProcedureError(error)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function WorkspaceMoveToast({ moveId }: { moveId: string }) {
? describeMoveError(move.error)
: null;
const retry = failure ? move.retry : null;
const openable = move.open !== null && !failure && ended;

const title =
move.stage === "failed"
Expand Down Expand Up @@ -82,10 +83,17 @@ export function WorkspaceMoveToast({ moveId }: { moveId: string }) {
<p className="mt-1 font-mono break-words">{failure.details}</p>
</details>
)}
{ended && !failure && move.stayed.length > 0 && (
<p className="mt-1 truncate text-xs text-muted-foreground/70">
{move.stage === "ready"
? move.stayed.join(", ")
: `${stayedSentence(move.stayed.length, i18n)} ${move.stayed.join(", ")}`}
</p>
)}
{!ended && (
<Progress className="mt-3 h-1.5" value={progressPercent(move)} />
)}
{((move.cancel && CANCELLABLE.has(move.stage)) || retry) && (
{((move.cancel && CANCELLABLE.has(move.stage)) || retry || openable) && (
<div className="mt-3 flex justify-end gap-2">
{move.cancel && CANCELLABLE.has(move.stage) && (
<Button size="sm" variant="outline" onClick={move.cancel}>
Expand All @@ -97,6 +105,11 @@ export function WorkspaceMoveToast({ moveId }: { moveId: string }) {
<Trans>Try again</Trans>
</Button>
)}
{openable && move.open && (
<Button size="sm" onClick={move.open}>
<Trans>Open</Trans>
</Button>
)}
</div>
)}
</div>
Expand Down Expand Up @@ -131,6 +144,18 @@ function describe(move: WorkspaceMoveProgress, i18n: I18n): string {
return i18n._(msg({ message: "Finishing the move…" }));
}
const done = chats.ready + chats.failed;
if (done === 0) {
return move.toCloud
? i18n._(msg({ message: "Starting the cloud workspace…" }))
: i18n._(
msg({
message: plural(chats.total, {
one: "Moving its chat…",
other: "Moving its chats…",
}),
}),
);
}
return i18n._(
msg({
message: plural(chats.total, {
Expand All @@ -141,7 +166,9 @@ function describe(move: WorkspaceMoveProgress, i18n: I18n): string {
);
}
case "ready":
return i18n._(msg({ message: "Everything moved." }));
return move.stayed.length === 0
? i18n._(msg({ message: "Everything moved." }))
: stayedSentence(move.stayed.length, i18n);
case "partial":
return i18n._(
msg({
Expand Down Expand Up @@ -173,3 +200,14 @@ function describe(move: WorkspaceMoveProgress, i18n: I18n): string {
);
}
}

function stayedSentence(count: number, i18n: I18n): string {
return i18n._(
msg({
message: plural(count, {
one: "# chat stayed in the old workspace.",
other: "# chats stayed in the old workspace.",
}),
}),
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useLingui } from "@lingui/react/macro";
import type { MachineSize } from "@superset/shared/billing";
import { useNavigate } from "@tanstack/react-router";
import { useCallback } from "react";
import { useHostProjects } from "renderer/hooks/host-projects/useHostProjects";
import { useActiveOrganizationId } from "renderer/hooks/useActiveOrganizationId";
Expand All @@ -23,7 +22,6 @@ export type MoveToCloudStage = "saving" | "starting";
*/
export function useMoveWorkspaceToCloud(workspace: MovableWorkspace) {
const { t } = useLingui();
const navigate = useNavigate();
const organizationId = useActiveOrganizationId();
const collections = useCollections();
const utils = cloudTrpc.useUtils();
Expand Down Expand Up @@ -139,21 +137,12 @@ export function useMoveWorkspaceToCloud(workspace: MovableWorkspace) {
rows ? [created, ...rows] : [created],
);
void utils.cloudWorkspace.list.invalidate();
await navigate({
to: "/v2-workspace/$workspaceId",
params: { workspaceId: created.id },
}).catch((error: unknown) => {
console.warn(
"[workspace-move] could not open the cloud workspace",
error,
);
});
return {
toWorkspaceId: created.id,
skipped: [
...prepared.skipped,
stayed: [
...prepared.skipped.filter((chat) => chat.reason !== "not_started"),
...prepared.chats.filter((chat) => refused.has(chat.chatSessionId)),
],
].map((chat) => chat.title ?? t({ message: "Untitled chat" })),
};
},
[
Expand All @@ -162,7 +151,6 @@ export function useMoveWorkspaceToCloud(workspace: MovableWorkspace) {
t,
workspace,
utils,
navigate,
collections,
sourceRepository,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useLingui } from "@lingui/react/macro";
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";
Expand Down Expand Up @@ -35,7 +34,6 @@ export type MoveDestination = { hostId: string; name: string | null };
*/
export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
const { t } = useLingui();
const navigate = useNavigate();
const { activeHostUrl, machineId, activeOrganizationId } =
useLocalHostService();
const relayUrl = useRelayUrl();
Expand Down Expand Up @@ -197,15 +195,6 @@ export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
title: chat.title,
});
}
await navigate({
to: "/v2-workspace/$workspaceId",
params: { workspaceId: created.workspaceId },
}).catch((error: unknown) => {
console.warn(
"[workspace-move] could not open the new workspace",
error,
);
});
// Each chat's pane shows how far its move got, its failure and a retry.
void (async () => {
for (const { moveId } of moves) {
Expand All @@ -220,10 +209,10 @@ export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
})();
return {
toWorkspaceId: created.workspaceId,
skipped: [
...prepared.skipped,
stayed: [
...prepared.skipped.filter((chat) => chat.reason !== "not_started"),
...prepared.chats.filter((chat) => refused.has(chat.chatSessionId)),
],
].map((chat) => chat.title ?? t({ message: "Untitled chat" })),
};
},
[
Expand All @@ -236,7 +225,6 @@ export function useMoveWorkspaceToComputer(workspace: MovableWorkspace) {
cloudWorkspaces,
projects,
submit,
navigate,
collections,
],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const move: WorkspaceMoveProgress = {
workspaceMoveId: null,
name: "Workspace",
destination: "Cloud",
toCloud: true,
stayed: [],
open: null,
stage: "moving-chats",
chats: { total: 4, ready: 1, failed: 1 },
error: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export interface WorkspaceMoveProgress {
workspaceMoveId: string | null;
name: string;
destination: string;
/** A new cloud workspace boots before any chat can copy into it. */
toCloud: boolean;
stayed: string[];
open: (() => void) | null;
stage: WorkspaceMoveProgressStage;
chats: { total: number; ready: number; failed: number } | null;
error: string | null;
Expand Down
Loading
Loading