-
Notifications
You must be signed in to change notification settings - Fork 894
refactor(site): improve parameters field #11802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
e97824a
49fab93
ae1890d
0a5e6b7
6c2b035
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { css } from "@emotion/css"; | ||
import { useTheme, type Interpolation, type Theme } from "@emotion/react"; | ||
import { type Interpolation, type Theme } from "@emotion/react"; | ||
import TextField from "@mui/material/TextField"; | ||
import type * as TypesGen from "api/typesGenerated"; | ||
import { UserAutocomplete } from "components/UserAutocomplete/UserAutocomplete"; | ||
|
@@ -21,10 +20,6 @@ import { | |
getInitialRichParameterValues, | ||
useValidationSchemaForRichParameters, | ||
} from "utils/richParameters"; | ||
import { | ||
ImmutableTemplateParametersSection, | ||
MutableTemplateParametersSection, | ||
} from "components/TemplateParameters/TemplateParameters"; | ||
import { ErrorAlert } from "components/Alert/ErrorAlert"; | ||
import { Stack } from "components/Stack/Stack"; | ||
import { | ||
|
@@ -44,6 +39,7 @@ import { | |
PageHeaderSubtitle, | ||
} from "components/PageHeader/PageHeader"; | ||
import { Pill } from "components/Pill/Pill"; | ||
import { RichParameterInput } from "components/RichParameterInput/RichParameterInput"; | ||
|
||
export const Language = { | ||
duplicationWarning: | ||
|
@@ -90,7 +86,6 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({ | |
onSubmit, | ||
onCancel, | ||
}) => { | ||
const theme = useTheme(); | ||
const [owner, setOwner] = useState(defaultOwner); | ||
const [searchParams] = useSearchParams(); | ||
const disabledParamsList = searchParams?.get("disable_params")?.split(","); | ||
|
@@ -223,64 +218,40 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({ | |
</FormSection> | ||
|
||
{parameters && ( | ||
<> | ||
<MutableTemplateParametersSection | ||
templateParameters={parameters} | ||
getInputProps={(parameter, index) => { | ||
return { | ||
...getFieldHelpers( | ||
"rich_parameter_values[" + index + "].value", | ||
), | ||
onChange: async (value) => { | ||
await form.setFieldValue( | ||
"rich_parameter_values." + index, | ||
{ | ||
name: parameter.name, | ||
value: value, | ||
}, | ||
); | ||
}, | ||
disabled: | ||
disabledParamsList?.includes( | ||
parameter.name.toLowerCase().replace(/ /g, "_"), | ||
) || creatingWorkspace, | ||
}; | ||
}} | ||
/> | ||
<ImmutableTemplateParametersSection | ||
templateParameters={parameters} | ||
classes={{ | ||
root: css` | ||
border: 1px solid ${theme.palette.warning.light}; | ||
border-radius: 8px; | ||
background-color: ${theme.palette.background.paper}; | ||
padding: 80px; | ||
margin-left: -80px; | ||
margin-right: -80px; | ||
`, | ||
}} | ||
getInputProps={(parameter, index) => { | ||
return { | ||
...getFieldHelpers( | ||
"rich_parameter_values[" + index + "].value", | ||
), | ||
onChange: async (value) => { | ||
await form.setFieldValue( | ||
"rich_parameter_values." + index, | ||
{ | ||
<FormSection | ||
title="Parameters" | ||
description="These are the settings used by your template. Please note that immutable parameters cannot be modified once the workspace is created." | ||
> | ||
{/* | ||
Opted not to use FormFields in order to increase spacing. | ||
This decision was made because rich parameter inputs are more visually dense than standard text fields. | ||
*/} | ||
<div css={{ display: "flex", flexDirection: "column", gap: 36 }}> | ||
{parameters.map((parameter, index) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: I might lift this function outside of the JSX. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which function? The map? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the callback that the map takes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is quite normal in react codebases but any specific concern? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like it lowers general readability because its a longer callback that defines multiple variables, but no strong concerns! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see! But in this case, we would have to pass 3+ arguments to the function so I'm not sure if extracting it to a new function or component would improve that much but I can understand the reasoning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, good point |
||
const parameterField = `rich_parameter_values.${index}`; | ||
const parameterInputName = `${parameterField}.value`; | ||
const isDisabled = | ||
disabledParamsList?.includes( | ||
parameter.name.toLowerCase().replace(/ /g, "_"), | ||
) || creatingWorkspace; | ||
|
||
return ( | ||
<RichParameterInput | ||
{...getFieldHelpers(parameterInputName)} | ||
onChange={async (value) => { | ||
await form.setFieldValue(parameterField, { | ||
name: parameter.name, | ||
value: value, | ||
}, | ||
); | ||
}, | ||
disabled: | ||
disabledParamsList?.includes( | ||
parameter.name.toLowerCase().replace(/ /g, "_"), | ||
) || creatingWorkspace, | ||
}; | ||
}} | ||
/> | ||
</> | ||
value, | ||
}); | ||
}} | ||
key={parameter.name} | ||
parameter={parameter} | ||
disabled={isDisabled} | ||
/> | ||
); | ||
})} | ||
</div> | ||
</FormSection> | ||
)} | ||
|
||
<FormFooter | ||
|
Uh oh!
There was an error while loading. Please reload this page.