Skip to content

Commit 453db7d

Browse files
committed
Add link to template field
1 parent b6dac4f commit 453db7d

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

site/src/components/ParameterInput/ParameterInput.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import FormControlLabel from "@material-ui/core/FormControlLabel"
2-
import Paper from "@material-ui/core/Paper"
32
import Radio from "@material-ui/core/Radio"
43
import RadioGroup from "@material-ui/core/RadioGroup"
5-
import { lighten, makeStyles } from "@material-ui/core/styles"
4+
import { makeStyles } from "@material-ui/core/styles"
65
import TextField from "@material-ui/core/TextField"
76
import { FC } from "react"
87
import { ParameterSchema } from "../../api/typesGenerated"
@@ -17,15 +16,15 @@ export interface ParameterInputProps {
1716
export const ParameterInput: FC<ParameterInputProps> = ({ disabled, onChange, schema }) => {
1817
const styles = useStyles()
1918
return (
20-
<Paper className={styles.paper}>
19+
<div className={styles.root}>
2120
<div className={styles.title}>
2221
<h2>var.{schema.name}</h2>
2322
{schema.description && <span>{schema.description}</span>}
2423
</div>
2524
<div className={styles.input}>
2625
<ParameterField disabled={disabled} onChange={onChange} schema={schema} />
2726
</div>
28-
</Paper>
27+
</div>
2928
)
3029
}
3130

@@ -67,28 +66,26 @@ const ParameterField: React.FC<ParameterInputProps> = ({ disabled, onChange, sch
6766
}
6867

6968
const useStyles = makeStyles((theme) => ({
70-
paper: {
69+
root: {
7170
display: "flex",
7271
flexDirection: "column",
7372
fontFamily: MONOSPACE_FONT_FAMILY,
73+
paddingTop: theme.spacing(2),
74+
paddingBottom: theme.spacing(2),
7475
},
7576
title: {
76-
background: lighten(theme.palette.background.default, 0.1),
77-
borderBottom: `1px solid ${theme.palette.divider}`,
78-
padding: theme.spacing(3),
7977
display: "flex",
8078
flexDirection: "column",
8179
"& h2": {
8280
margin: 0,
8381
},
8482
"& span": {
85-
paddingTop: theme.spacing(2),
83+
paddingTop: theme.spacing(1),
8684
},
8785
},
8886
input: {
89-
padding: theme.spacing(3),
87+
marginTop: theme.spacing(2),
9088
display: "flex",
9189
flexDirection: "column",
92-
maxWidth: 480,
9390
},
9491
}))

site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
167167

168168
return (
169169
<FullPageForm onCancel={onCancel} title="Workspace Schedule">
170-
<form className={styles.form} onSubmit={form.handleSubmit}>
171-
<Stack className={styles.stack}>
170+
<form onSubmit={form.handleSubmit}>
171+
<Stack>
172172
<TextField
173173
{...formHelpers("startTime", Language.startTimeHelperText)}
174174
disabled={form.isSubmitting || isLoading}
@@ -212,6 +212,9 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
212212
disabled={!form.values.startTime || form.isSubmitting || isLoading}
213213
onChange={form.handleChange}
214214
name={checkbox.name}
215+
color="primary"
216+
size="small"
217+
disableRipple
215218
/>
216219
}
217220
key={checkbox.name}
@@ -240,18 +243,6 @@ export const WorkspaceScheduleForm: FC<WorkspaceScheduleFormProps> = ({
240243
}
241244

242245
const useStyles = makeStyles({
243-
form: {
244-
display: "flex",
245-
justifyContent: "center",
246-
},
247-
stack: {
248-
// REMARK: 360 is 'arbitrary' in that it gives the helper text enough room
249-
// to render on one line. If we change the text, we might want to
250-
// adjust these. Without constraining the width, the date picker
251-
// and number inputs aren't visually appealing or maximally usable.
252-
maxWidth: 360,
253-
minWidth: 360,
254-
},
255246
daysOfWeekLabel: {
256247
fontSize: 12,
257248
},

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import Link from "@material-ui/core/Link"
12
import MenuItem from "@material-ui/core/MenuItem"
3+
import { makeStyles } from "@material-ui/core/styles"
24
import TextField, { TextFieldProps } from "@material-ui/core/TextField"
5+
import OpenInNewIcon from "@material-ui/icons/OpenInNew"
36
import { FormikContextType, useFormik } from "formik"
47
import { FC, useState } from "react"
8+
import { Link as RouterLink } from "react-router-dom"
59
import * as Yup from "yup"
610
import * as TypesGen from "../../api/typesGenerated"
711
import { FormFooter } from "../../components/FormFooter/FormFooter"
@@ -34,6 +38,7 @@ export const validationSchema = Yup.object({
3438

3539
export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = (props) => {
3640
const [parameterValues, setParameterValues] = useState<Record<string, string>>({})
41+
const styles = useStyles()
3742
const form: FormikContextType<TypesGen.CreateWorkspaceRequest> = useFormik<TypesGen.CreateWorkspaceRequest>({
3843
initialValues: {
3944
name: "",
@@ -66,6 +71,10 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = (props)
6671
},
6772
})
6873
const getFieldHelpers = getFormHelpers<TypesGen.CreateWorkspaceRequest>(form)
74+
const selectedTemplate =
75+
props.templates &&
76+
form.values.template_id &&
77+
props.templates.find((template) => template.id === form.values.template_id)
6978

7079
const handleTemplateChange: TextFieldProps["onChange"] = (event) => {
7180
if (!props.templates) {
@@ -99,6 +108,18 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = (props)
99108
label={Language.templateLabel}
100109
variant="outlined"
101110
select
111+
helperText={
112+
selectedTemplate && (
113+
<Link
114+
className={styles.readMoreLink}
115+
component={RouterLink}
116+
to={`/templates/${selectedTemplate.name}`}
117+
target="_blank"
118+
>
119+
Read more about this template <OpenInNewIcon />
120+
</Link>
121+
)
122+
}
102123
>
103124
{props.templates.map((template) => (
104125
<MenuItem key={template.id} value={template.id}>
@@ -146,3 +167,16 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = (props)
146167
</FullPageForm>
147168
)
148169
}
170+
171+
const useStyles = makeStyles((theme) => ({
172+
readMoreLink: {
173+
display: "flex",
174+
alignItems: "center",
175+
176+
"& svg": {
177+
width: 12,
178+
height: 12,
179+
marginLeft: theme.spacing(0.5),
180+
},
181+
},
182+
}))

0 commit comments

Comments
 (0)