Skip to content

Commit 522968a

Browse files
committed
chore: Update version flow updates deployment (#4852)
## Problem solved Changes the "update Engine version" flow to query the infra backend to perform the version upgrade. Previously this would ping Slack for a thirdweb staff to update. <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on improving the code quality and user interface across various components in the dashboard. It includes updates to placeholders, text content, and the handling of engine updates. ### Detailed summary - Updated `placeholder` in `ip-allowlist.tsx` to use curly braces. - Added periods to sentences in `EngineImportPage.tsx` and `CreateEnginePage.tsx`. - Simplified conditional rendering in `engine-instances-table.tsx`. - Changed `cloudDeployedAt` to `deploymentId` in `useEngine.ts`. - Renamed `useEngineUpdateVersion` to `useEngineUpdateServerVersion`. - Updated fetch method to `PUT` for engine updates. - Changed variable names for clarity in `EngineVersionBadge.tsx`. - Updated props in `UpdateVersionModal` to use `latestVersion`. - Adjusted toast messages for better user feedback during engine updates. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 454f063 commit 522968a

File tree

6 files changed

+54
-45
lines changed

6 files changed

+54
-45
lines changed

apps/dashboard/src/@3rdweb-sdk/react/hooks/useEngine.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ export type EngineInstance = {
1818
name: string;
1919
url: string;
2020
lastAccessedAt: string;
21-
cloudDeployedAt?: string;
2221
status:
2322
| "active"
2423
| "pending"
2524
| "requested"
2625
| "deploying"
2726
| "paymentFailed"
2827
| "deploymentFailed";
28+
deploymentId?: string;
2929
};
3030

3131
// Not checking for null token because the token is required the tanstack useQuery hook
@@ -189,23 +189,26 @@ export function useEngineLatestVersion() {
189189

190190
interface UpdateVersionInput {
191191
engineId: string;
192+
serverVersion: string;
192193
}
193194

194-
export function useEngineUpdateVersion() {
195+
export function useEngineUpdateServerVersion() {
195196
return useMutation({
196197
mutationFn: async (input: UpdateVersionInput) => {
197198
invariant(input.engineId, "engineId is required");
198199

199-
const res = await fetch(`${THIRDWEB_API_HOST}/v1/engine/update-version`, {
200-
method: "POST",
201-
202-
headers: {
203-
"Content-Type": "application/json",
200+
const res = await fetch(
201+
`${THIRDWEB_API_HOST}/v2/engine/${input.engineId}/infrastructure`,
202+
{
203+
method: "PUT",
204+
headers: {
205+
"Content-Type": "application/json",
206+
},
207+
body: JSON.stringify({
208+
serverVersion: input.serverVersion,
209+
}),
204210
},
205-
body: JSON.stringify({
206-
engineId: input.engineId,
207-
}),
208-
});
211+
);
209212
// we never use the response body
210213
res.body?.cancel();
211214
if (!res.ok) {

apps/dashboard/src/components/engine/badges/version.tsx

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
type EngineInstance,
55
useEngineLatestVersion,
66
useEngineSystemHealth,
7-
useEngineUpdateVersion,
7+
useEngineUpdateServerVersion,
88
} from "@3rdweb-sdk/react/hooks/useEngine";
99
import { CircleArrowDownIcon, CloudDownloadIcon } from "lucide-react";
1010
import { useState } from "react";
@@ -30,15 +30,15 @@ export const EngineVersionBadge = ({
3030
const latestVersionQuery = useEngineLatestVersion();
3131
const [isModalOpen, setModalOpen] = useState(false);
3232

33-
const current = healthQuery.data?.engineVersion ?? "...";
34-
const latest = latestVersionQuery.data ?? "...";
35-
const isStale = current !== latest;
33+
const currentVersion = healthQuery.data?.engineVersion ?? "...";
34+
const latestVersion = latestVersionQuery.data;
35+
const isStale = latestVersion && currentVersion !== latestVersion;
3636

3737
if (!isStale) {
3838
return (
3939
<ToolTipLabel label="Latest Version">
4040
<Button variant="outline" asChild className="hover:bg-transparent">
41-
<div>{current}</div>
41+
<div>{currentVersion}</div>
4242
</Button>
4343
</ToolTipLabel>
4444
);
@@ -57,7 +57,7 @@ export const EngineVersionBadge = ({
5757
className="relative"
5858
onClick={() => setModalOpen(true)}
5959
>
60-
{current}
60+
{currentVersion}
6161

6262
{/* Notification Dot */}
6363
<span className="-top-1 -right-1 absolute">
@@ -66,26 +66,28 @@ export const EngineVersionBadge = ({
6666
</Button>
6767
</ToolTipLabel>
6868

69-
<UpdateVersionModal
70-
open={isModalOpen}
71-
onOpenChange={setModalOpen}
72-
latest={latest ?? ""}
73-
instance={instance}
74-
/>
69+
{latestVersion && (
70+
<UpdateVersionModal
71+
open={isModalOpen}
72+
onOpenChange={setModalOpen}
73+
latestVersion={latestVersion}
74+
instance={instance}
75+
/>
76+
)}
7577
</>
7678
);
7779
};
7880

7981
const UpdateVersionModal = (props: {
8082
open: boolean;
8183
onOpenChange: (open: boolean) => void;
82-
latest: string;
84+
latestVersion: string;
8385
instance: EngineInstance;
8486
}) => {
85-
const { open, onOpenChange, latest, instance } = props;
86-
const updateEngine = useEngineUpdateVersion();
87+
const { open, onOpenChange, latestVersion, instance } = props;
88+
const updateEngineServerMutation = useEngineUpdateServerVersion();
8789

88-
if (!instance.cloudDeployedAt) {
90+
if (!instance.deploymentId) {
8991
// For self-hosted, show a prompt to the Github release page.
9092
return (
9193
<Dialog open={open} onOpenChange={onOpenChange}>
@@ -95,19 +97,20 @@ const UpdateVersionModal = (props: {
9597
>
9698
<DialogHeader>
9799
<DialogTitle className="mb-6 pr-4 font-semibold text-2xl tracking-tight">
98-
Update your self-hosted Engine to {latest}
100+
Update your self-hosted Engine to {latestVersion}
99101
</DialogTitle>
100102
<DialogDescription>
101-
View the changelog in the
103+
View the{" "}
102104
<TrackedLinkTW
103105
href="https://github.com/thirdweb-dev/engine/releases"
104106
category="engine"
105107
label="clicked-engine-releases"
106108
target="_blank"
107109
className="text-link-foreground hover:text-foreground"
108110
>
109-
Engine Github repository
111+
latest changelog
110112
</TrackedLinkTW>
113+
.
111114
</DialogDescription>
112115
</DialogHeader>
113116
</DialogContent>
@@ -117,11 +120,13 @@ const UpdateVersionModal = (props: {
117120

118121
const onClick = async () => {
119122
try {
120-
const promise = updateEngine.mutateAsync({ engineId: instance.id });
123+
const promise = updateEngineServerMutation.mutateAsync({
124+
engineId: instance.id,
125+
serverVersion: latestVersion,
126+
});
121127
toast.promise(promise, {
122-
success:
123-
"Submitted a request to update your Engine instance. Please allow 1-2 business days for this process.",
124-
error: "Unexpected error updating your Engine instance.",
128+
success: `Upgrading your Engine to ${latestVersion}. Please confirm after a few minutes.`,
129+
error: "Unexpected error updating your Engine.",
125130
});
126131
await promise;
127132
} finally {
@@ -136,7 +141,12 @@ const UpdateVersionModal = (props: {
136141
dialogOverlayClassName="z-[10000]"
137142
>
138143
<DialogHeader>
139-
<DialogTitle>Update Engine to {latest}?</DialogTitle>
144+
<DialogTitle>Update Engine to {latestVersion}?</DialogTitle>
145+
146+
<DialogDescription>
147+
It is recommended to pause traffic to Engine before performing this
148+
upgrade. There is &lt; 1 minute of expected downtime.
149+
</DialogDescription>
140150
</DialogHeader>
141151

142152
<DialogFooter className="mt-5">
@@ -153,7 +163,7 @@ const UpdateVersionModal = (props: {
153163
variant="primary"
154164
className="gap-2"
155165
>
156-
{updateEngine.isPending ? (
166+
{updateEngineServerMutation.isPending ? (
157167
<Spinner className="size-4" />
158168
) : (
159169
<CloudDownloadIcon className="size-4" />

apps/dashboard/src/components/engine/configuration/ip-allowlist.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const EngineIpAllowlistConfig: React.FC<
8787
</Flex>
8888

8989
<Textarea
90-
placeholder="8.8.8.8\nff06:0:0:0:0:0:0:c3"
90+
placeholder={"8.8.8.8\nff06:0:0:0:0:0:0:c3"}
9191
rows={4}
9292
{...form.register("raw")}
9393
/>

apps/dashboard/src/components/engine/create/CreateEnginePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const CreateEnginePage = () => {
112112
</h1>
113113

114114
<p className="mb-7 text-muted-foreground">
115-
Host Engine on thirdweb with no setup or maintenance required
115+
Host Engine on thirdweb with no setup or maintenance required.
116116
</p>
117117

118118
<div className="grid grid-cols-1 gap-6 lg:grid-cols-3">

apps/dashboard/src/components/engine/engine-instances-table.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,7 @@ const EditModal = (props: {
266266
className="gap-2"
267267
disabled={!form.formState.isDirty}
268268
>
269-
{editInstance.isPending ? (
270-
<Spinner className="size-4" />
271-
) : (
272-
<SendIcon className="size-4" />
273-
)}
269+
{editInstance.isPending && <Spinner className="size-4" />}
274270
Update
275271
</Button>
276272
</DialogFooter>
@@ -292,7 +288,7 @@ const RemoveModal = (props: {
292288
<Dialog open={open} onOpenChange={onOpenChange}>
293289
<DialogContent className="z-[10001]" dialogOverlayClassName="z-[10000]">
294290
{instance.status === "paymentFailed" ||
295-
(instance.status === "active" && !instance.cloudDeployedAt) ? (
291+
(instance.status === "active" && !instance.deploymentId) ? (
296292
<RemoveFromDashboardModalContent
297293
refetch={refetch}
298294
instance={instance}

apps/dashboard/src/components/engine/import/EngineImportPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export const EngineImportPage = () => {
114114
<div className="mt-2 flex items-center gap-2">
115115
<CircleAlertIcon className="!static size-3 text-warning-foreground" />
116116
<p className="text-muted-foreground text-sm">
117-
Do not import a URL you do not recognize
117+
Do not import a URL you do not recognize.
118118
</p>
119119
</div>
120120
</FormControl>

0 commit comments

Comments
 (0)