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

Commitecf716f

Browse files
greyscaledkylecarbs
authored andcommitted
feat: ws schedule timezone select (#2032)
Resolves:#1959Summary:The package tzdata is used to create a meaningful select-list fortimezone in the workspace schedule form.Impact:Improved UX. Furthermore, we guess your timezone if the form is beinginitialized from scratch.
1 parent7f204b6 commitecf716f

File tree

6 files changed

+37
-15
lines changed

6 files changed

+37
-15
lines changed

‎site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"react-router-dom":"6.3.0",
4949
"sourcemapped-stacktrace":"1.1.11",
5050
"swr":"1.2.2",
51+
"tzdata":"1.0.30",
5152
"uuid":"8.3.2",
5253
"xstate":"4.32.1",
5354
"xterm":"4.18.0",

‎site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import{Language,validationSchema,WorkspaceScheduleFormValues}from"./WorkspaceScheduleForm"
2+
import{zones}from"./zones"
23

34
constvalid:WorkspaceScheduleFormValues={
45
sunday:false,
@@ -127,6 +128,15 @@ describe("validationSchema", () => {
127128
expect(validate).toThrowError(Language.errorTimezone)
128129
})
129130

131+
it.each<[string]>(zones.map((zone)=>[zone]))(`validation passes for tz=%p`,(zone)=>{
132+
constvalues:WorkspaceScheduleFormValues={
133+
...valid,
134+
timezone:zone,
135+
}
136+
constvalidate=()=>validationSchema.validateSync(values)
137+
expect(validate).not.toThrow()
138+
})
139+
130140
it("allows a ttl of 7 days",()=>{
131141
constvalues:WorkspaceScheduleFormValues={
132142
...valid,

‎site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import FormControlLabel from "@material-ui/core/FormControlLabel"
44
importFormGroupfrom"@material-ui/core/FormGroup"
55
importFormHelperTextfrom"@material-ui/core/FormHelperText"
66
importFormLabelfrom"@material-ui/core/FormLabel"
7-
importLinkfrom"@material-ui/core/Link"
7+
importMenuItemfrom"@material-ui/core/MenuItem"
88
importmakeStylesfrom"@material-ui/core/styles/makeStyles"
99
importTextFieldfrom"@material-ui/core/TextField"
1010
importdayjsfrom"dayjs"
@@ -18,6 +18,7 @@ import { getFormHelpers } from "../../util/formUtils"
1818
import{FormFooter}from"../FormFooter/FormFooter"
1919
import{FullPageForm}from"../FullPageForm/FullPageForm"
2020
import{Stack}from"../Stack/Stack"
21+
import{zones}from"./zones"
2122

2223
// REMARK: timezone plugin depends on UTC
2324
//
@@ -203,21 +204,20 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
203204
/>
204205

205206
<TextField
206-
{...formHelpers(
207-
"timezone",
208-
<>
209-
Timezone must be a valid name from the{" "}
210-
<Linkhref="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List"target="_blank">
211-
timezone database
212-
</Link>
213-
</>,
214-
)}
207+
{...formHelpers("timezone")}
215208
disabled={isLoading}
216209
InputLabelProps={{
217210
shrink:true,
218211
}}
219212
label={Language.timezoneLabel}
220-
/>
213+
select
214+
>
215+
{zones.map((zone)=>(
216+
<MenuItemkey={zone}value={zone}>
217+
{zone}
218+
</MenuItem>
219+
))}
220+
</TextField>
221221

222222
<FormControlcomponent="fieldset"error={Boolean(form.errors.monday)}>
223223
<FormLabelclassName={styles.daysOfWeekLabel}component="legend">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
importtzDatafrom"tzdata"
2+
3+
exportconstzones:string[]=Object.keys(tzData.zones)

‎site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ export const formValuesToTTLRequest = (values: WorkspaceScheduleFormValues): Typ
9292
}
9393
}
9494

95-
exportconstworkspaceToInitialValues=(workspace:TypesGen.Workspace):WorkspaceScheduleFormValues=>{
95+
exportconstworkspaceToInitialValues=(
96+
workspace:TypesGen.Workspace,
97+
defaultTimeZone="",
98+
):WorkspaceScheduleFormValues=>{
9699
constschedule=workspace.autostart_schedule
97100
constttlHours=workspace.ttl_ms ?Math.round(workspace.ttl_ms/(1000*60*60)) :0
98101

@@ -106,12 +109,12 @@ export const workspaceToInitialValues = (workspace: TypesGen.Workspace): Workspa
106109
friday:false,
107110
saturday:false,
108111
startTime:"",
109-
timezone:"",
112+
timezone:defaultTimeZone,
110113
ttl:ttlHours,
111114
}
112115
}
113116

114-
consttimezone=extractTimezone(schedule,dayjs.tz.guess())
117+
consttimezone=extractTimezone(schedule,defaultTimeZone)
115118

116119
constexpression=cronParser.parseExpression(stripTimezone(schedule))
117120

@@ -162,7 +165,7 @@ export const WorkspaceSchedulePage: React.FC = () => {
162165
return(
163166
<WorkspaceScheduleForm
164167
fieldErrors={formErrors}
165-
initialValues={workspaceToInitialValues(workspace)}
168+
initialValues={workspaceToInitialValues(workspace,dayjs.tz.guess())}
166169
isLoading={scheduleState.tags.has("loading")}
167170
onCancel={()=>{
168171
navigate(`/workspaces/${workspaceId}`)

‎site/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13270,6 +13270,11 @@ typescript@4.6.4:
1327013270
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9"
1327113271
integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==
1327213272

13273+
tzdata@1.0.30:
13274+
version "1.0.30"
13275+
resolved "https://registry.yarnpkg.com/tzdata/-/tzdata-1.0.30.tgz#d9d5a4b4b5e1ed95f6255f98c0564c4256316f52"
13276+
integrity sha512-/0yogZsIRUVhGIEGZahL+Nnl9gpMD6jtQ9MlVtPVofFwhaqa+cFTgRy1desTAKqdmIJjS6CL+i6F/mnetrLaxw==
13277+
1327313278
uglify-js@^3.1.4:
1327413279
version "3.15.1"
1327513280
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.15.1.tgz#9403dc6fa5695a6172a91bc983ea39f0f7c9086d"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp