Fix vercel deployment fetching (#758)
This commit is contained in:
@@ -4,6 +4,7 @@ import { Globe } from "lucide-react";
|
|||||||
import { IpcClient } from "@/ipc/ipc_client";
|
import { IpcClient } from "@/ipc/ipc_client";
|
||||||
import { useSettings } from "@/hooks/useSettings";
|
import { useSettings } from "@/hooks/useSettings";
|
||||||
import { useLoadApp } from "@/hooks/useLoadApp";
|
import { useLoadApp } from "@/hooks/useLoadApp";
|
||||||
|
import { useVercelDeployments } from "@/hooks/useVercelDeployments";
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -14,7 +15,7 @@ import {
|
|||||||
import {} from "@/components/ui/dialog";
|
import {} from "@/components/ui/dialog";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { App, VercelDeployment } from "@/ipc/ipc_types";
|
import { App } from "@/ipc/ipc_types";
|
||||||
|
|
||||||
interface VercelConnectorProps {
|
interface VercelConnectorProps {
|
||||||
appId: number | null;
|
appId: number | null;
|
||||||
@@ -46,41 +47,19 @@ function ConnectedVercelConnector({
|
|||||||
app,
|
app,
|
||||||
refreshApp,
|
refreshApp,
|
||||||
}: ConnectedVercelConnectorProps) {
|
}: ConnectedVercelConnectorProps) {
|
||||||
const [isLoadingDeployments, setIsLoadingDeployments] = useState(false);
|
const {
|
||||||
const [deploymentsError, setDeploymentsError] = useState<string | null>(null);
|
deployments,
|
||||||
const [deployments, setDeployments] = useState<VercelDeployment[]>([]);
|
isLoading: isLoadingDeployments,
|
||||||
const [isDisconnecting, setIsDisconnecting] = useState(false);
|
error: deploymentsError,
|
||||||
const [disconnectError, setDisconnectError] = useState<string | null>(null);
|
getDeployments: handleGetDeployments,
|
||||||
|
disconnectProject,
|
||||||
|
isDisconnecting,
|
||||||
|
disconnectError,
|
||||||
|
} = useVercelDeployments(appId);
|
||||||
|
|
||||||
const handleDisconnectProject = async () => {
|
const handleDisconnectProject = async () => {
|
||||||
setIsDisconnecting(true);
|
await disconnectProject();
|
||||||
setDisconnectError(null);
|
refreshApp();
|
||||||
try {
|
|
||||||
await IpcClient.getInstance().disconnectVercelProject({ appId });
|
|
||||||
refreshApp();
|
|
||||||
} catch (err: any) {
|
|
||||||
setDisconnectError(err.message || "Failed to disconnect project.");
|
|
||||||
} finally {
|
|
||||||
setIsDisconnecting(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleGetDeployments = async () => {
|
|
||||||
setIsLoadingDeployments(true);
|
|
||||||
setDeploymentsError(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await IpcClient.getInstance().getVercelDeployments({
|
|
||||||
appId,
|
|
||||||
});
|
|
||||||
setDeployments(result);
|
|
||||||
} catch (err: any) {
|
|
||||||
setDeploymentsError(
|
|
||||||
err.message || "Failed to get deployments from Vercel.",
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
setIsLoadingDeployments(false);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -154,7 +133,7 @@ function ConnectedVercelConnector({
|
|||||||
Getting Deployments...
|
Getting Deployments...
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
"Get Deployments"
|
"Refresh Deployments"
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
@@ -193,7 +172,7 @@ function ConnectedVercelConnector({
|
|||||||
{deployment.readyState}
|
{deployment.readyState}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-sm text-gray-600 dark:text-gray-300">
|
<span className="text-sm text-gray-600 dark:text-gray-300">
|
||||||
{new Date(deployment.createdAt * 1000).toLocaleString()}
|
{new Date(deployment.createdAt).toLocaleString()}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<a
|
<a
|
||||||
|
|||||||
50
src/hooks/useVercelDeployments.ts
Normal file
50
src/hooks/useVercelDeployments.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { IpcClient } from "@/ipc/ipc_client";
|
||||||
|
import { VercelDeployment } from "@/ipc/ipc_types";
|
||||||
|
|
||||||
|
export function useVercelDeployments(appId: number) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: deployments = [],
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
refetch,
|
||||||
|
} = useQuery<VercelDeployment[], Error>({
|
||||||
|
queryKey: ["vercel-deployments", appId],
|
||||||
|
queryFn: async () => {
|
||||||
|
const ipcClient = IpcClient.getInstance();
|
||||||
|
return ipcClient.getVercelDeployments({ appId });
|
||||||
|
},
|
||||||
|
// enabled: false, // Don't auto-fetch, only fetch when explicitly requested
|
||||||
|
});
|
||||||
|
|
||||||
|
const disconnectProjectMutation = useMutation<void, Error, void>({
|
||||||
|
mutationFn: async () => {
|
||||||
|
const ipcClient = IpcClient.getInstance();
|
||||||
|
return ipcClient.disconnectVercelProject({ appId });
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
// Clear deployments cache when project is disconnected
|
||||||
|
queryClient.removeQueries({ queryKey: ["vercel-deployments", appId] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const getDeployments = async () => {
|
||||||
|
return refetch();
|
||||||
|
};
|
||||||
|
|
||||||
|
const disconnectProject = async () => {
|
||||||
|
return disconnectProjectMutation.mutateAsync();
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
deployments,
|
||||||
|
isLoading,
|
||||||
|
error: error?.message || null,
|
||||||
|
getDeployments,
|
||||||
|
disconnectProject,
|
||||||
|
isDisconnecting: disconnectProjectMutation.isPending,
|
||||||
|
disconnectError: disconnectProjectMutation.error?.message || null,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
CreateVercelProjectParams,
|
CreateVercelProjectParams,
|
||||||
IsVercelProjectAvailableParams,
|
IsVercelProjectAvailableParams,
|
||||||
SaveVercelAccessTokenParams,
|
SaveVercelAccessTokenParams,
|
||||||
|
VercelDeployment,
|
||||||
VercelProject,
|
VercelProject,
|
||||||
} from "../ipc_types";
|
} from "../ipc_types";
|
||||||
import { ConnectToExistingVercelProjectParams } from "../ipc_types";
|
import { ConnectToExistingVercelProjectParams } from "../ipc_types";
|
||||||
@@ -400,16 +401,7 @@ async function handleConnectToExistingProject(
|
|||||||
async function handleGetVercelDeployments(
|
async function handleGetVercelDeployments(
|
||||||
event: IpcMainInvokeEvent,
|
event: IpcMainInvokeEvent,
|
||||||
{ appId }: GetVercelDeploymentsParams,
|
{ appId }: GetVercelDeploymentsParams,
|
||||||
): Promise<
|
): Promise<VercelDeployment[]> {
|
||||||
{
|
|
||||||
uid: string;
|
|
||||||
url: string;
|
|
||||||
state: string;
|
|
||||||
createdAt: number;
|
|
||||||
target: string;
|
|
||||||
readyState: string;
|
|
||||||
}[]
|
|
||||||
> {
|
|
||||||
try {
|
try {
|
||||||
const settings = readSettings();
|
const settings = readSettings();
|
||||||
const accessToken = settings.vercelAccessToken?.value;
|
const accessToken = settings.vercelAccessToken?.value;
|
||||||
|
|||||||
@@ -272,15 +272,6 @@ export interface GetAppEnvVarsParams {
|
|||||||
appId: number;
|
appId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VercelDeployment {
|
|
||||||
uid: string;
|
|
||||||
url: string;
|
|
||||||
state: string;
|
|
||||||
createdAt: number;
|
|
||||||
target: string;
|
|
||||||
readyState: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ConnectToExistingVercelProjectParams {
|
export interface ConnectToExistingVercelProjectParams {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
appId: number;
|
appId: number;
|
||||||
@@ -300,6 +291,15 @@ export interface GetVercelDeploymentsParams {
|
|||||||
appId: number;
|
appId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface VercelDeployment {
|
||||||
|
uid: string;
|
||||||
|
url: string;
|
||||||
|
state: string;
|
||||||
|
createdAt: number;
|
||||||
|
target: string;
|
||||||
|
readyState: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface DisconnectVercelProjectParams {
|
export interface DisconnectVercelProjectParams {
|
||||||
appId: number;
|
appId: number;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user