Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit395e3f3

Browse files
committed
wip(site): Add support for informing of updates
1 parent6beb53d commit395e3f3

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

‎site/src/api/api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ export const getBuildInfo = async (): Promise<TypesGen.BuildInfoResponse> => {
376376
returnresponse.data
377377
}
378378

379+
exportconstgetUpdateCheck=
380+
async():Promise<TypesGen.UpdateCheckResponse>=>{
381+
constresponse=awaitaxios.get("/api/v2/updatecheck")
382+
returnresponse.data
383+
}
384+
379385
exportconstputWorkspaceAutostart=async(
380386
workspaceID:string,
381387
autostart:TypesGen.UpdateWorkspaceAutostartRequest,

‎site/src/testHelpers/entities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export const MockBuildInfo: TypesGen.BuildInfoResponse = {
2424
version:"v99.999.9999+c9cdf14",
2525
}
2626

27+
exportconstMockUpdateCheck:TypesGen.UpdateCheckResponse={
28+
current:true,
29+
url:"file:///mock-url",
30+
version:"v99.999.9999+c9cdf14",
31+
}
32+
2733
exportconstMockOwnerRole:TypesGen.Role={
2834
name:"owner",
2935
display_name:"Owner",

‎site/src/testHelpers/handlers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export const handlers = [
1515
returnres(ctx.status(200),ctx.json(M.MockBuildInfo))
1616
}),
1717

18+
// update check
19+
rest.get("/api/v2/updatecheck",async(req,res,ctx)=>{
20+
returnres(ctx.status(200),ctx.json(M.MockUpdateCheck))
21+
}),
22+
1823
// organizations
1924
rest.get("/api/v2/organizations/:organizationId",async(req,res,ctx)=>{
2025
returnres(ctx.status(200),ctx.json(M.MockOrganization))

‎site/src/xServices/StateContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createContext, FC, ReactNode } from "react"
33
import{ActorRefFrom}from"xstate"
44
import{authMachine}from"./auth/authXService"
55
import{buildInfoMachine}from"./buildInfo/buildInfoXService"
6+
import{updateCheckMachine}from"./updateCheck/updateCheckXService"
67
import{deploymentConfigMachine}from"./deploymentConfig/deploymentConfigMachine"
78
import{entitlementsMachine}from"./entitlements/entitlementsXService"
89
import{siteRolesMachine}from"./roles/siteRolesXService"
@@ -14,6 +15,7 @@ interface XServiceContextType {
1415
siteRolesXService:ActorRefFrom<typeofsiteRolesMachine>
1516
// Since the info here is used by multiple deployment settings page and we don't want to refetch them every time
1617
deploymentConfigXService:ActorRefFrom<typeofdeploymentConfigMachine>
18+
updateCheckXService:ActorRefFrom<typeofupdateCheckMachine>
1719
}
1820

1921
/**
@@ -35,6 +37,7 @@ export const XServiceProvider: FC<{ children: ReactNode }> = ({ children }) => {
3537
entitlementsXService:useInterpret(entitlementsMachine),
3638
siteRolesXService:useInterpret(siteRolesMachine),
3739
deploymentConfigXService:useInterpret(deploymentConfigMachine),
40+
updateCheckXService:useInterpret(updateCheckMachine),
3841
}}
3942
>
4043
{children}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import{assign,createMachine}from"xstate"
2+
import*asAPIfrom"../../api/api"
3+
import*asTypesGenfrom"../../api/typesGenerated"
4+
import{displayMsg}from"../../components/GlobalSnackbar/utils"
5+
6+
exportconstLanguage={
7+
updateAvailable:"New version available",
8+
updateAvailableMessage:(
9+
version:string,
10+
url:string,
11+
upgrade_instructions_url:string,
12+
):string=>
13+
`Coder${version} is now available at${url}. See${upgrade_instructions_url} for information on how to upgrade.`,
14+
}
15+
16+
exportinterfaceUpdateCheckContext{
17+
getUpdateCheckError?:Error|unknown
18+
updateCheck?:TypesGen.UpdateCheckResponse
19+
}
20+
21+
exportconstupdateCheckMachine=createMachine(
22+
{
23+
id:"updateCheckState",
24+
predictableActionArguments:true,
25+
tsTypes:{}asimport("./updateCheckXService.typegen").Typegen0,
26+
schema:{
27+
context:{}asUpdateCheckContext,
28+
services:{}as{
29+
getUpdateCheck:{
30+
data:TypesGen.UpdateCheckResponse
31+
}
32+
},
33+
},
34+
context:{
35+
updateCheck:undefined,
36+
},
37+
initial:"gettingUpdateCheck",
38+
states:{
39+
gettingUpdateCheck:{
40+
invoke:{
41+
src:"getUpdateCheck",
42+
id:"getUpdateCheck",
43+
onDone:[
44+
{
45+
actions:[
46+
"assignUpdateCheck",
47+
"clearGetUpdateCheckError",
48+
"notifyUpdateAvailable",
49+
],
50+
target:"#updateCheckState.success",
51+
},
52+
],
53+
onError:[
54+
{
55+
actions:["assignGetUpdateCheckError","clearUpdateCheck"],
56+
target:"#updateCheckState.failure",
57+
},
58+
],
59+
},
60+
},
61+
success:{
62+
type:"final",
63+
},
64+
failure:{
65+
type:"final",
66+
},
67+
},
68+
},
69+
{
70+
services:{
71+
getUpdateCheck:API.getUpdateCheck,
72+
},
73+
actions:{
74+
assignUpdateCheck:assign({
75+
updateCheck:(_,event)=>event.data,
76+
}),
77+
clearUpdateCheck:assign((context:UpdateCheckContext)=>({
78+
...context,
79+
updateCheck:undefined,
80+
})),
81+
assignGetUpdateCheckError:assign({
82+
getUpdateCheckError:(_,event)=>event.data,
83+
}),
84+
clearGetUpdateCheckError:assign((context:UpdateCheckContext)=>({
85+
...context,
86+
getUpdateCheckError:undefined,
87+
})),
88+
notifyUpdateAvailable:(context:UpdateCheckContext)=>{
89+
if(context.updateCheck&&!context.updateCheck.current){
90+
// TODO(mafredri): HTML formatting, persistance?
91+
displayMsg(
92+
Language.updateAvailable,
93+
Language.updateAvailableMessage(
94+
context.updateCheck.version,
95+
context.updateCheck.url,
96+
"https://coder.com/docs/coder-oss/latest/admin/upgrade",
97+
),
98+
)
99+
}
100+
},
101+
},
102+
},
103+
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp