-
Notifications
You must be signed in to change notification settings - Fork 929
feat: Group immutable and mutable rich parameters #5975
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 all commits
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,4 +1,5 @@ | ||
import { useMachine } from "@xstate/react" | ||
import { TemplateVersionParameter } from "api/typesGenerated" | ||
import { useMe } from "hooks/useMe" | ||
import { useOrganizationId } from "hooks/useOrganizationId" | ||
import { FC } from "react" | ||
|
@@ -58,7 +59,7 @@ const CreateWorkspacePage: FC = () => { | |
templateName={templateName} | ||
templates={templates} | ||
selectedTemplate={selectedTemplate} | ||
templateParameters={templateParameters} | ||
templateParameters={orderedTemplateParameters(templateParameters)} | ||
templateSchema={templateSchema} | ||
createWorkspaceErrors={{ | ||
[CreateWorkspaceErrors.GET_TEMPLATES_ERROR]: getTemplatesError, | ||
|
@@ -104,4 +105,18 @@ const getDefaultParameterValues = ( | |
return paramValues | ||
} | ||
|
||
export const orderedTemplateParameters = ( | ||
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. Is it used in more than one place? If not, I think we can remove the 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. It is used in 2 places as it's also in |
||
templateParameters?: TemplateVersionParameter[], | ||
): TemplateVersionParameter[] => { | ||
if (!templateParameters) { | ||
return [] | ||
} | ||
|
||
const immutables = templateParameters.filter( | ||
(parameter) => !parameter.mutable, | ||
) | ||
const mutables = templateParameters.filter((parameter) => parameter.mutable) | ||
return [...immutables, ...mutables] | ||
} | ||
|
||
export default CreateWorkspacePage |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ export interface WorkspaceBuildParametersPageViewProps { | |
templateParameters?: TypesGen.TemplateVersionParameter[] | ||
workspaceBuildParameters?: TypesGen.WorkspaceBuildParameter[] | ||
|
||
isLoading: boolean | ||
initialTouched?: FormikTouched<TypesGen.CreateWorkspaceRequest> | ||
updatingWorkspace: boolean | ||
onCancel: () => void | ||
|
@@ -150,7 +151,9 @@ export const WorkspaceBuildParametersPageView: FC< | |
|
||
<Maybe | ||
condition={Boolean( | ||
props.templateParameters && props.templateParameters.length === 0, | ||
!props.isLoading && | ||
props.templateParameters && | ||
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. Usage could be nicer here if we defaulted to an empty array for the prop. 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. Before introducing 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. Usually, it is not a good idea to use an empty array in the FE because we usually use undefined to identify the "loading data" state. However, if this data is provided internally and not from an external source that depends on an effect like network calls, file reading, etc. Providing an empty array is ok 👍 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. Also, we could introduce |
||
props.templateParameters.length === 0, | ||
)} | ||
> | ||
<div className={styles.formSection}> | ||
|
@@ -161,7 +164,8 @@ export const WorkspaceBuildParametersPageView: FC< | |
</div> | ||
</Maybe> | ||
|
||
{props.templateParameters && | ||
{!props.isLoading && | ||
props.templateParameters && | ||
props.templateParameters.length > 0 && | ||
props.workspaceBuildParameters && ( | ||
<div className={styles.formSection}> | ||
|
@@ -171,27 +175,67 @@ export const WorkspaceBuildParametersPageView: FC< | |
spacing={4} // Spacing here is diff because the fields here don't have the MUI floating label spacing | ||
className={styles.formSectionFields} | ||
> | ||
{props.templateParameters.map((parameter, index) => ( | ||
<RichParameterInput | ||
{...getFieldHelpers( | ||
"rich_parameter_values[" + index + "].value", | ||
)} | ||
disabled={!parameter.mutable || form.isSubmitting} | ||
index={index} | ||
key={parameter.name} | ||
onChange={(value) => { | ||
form.setFieldValue("rich_parameter_values." + index, { | ||
name: parameter.name, | ||
value: value, | ||
}) | ||
}} | ||
parameter={parameter} | ||
initialValue={workspaceBuildParameterValue( | ||
initialRichParameterValues, | ||
parameter, | ||
)} | ||
/> | ||
))} | ||
{props.templateParameters.filter((p) => !p.mutable).length > | ||
0 && ( | ||
<div className={styles.formSectionParameterTitle}> | ||
Immutable parameters | ||
</div> | ||
)} | ||
{props.templateParameters.map( | ||
(parameter, index) => | ||
!parameter.mutable && ( | ||
<RichParameterInput | ||
{...getFieldHelpers( | ||
"rich_parameter_values[" + index + "].value", | ||
)} | ||
disabled={!parameter.mutable || form.isSubmitting} | ||
index={index} | ||
key={parameter.name} | ||
onChange={(value) => { | ||
form.setFieldValue("rich_parameter_values." + index, { | ||
name: parameter.name, | ||
value: value, | ||
}) | ||
}} | ||
parameter={parameter} | ||
initialValue={workspaceBuildParameterValue( | ||
initialRichParameterValues, | ||
parameter, | ||
)} | ||
/> | ||
), | ||
)} | ||
|
||
{props.templateParameters.filter((p) => p.mutable).length > | ||
0 && ( | ||
<div className={styles.formSectionParameterTitle}> | ||
Mutable parameters | ||
</div> | ||
)} | ||
{props.templateParameters.map( | ||
(parameter, index) => | ||
parameter.mutable && ( | ||
<RichParameterInput | ||
{...getFieldHelpers( | ||
"rich_parameter_values[" + index + "].value", | ||
)} | ||
disabled={!parameter.mutable || form.isSubmitting} | ||
index={index} | ||
key={parameter.name} | ||
onChange={(value) => { | ||
form.setFieldValue("rich_parameter_values." + index, { | ||
name: parameter.name, | ||
value: value, | ||
}) | ||
}} | ||
parameter={parameter} | ||
initialValue={workspaceBuildParameterValue( | ||
initialRichParameterValues, | ||
parameter, | ||
)} | ||
/> | ||
), | ||
)} | ||
<FormFooter | ||
styles={formFooterStyles} | ||
onCancel={props.onCancel} | ||
|
@@ -279,7 +323,7 @@ const stripImmutableParameters = ( | |
} | ||
} | ||
|
||
const useStyles = makeStyles(() => ({ | ||
const useStyles = makeStyles((theme) => ({ | ||
goBackSection: { | ||
display: "flex", | ||
width: "100%", | ||
|
@@ -292,6 +336,13 @@ const useStyles = makeStyles(() => ({ | |
formSectionFields: { | ||
width: "100%", | ||
}, | ||
formSectionParameterTitle: { | ||
fontSize: 20, | ||
color: theme.palette.text.primary, | ||
fontWeight: 400, | ||
margin: 0, | ||
marginBottom: theme.spacing(1), | ||
}, | ||
})) | ||
|
||
const useFormFooterStyles = makeStyles((theme) => ({ | ||
|
Uh oh!
There was an error while loading. Please reload this page.