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
@@ -1,3 +1,4 @@
import { Trans, useLingui } from "@lingui/react/macro";
import type { MachineSize } from "@superset/shared/billing";
import {
DropdownMenu,
Expand All @@ -12,7 +13,7 @@ import { useMachineSizeOptions } from "renderer/routes/_authenticated/hooks/useM

interface MachineSizePickerProps {
value: MachineSize | null;
onChange: (machineSize: MachineSize) => void;
onChange: (machineSize: MachineSize | null) => void;
className?: string;
disabled?: boolean;
}
Expand All @@ -23,10 +24,9 @@ export function MachineSizePicker({
className,
disabled,
}: MachineSizePickerProps) {
const { options, defaultSize } = useMachineSizeOptions();
const selected =
options.find((option) => option.size === value) ??
options.find((option) => option.size === defaultSize);
const { t } = useLingui();
const { options } = useMachineSizeOptions();
const selected = options.find((option) => option.size === value);

return (
<DropdownMenu>
Expand All @@ -35,11 +35,23 @@ export function MachineSizePicker({
disabled={disabled}
className={className}
icon={<LuCpu className="size-4 shrink-0" />}
label={selected?.name ?? value ?? defaultSize}
label={
selected?.name ?? value ?? t({ message: "Environment's size" })
}
title={selected?.spec}
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-64">
<DropdownMenuItem
onSelect={() => onChange(null)}
className="items-start gap-2"
>
<LuCpu className="mt-0.5 size-4 shrink-0" />
<span className="flex-1">
<Trans>Environment's size</Trans>
</span>
{value === null && <HiCheck className="mt-0.5 size-4 shrink-0" />}
</DropdownMenuItem>
{options.map((option) => (
<DropdownMenuItem
key={option.size}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
useWorkspaceRowContextMenu,
} from "./components/DashboardSidebarWorkspaceBulkContextMenu";
import { DashboardSidebarWorkspaceContextMenu } from "./components/DashboardSidebarWorkspaceContextMenu/DashboardSidebarWorkspaceContextMenu";
import { ManageEnvironmentItem } from "./components/ManageEnvironmentItem";
import { useDashboardSidebarWorkspaceItemActions } from "./hooks/useDashboardSidebarWorkspaceItemActions";

interface DashboardSidebarWorkspaceItemProps {
Expand Down Expand Up @@ -73,6 +74,9 @@ export function DashboardSidebarWorkspaceItem({
} = workspace;
const isSessionWorkspace = workspace.type === "session";
const isCloudWorkspace = hostType === "cloud";
const environmentItem = isCloudWorkspace ? (
<ManageEnvironmentItem workspaceId={id} />
) : undefined;
const moveDirections = useWorkspaceMoveDirections(workspace.hostId);
const move =
moveDirections.length > 0
Expand Down Expand Up @@ -296,6 +300,7 @@ export function DashboardSidebarWorkspaceItem({
onRemovePullRequest={handleRemovePullRequest}
onRename={startRename}
onDelete={requestDelete}
environmentItem={environmentItem}
onToggleUnread={handleToggleUnread}
onClearStatus={handleClearStatus}
>
Expand Down Expand Up @@ -387,6 +392,7 @@ export function DashboardSidebarWorkspaceItem({
onRemovePullRequest={handleRemovePullRequest}
onRename={startRename}
onDelete={requestDelete}
environmentItem={environmentItem}
onToggleUnread={handleToggleUnread}
onClearStatus={handleClearStatus}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ interface DashboardSidebarWorkspaceContextMenuProps {
onRemoveFromSidebar?: () => void;
onRename?: () => void;
onDelete?: () => void;
environmentItem?: React.ReactNode;
onToggleUnread: () => void;
onClearStatus: () => void;
onRemovePullRequest: () => void;
Expand Down Expand Up @@ -109,6 +110,7 @@ export function DashboardSidebarWorkspaceContextMenu({
onRemoveFromSidebar,
onRename,
onDelete,
environmentItem,
onToggleUnread,
onClearStatus,
onRemovePullRequest,
Expand Down Expand Up @@ -249,6 +251,7 @@ export function DashboardSidebarWorkspaceContextMenu({
)}
</>
)}
{environmentItem}
{move && (
<>
<ContextMenuSeparator />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Trans } from "@lingui/react/macro";
import {
ContextMenuItem,
ContextMenuSeparator,
} from "@superset/ui/context-menu";
import { useNavigate } from "@tanstack/react-router";
import { LuContainer } from "react-icons/lu";
import { useWorkspaceEnvironment } from "renderer/routes/_authenticated/_dashboard/hooks/useWorkspaceEnvironment";

/** Rendered only inside an open menu, so closed sidebar rows look nothing up. */
export function ManageEnvironmentItem({
workspaceId,
}: {
workspaceId: string;
}) {
const navigate = useNavigate();
const environment = useWorkspaceEnvironment(workspaceId);
if (!environment) return null;
return (
<>
<ContextMenuSeparator />
<ContextMenuItem
onSelect={() =>
void navigate({
to: "/settings/environments/$environmentId",
params: { environmentId: environment.id },
})
}
>
<LuContainer className="size-4 mr-2" />
<Trans>Manage environment</Trans>
</ContextMenuItem>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ManageEnvironmentItem } from "./ManageEnvironmentItem";
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import { useActiveOrganizationId } from "renderer/hooks/useActiveOrganizationId"
import { cloudTrpc } from "renderer/lib/cloud-trpc";
import { CreateEnvironmentFlow } from "renderer/routes/_authenticated/components/CreateEnvironmentFlow";
import { EnvironmentPickerPill } from "renderer/routes/_authenticated/components/EnvironmentPickerPill";
import { MachineSizePickerPill } from "renderer/routes/_authenticated/components/MachineSizePickerPill";
import { useMachineSizeOptions } from "renderer/routes/_authenticated/hooks/useMachineSizeOptions";
import { resolveCloudChoices } from "renderer/routes/_authenticated/utils/resolveCloudChoices";
import {
NO_PROJECT_KEY,
Expand Down Expand Up @@ -61,7 +59,6 @@ export function MoveWorkspaceToCloudDialog({
{ organizationId: organizationId ?? "" },
{ enabled: open && !!organizationId },
);
const machineSizeOptions = useMachineSizeOptions();
const cloudChoices = useV2WorkspaceCreateDefaultsStore(
(state) => state.cloudChoices,
);
Expand All @@ -76,16 +73,8 @@ export function MoveWorkspaceToCloudDialog({
projectId,
repositoryFullName,
choices: cloudChoices,
offeredSizes: machineSizeOptions.options.map((option) => option.size),
defaultSize: machineSizeOptions.defaultSize,
}),
[
environmentsQuery.data,
projectId,
repositoryFullName,
cloudChoices,
machineSizeOptions,
],
[environmentsQuery.data, projectId, repositoryFullName, cloudChoices],
);
const environment = selection.environment;

Expand All @@ -104,7 +93,6 @@ export function MoveWorkspaceToCloudDialog({
id: environment.id,
repositoryFullName: environment.repositories?.[0]?.fullName ?? null,
},
machineSize: selection.machineSize,
onStage: (stage) =>
progress.setStage(stage === "saving" ? "saving" : "creating"),
onBegun: progress.begun,
Expand Down Expand Up @@ -163,13 +151,6 @@ export function MoveWorkspaceToCloudDialog({
}}
isLoading={environmentsQuery.isLoading}
/>
<MachineSizePickerPill
triggerClassName={PICKER_TRIGGER_CLASS}
machineSize={selection.machineSize}
onSelectMachineSize={(machineSize) =>
setCloudChoice(choiceKey, { machineSize })
}
/>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => onOpenChange(false)}>
Expand All @@ -185,8 +166,9 @@ export function MoveWorkspaceToCloudDialog({
<CreateEnvironmentFlow
open={isCreatingEnvironment}
onOpenChange={setIsCreatingEnvironment}
onStarted={() => onOpenChange(false)}
organizationId={organizationId}
projectId={projectId}
project={projectId ? { id: projectId, repositoryFullName } : null}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
import { Trans } from "@lingui/react/macro";
import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { HiArrowLeft } from "react-icons/hi2";
import { EnvironmentView } from "renderer/routes/_authenticated/components/EnvironmentView";
import { createFileRoute, redirect } from "@tanstack/react-router";

export const Route = createFileRoute(
"/_authenticated/_dashboard/environments/$environmentId/",
)({
component: EnvironmentPage,
beforeLoad: ({ params }) => {
throw redirect({
to: "/settings/environments/$environmentId",
params: { environmentId: params.environmentId },
replace: true,
});
},
});

function EnvironmentPage() {
const { environmentId } = Route.useParams();
const navigate = useNavigate();
const backToSettings = () => navigate({ to: "/settings/environments" });

return (
<div className="flex h-full w-full flex-col overflow-hidden bg-background">
<div className="flex h-12 shrink-0 items-center px-4">
<button
className="flex items-center gap-2 text-sm text-muted-foreground transition-colors hover:text-foreground"
onClick={backToSettings}
type="button"
>
<HiArrowLeft className="size-4" />
<Trans>Environments</Trans>
</button>
</div>
<div className="mx-auto flex min-h-0 w-full max-w-2xl flex-1 flex-col">
<EnvironmentView
environmentId={environmentId}
onArchived={backToSettings}
/>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useLingui } from "@lingui/react/macro";
import type { MachineSize } from "@superset/shared/billing";
import { useCallback } from "react";
import { useHostProjects } from "renderer/hooks/host-projects/useHostProjects";
import { useActiveOrganizationId } from "renderer/hooks/useActiveOrganizationId";
Expand Down Expand Up @@ -39,13 +38,11 @@ export function useMoveWorkspaceToCloud(workspace: MovableWorkspace) {
return useCallback(
async ({
environment,
machineSize,
onStage,
onBegun,
signal,
}: {
environment: { id: string; repositoryFullName: string | null };
machineSize: MachineSize;
onStage: (stage: MoveToCloudStage) => void;
onBegun?: (workspaceMoveId: string) => void;
signal?: AbortSignal;
Expand Down Expand Up @@ -95,7 +92,6 @@ export function useMoveWorkspaceToCloud(workspace: MovableWorkspace) {
const created = await cloudTrpcClient.cloudWorkspace.create.mutate({
organizationId,
environmentId: environment.id,
machineSize,
name: workspace.name,
branch: prepared.branch,
move: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
useWorkspaceEnvironment,
type WorkspaceEnvironment,
} from "./useWorkspaceEnvironment";
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useCloudWorkspaces } from "renderer/hooks/useCloudWorkspaces";
import { cloudTrpc } from "renderer/lib/cloud-trpc";

export interface WorkspaceEnvironment {
id: string;
name: string;
sourceKind: string;
scope: string;
createdByUserId: string | null;
}

/** The cloud workspace's environment, when this user can open it: a teammate's personal environment is not listed. */
export function useWorkspaceEnvironment(
workspaceId: string,
): WorkspaceEnvironment | null {
const { workspaces, organizationId } = useCloudWorkspaces();
const environmentId =
workspaces?.find((workspace) => workspace.id === workspaceId)
?.environmentId ?? null;
const environments = cloudTrpc.environment.list.useQuery(
{ organizationId: organizationId ?? "" },
{ enabled: !!environmentId && !!organizationId },
);
const environment = environments.data?.find(
(row) => row.id === environmentId,
);
return environment
? {
id: environment.id,
name: environment.name,
sourceKind: environment.sourceKind,
scope: environment.scope,
createdByUserId: environment.createdByUserId,
}
: null;
}
Loading
Loading