Skip to content

fix: prompt when parameter options are incompatible #9247

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 13 commits into from
Aug 23, 2023
Prev Previous commit
Next Next commit
site: ask for changed parameter option
  • Loading branch information
mtojek committed Aug 22, 2023
commit e5421c4942d7160687022524e92d130a84d4c829
26 changes: 25 additions & 1 deletion site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,6 @@ const getMissingParameters = (

if (isMutableAndRequired || isImmutable) {
requiredParameters.push(p)
return
}
})

Expand All @@ -1243,6 +1242,31 @@ const getMissingParameters = (
missingParameters.push(parameter)
}

// Check if parameter "options" changed and we can't use old build parameters.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrunoQuaresma I may need your frontend wisdom. I battling the following edge case here:

  1. We have a foobar string parameter with options: aaa, bbb (default), ccc, and the workspace built on it. The workspace uses bbb option.
  2. Change the parameter option bbb to something else, let's say ddd.
  3. Click "Update".

I can see the UpdateParametersDialog, but when I click the Update button, it gets back to it. If I pick something else, and then click back to the default, it works fine.

I looked deeper, and it seems that Formik doesn't set the internal form.values, even though initialValues are passed. I'm not sure how I can proceed here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, I got it fixes with enableReinitialize. Thanks for the suggestion!

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
}

Expand Down
3 changes: 3 additions & 0 deletions site/src/pages/WorkspacePage/UpdateBuildParametersDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export const UpdateBuildParametersDialog: FC<
onUpdate(values.rich_parameter_values)
},
})
form.values = {
rich_parameter_values: initialRichParameterValues,
}
const getFieldHelpers = getFormHelpers(form)
const { t } = useTranslation("workspacePage")

Expand Down