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

Commitbadcfec

Browse files
committed
frontend
1 parentd7e6cd2 commitbadcfec

File tree

4 files changed

+103
-34
lines changed

4 files changed

+103
-34
lines changed

‎site/src/components/Workspace/Workspace.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const Workspace: React.FC<WorkspaceProps> = ({
5050
<WorkspaceSectiontitle="Applications">
5151
<Placeholder/>
5252
</WorkspaceSection>
53-
<WorkspaceScheduleautostart={workspace.autostart_schedule}autostop={workspace.autostop_schedule}/>
53+
<WorkspaceScheduleworkspace={workspace}/>
5454
<WorkspaceSectiontitle="Dev URLs">
5555
<Placeholder/>
5656
</WorkspaceSection>
Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import{Story}from"@storybook/react"
2+
importdayjsfrom"dayjs"
23
importReactfrom"react"
3-
import{MockWorkspaceAutostartEnabled}from"../../testHelpers/renderHelpers"
4+
import*asMocksfrom"../../testHelpers/renderHelpers"
45
import{WorkspaceSchedule,WorkspaceScheduleProps}from"./WorkspaceSchedule"
56

67
exportdefault{
@@ -10,8 +11,66 @@ export default {
1011

1112
constTemplate:Story<WorkspaceScheduleProps>=(args)=><WorkspaceSchedule{...args}/>
1213

13-
exportconstExample=Template.bind({})
14-
Example.args={
15-
autostart:MockWorkspaceAutostartEnabled.schedule,
16-
autostop:"",
14+
exportconstNoTTL=Template.bind({})
15+
NoTTL.args={
16+
workspace:{
17+
...Mocks.MockWorkspace,
18+
ttl:undefined,
19+
},
20+
}
21+
22+
exportconstShutdownSoon=Template.bind({})
23+
ShutdownSoon.args={
24+
workspace:{
25+
...Mocks.MockWorkspace,
26+
27+
latest_build:{
28+
...Mocks.MockWorkspaceBuild,
29+
transition:"start",
30+
updated_at:dayjs().subtract(1,"hour").toString(),// 1 hour ago
31+
},
32+
ttl:2*60*60*1000*1_000_000,// 2 hours
33+
},
34+
}
35+
36+
exportconstShutdownLong=Template.bind({})
37+
ShutdownLong.args={
38+
workspace:{
39+
...Mocks.MockWorkspace,
40+
41+
latest_build:{
42+
...Mocks.MockWorkspaceBuild,
43+
transition:"start",
44+
updated_at:dayjs().toString(),
45+
},
46+
ttl:7*24*60*60*1000*1_000_000,// 7 days
47+
},
48+
}
49+
50+
exportconstWorkspaceOffShort=Template.bind({})
51+
WorkspaceOffShort.args={
52+
workspace:{
53+
...Mocks.MockWorkspace,
54+
55+
latest_build:{
56+
...Mocks.MockWorkspaceBuild,
57+
transition:"stop",
58+
updated_at:dayjs().subtract(2,"days").toString(),
59+
},
60+
ttl:2*60*60*1000*1_000_000,// 2 hours
61+
},
62+
}
63+
64+
exportconstWorkspaceOffLong=Template.bind({})
65+
WorkspaceOffLong.args={
66+
workspace:{
67+
...Mocks.MockWorkspace,
68+
69+
latest_build:{
70+
...Mocks.MockWorkspaceBuild,
71+
transition:"stop",
72+
updated_at:dayjs().subtract(2,"days").toString(),
73+
},
74+
ttl:2*365*24*60*60*1000*1_000_000,// 2 years
75+
},
1776
}

‎site/src/components/WorkspaceSchedule/WorkspaceSchedule.tsx‎

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,77 @@
11
importBoxfrom"@material-ui/core/Box"
22
importTypographyfrom"@material-ui/core/Typography"
33
importcronstruefrom"cronstrue"
4+
importdayjsfrom"dayjs"
5+
importdurationfrom"dayjs/plugin/duration"
6+
importrelativeTimefrom"dayjs/plugin/relativeTime"
47
importReactfrom"react"
8+
import*asTypesGenfrom"../../api/typesGenerated"
59
import{extractTimezone,stripTimezone}from"../../util/schedule"
610
import{WorkspaceSection}from"../WorkspaceSection/WorkspaceSection"
711

12+
dayjs.extend(duration)
13+
dayjs.extend(relativeTime)
14+
815
constLanguage={
916
autoStartLabel:(schedule:string):string=>{
10-
constprefix="Workspace start"
11-
12-
if(schedule){
13-
return`${prefix} (${extractTimezone(schedule)})`
14-
}else{
15-
returnprefix
16-
}
17-
},
18-
autoStopLabel:(schedule:string):string=>{
19-
constprefix="Workspace shutdown"
17+
constprefix="Start"
2018

2119
if(schedule){
2220
return`${prefix} (${extractTimezone(schedule)})`
2321
}else{
2422
returnprefix
2523
}
2624
},
27-
cronHumanDisplay:(schedule:string):string=>{
25+
autoStartDisplay:(schedule:string):string=>{
2826
if(schedule){
2927
returncronstrue.toString(stripTimezone(schedule),{throwExceptionOnParseError:false})
3028
}
3129
return"Manual"
3230
},
31+
autoStopLabel:"Shutdown",
32+
autoStopDisplay:(workspace:TypesGen.Workspace):string=>{
33+
constlatest=workspace.latest_build
34+
35+
if(!workspace.ttl||workspace.ttl<1){
36+
return"Manual"
37+
}
38+
39+
if(latest.transition==="start"){
40+
constnow=dayjs()
41+
constupdatedAt=dayjs(latest.updated_at)
42+
constdeadline=updatedAt.add(workspace.ttl/1_000_000,"ms")
43+
if(now.isAfter(deadline)){
44+
return"WORKING ON THIS"
45+
}else{
46+
returnnow.to(deadline)
47+
}
48+
}
49+
50+
constduration=dayjs.duration(workspace.ttl/1_000_000,"milliseconds")
51+
return`${duration.humanize()} after start`
52+
},
3353
}
3454

3555
exportinterfaceWorkspaceScheduleProps{
36-
autostart:string
37-
autostop:string
56+
workspace:TypesGen.Workspace
3857
}
3958

4059
/**
4160
* WorkspaceSchedule displays a workspace schedule in a human-readable format
4261
*
4362
*@remarks Visual Component
4463
*/
45-
exportconstWorkspaceSchedule:React.FC<WorkspaceScheduleProps>=({autostart, autostop})=>{
64+
exportconstWorkspaceSchedule:React.FC<WorkspaceScheduleProps>=({workspace})=>{
4665
return(
4766
<WorkspaceSectiontitle="Workspace schedule">
4867
<Boxmt={2}>
49-
<Typographyvariant="h6">{Language.autoStartLabel(autostart)}</Typography>
50-
<Typography>{Language.cronHumanDisplay(autostart)}</Typography>
68+
<Typographyvariant="h6">{Language.autoStartLabel(workspace.autostart_schedule)}</Typography>
69+
<Typography>{Language.autoStartDisplay(workspace.autostart_schedule)}</Typography>
5170
</Box>
5271

5372
<Boxmt={2}>
54-
<Typographyvariant="h6">{Language.autoStopLabel(autostop)}</Typography>
55-
<Typography>{Language.cronHumanDisplay(autostop)}</Typography>
73+
<Typographyvariant="h6">{Language.autoStopLabel}</Typography>
74+
<Typographydata-chromatic="ignore">{Language.autoStopDisplay(workspace)}</Typography>
5675
</Box>
5776
</WorkspaceSection>
5877
)

‎site/src/testHelpers/entities.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@ export const MockWorkspaceAutostartEnabled: TypesGen.UpdateWorkspaceAutostartReq
100100
schedule:"CRON_TZ=Canada/Eastern 30 9 * * 1-5",
101101
}
102102

103-
exportconstMockWorkspaceAutostopDisabled:TypesGen.UpdateWorkspaceAutostartRequest={
104-
schedule:"",
105-
}
106-
107-
exportconstMockWorkspaceAutostopEnabled:TypesGen.UpdateWorkspaceAutostartRequest={
108-
// Runs at 9:30pm Monday through Friday using America/Toronto
109-
schedule:"CRON_TZ=America/Toronto 30 21 * * 1-5",
110-
}
111-
112103
exportconstMockWorkspaceBuild:TypesGen.WorkspaceBuild={
113104
build_number:1,
114105
created_at:"2022-05-17T17:39:01.382927298Z",
@@ -147,7 +138,7 @@ export const MockWorkspace: TypesGen.Workspace = {
147138
owner_id:MockUser.id,
148139
owner_name:MockUser.username,
149140
autostart_schedule:MockWorkspaceAutostartEnabled.schedule,
150-
autostop_schedule:MockWorkspaceAutostopEnabled.schedule,
141+
ttl:2*60*1000*1_000_000,// 2 hours as nanoseconds
151142
latest_build:MockWorkspaceBuild,
152143
}
153144

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp