Skip to content

fix(site): show error when parameter is invalid #8125

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 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions codersdk/richparameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func ValidateWorkspaceBuildParameter(richParameter TemplateVersionParameter, bui
switch richParameter.ValidationMonotonic {
case MonotonicOrderIncreasing:
if lastBuildParameter.Value > buildParameter.Value {
return xerrors.Errorf("parameter value must be equal or greater than previous value: %s", lastBuildParameter.Value)
return xerrors.Errorf("Parameter value must be equal or greater than previous value: %s", lastBuildParameter.Value)
}
case MonotonicOrderDecreasing:
if lastBuildParameter.Value < buildParameter.Value {
return xerrors.Errorf("parameter value must be equal or lower than previous value: %s", lastBuildParameter.Value)
return xerrors.Errorf("Parameter value must be equal or lower than previous value: %s", lastBuildParameter.Value)
}
}
}
Expand All @@ -69,7 +69,7 @@ func ValidateWorkspaceBuildParameter(richParameter TemplateVersionParameter, bui
}

if !matched {
return xerrors.Errorf("parameter value must match one of options: %s", parameterValuesAsArray(richParameter.Options))
return xerrors.Errorf("Parameter value must match one of options: %s", parameterValuesAsArray(richParameter.Options))
}
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion site/src/components/Alert/ErrorAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ export const ErrorAlert: FC<
const message = getErrorMessage(error, "Something went wrong.")
const detail = getErrorDetail(error)

// For some reason, the message and detail can be the same on the BE, but does
// not make sense in the FE to showing them duplicated
const shouldDisplayDetail = message !== detail

return (
<Alert severity="error" {...alertProps}>
{detail ? (
<>
<AlertTitle>{message}</AlertTitle>
<AlertDetail>{detail}</AlertDetail>
{shouldDisplayDetail && <AlertDetail>{detail}</AlertDetail>}
</>
) : (
message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { makeStyles } from "@mui/styles"
import { PageHeader, PageHeaderTitle } from "components/PageHeader/PageHeader"
import { displaySuccess } from "components/GlobalSnackbar/utils"
import { FC } from "react"
import { isApiValidationError } from "api/errors"
import { ErrorAlert } from "components/Alert/ErrorAlert"

const getWorkspaceParameters = async (workspace: Workspace) => {
const latestBuild = workspace.latest_build
Expand Down Expand Up @@ -90,6 +92,10 @@ export const WorkspaceParametersPageView: FC<
<PageHeaderTitle>Workspace parameters</PageHeaderTitle>
</PageHeader>

{submitError && !isApiValidationError(submitError) && (
<ErrorAlert error={submitError} sx={{ mb: 6 }} />
)}

{data ? (
<WorkspaceParametersForm
buildParameters={data.buildParameters}
Expand Down