mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: prompt when parameter options are incompatible (#9247)
This commit is contained in:
+29
-1
@@ -1225,7 +1225,6 @@ const getMissingParameters = (
|
||||
|
||||
if (isMutableAndRequired || isImmutable) {
|
||||
requiredParameters.push(p)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1248,6 +1247,35 @@ const getMissingParameters = (
|
||||
missingParameters.push(parameter)
|
||||
}
|
||||
|
||||
// Check if parameter "options" changed and we can't use old build parameters.
|
||||
templateParameters.forEach((templateParameter) => {
|
||||
if (templateParameter.options.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if there is a new value
|
||||
let buildParameter = newBuildParameters.find(
|
||||
(p) => p.name === templateParameter.name,
|
||||
)
|
||||
|
||||
// If not, get the old one
|
||||
if (!buildParameter) {
|
||||
buildParameter = oldBuildParameters.find(
|
||||
(p) => p.name === templateParameter.name,
|
||||
)
|
||||
}
|
||||
|
||||
if (!buildParameter) {
|
||||
return
|
||||
}
|
||||
|
||||
const matchingOption = templateParameter.options.find(
|
||||
(option) => option.value === buildParameter?.value,
|
||||
)
|
||||
if (!matchingOption) {
|
||||
missingParameters.push(templateParameter)
|
||||
}
|
||||
})
|
||||
return missingParameters
|
||||
}
|
||||
|
||||
|
||||
Generated
+2
-7
@@ -1663,13 +1663,8 @@ export type InsightsReportInterval = "day"
|
||||
export const InsightsReportIntervals: InsightsReportInterval[] = ["day"]
|
||||
|
||||
// From codersdk/provisionerdaemons.go
|
||||
export type JobErrorCode =
|
||||
| "MISSING_TEMPLATE_PARAMETER"
|
||||
| "REQUIRED_TEMPLATE_VARIABLES"
|
||||
export const JobErrorCodes: JobErrorCode[] = [
|
||||
"MISSING_TEMPLATE_PARAMETER",
|
||||
"REQUIRED_TEMPLATE_VARIABLES",
|
||||
]
|
||||
export type JobErrorCode = "REQUIRED_TEMPLATE_VARIABLES"
|
||||
export const JobErrorCodes: JobErrorCode[] = ["REQUIRED_TEMPLATE_VARIABLES"]
|
||||
|
||||
// From codersdk/provisionerdaemons.go
|
||||
export type LogLevel = "debug" | "error" | "info" | "trace" | "warn"
|
||||
|
||||
@@ -48,6 +48,7 @@ export const UpdateBuildParametersDialog: FC<
|
||||
onSubmit: (values) => {
|
||||
onUpdate(values.rich_parameter_values)
|
||||
},
|
||||
enableReinitialize: true,
|
||||
})
|
||||
const getFieldHelpers = getFormHelpers(form)
|
||||
const { t } = useTranslation("workspacePage")
|
||||
|
||||
@@ -517,11 +517,7 @@ export const createTemplateMachine =
|
||||
isNotUsingExample: ({ exampleId }) => !exampleId,
|
||||
hasFile: ({ file }) => Boolean(file),
|
||||
hasFailed: (_, { data }) =>
|
||||
Boolean(
|
||||
data.job.status === "failed" &&
|
||||
!isMissingParameter(data) &&
|
||||
!isMissingVariables(data),
|
||||
),
|
||||
Boolean(data.job.status === "failed" && !isMissingVariables(data)),
|
||||
hasNoParametersOrVariables: (_, { data }) =>
|
||||
data.variables === undefined,
|
||||
hasParametersOrVariables: (_, { data }) => {
|
||||
@@ -531,13 +527,6 @@ export const createTemplateMachine =
|
||||
},
|
||||
)
|
||||
|
||||
const isMissingParameter = (version: TemplateVersion) => {
|
||||
return Boolean(
|
||||
version.job.error_code &&
|
||||
version.job.error_code === "MISSING_TEMPLATE_PARAMETER",
|
||||
)
|
||||
}
|
||||
|
||||
const isMissingVariables = (version: TemplateVersion) => {
|
||||
return Boolean(
|
||||
version.job.error_code &&
|
||||
|
||||
Reference in New Issue
Block a user