Skip to content

feat(site): add build parameters option when starting or restarting a workspace #8524

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

Merged
merged 15 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't show ephemeral parameters on create form
  • Loading branch information
BrunoQuaresma committed Jul 18, 2023
commit 98fd6f8606f28feaf8e6a64e1a93f60852cecd22
2 changes: 2 additions & 0 deletions site/src/components/WorkspaceActions/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const StartButton: FC<
> = ({ handleAction, workspace, loading }) => {
return (
<ButtonGroup
key="start"
variant="outlined"
sx={{
// Workaround to make the border transitions smmothly on button groups
Expand Down Expand Up @@ -90,6 +91,7 @@ export const RestartButton: FC<
> = ({ handleAction, loading, workspace }) => {
return (
<ButtonGroup
key="restart"
variant="outlined"
sx={{
// Workaround to make the border transitions smmothly on button groups
Expand Down
18 changes: 9 additions & 9 deletions site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
MutableTemplateParametersSection,
} from "components/TemplateParameters/TemplateParameters"
import { ErrorAlert } from "components/Alert/ErrorAlert"
import { paramUsedToCreateWorkspace } from "utils/workspace"

export enum CreateWorkspaceErrors {
GET_TEMPLATES_ERROR = "getTemplatesError",
Expand Down Expand Up @@ -59,8 +60,11 @@ export interface CreateWorkspacePageViewProps {
export const CreateWorkspacePageView: FC<
React.PropsWithChildren<CreateWorkspacePageViewProps>
> = (props) => {
const templateParameters = props.templateParameters?.filter(
paramUsedToCreateWorkspace,
)
const initialRichParameterValues = selectInitialRichParametersValues(
props.templateParameters,
templateParameters,
props.defaultParameterValues,
)
const [gitAuthErrors, setGitAuthErrors] = useState<Record<string, string>>({})
Expand All @@ -72,20 +76,16 @@ export const CreateWorkspacePageView: FC<
// to disappear.
setGitAuthErrors({})
}, [props.templateGitAuth])

const workspaceErrors =
props.createWorkspaceErrors[CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR]

// Scroll to top of page if errors are present
useEffect(() => {
if (props.hasTemplateErrors || Boolean(workspaceErrors)) {
window.scrollTo(0, 0)
}
}, [props.hasTemplateErrors, workspaceErrors])

const { t } = useTranslation("createWorkspacePage")
const styles = useStyles()

const form: FormikContextType<TypesGen.CreateWorkspaceRequest> =
useFormik<TypesGen.CreateWorkspaceRequest>({
initialValues: {
Expand All @@ -97,7 +97,7 @@ export const CreateWorkspacePageView: FC<
name: nameValidator(t("nameLabel", { ns: "createWorkspacePage" })),
rich_parameter_values: useValidationSchemaForRichParameters(
"createWorkspacePage",
props.templateParameters,
templateParameters,
),
}),
enableReinitialize: true,
Expand Down Expand Up @@ -240,10 +240,10 @@ export const CreateWorkspacePageView: FC<
</FormSection>
)}

{props.templateParameters && (
{templateParameters && (
<>
<MutableTemplateParametersSection
templateParameters={props.templateParameters}
templateParameters={templateParameters}
getInputProps={(parameter, index) => {
return {
...getFieldHelpers(
Expand All @@ -264,7 +264,7 @@ export const CreateWorkspacePageView: FC<
}}
/>
<ImmutableTemplateParametersSection
templateParameters={props.templateParameters}
templateParameters={templateParameters}
classes={{ root: styles.warningSection }}
getInputProps={(parameter, index) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
selectInitialRichParametersValues,
workspaceBuildParameterValue,
} from "utils/richParameters"
import { paramUsedToCreateWorkspace } from "utils/workspace"

type ButtonValues = Record<string, string>

Expand All @@ -38,7 +39,9 @@ const TemplateEmbedPage = () => {
</Helmet>
<TemplateEmbedPageView
template={template}
templateParameters={templateParameters}
templateParameters={templateParameters?.filter(
paramUsedToCreateWorkspace,
)}
/>
</>
)
Expand Down
4 changes: 4 additions & 0 deletions site/src/utils/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,7 @@ const LoadingIcon = () => {
export const hasJobError = (workspace: TypesGen.Workspace) => {
return workspace.latest_build.job.error !== undefined
}

export const paramUsedToCreateWorkspace = (
param: TypesGen.TemplateVersionParameter,
) => !param.ephemeral