8000 refactor: show icons for multi-select parameter options by aslilac · Pull Request #18594 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

refactor: show icons for multi-select parameter options #18594

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 6 commits into from
Jun 27, 2025
Merged
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
oh boy
  • Loading branch information
aslilac committed Jun 26, 2025
commit 605f40d252643033986239ae33edb3b079cecaee
203 changes: 102 additions & 101 deletions site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -735,119 +735,120 @@ export const useValidationSchemaForDynamicParameters = (
.of(
Yup.object().shape({
name: Yup.string().required(),
value: Yup.string().test("verify with template", (val, ctx) => {
const name = ctx.parent.name;
const parameter = parameters.find(
(parameter) => parameter.name === name,
);
if (parameter) {
switch (parameter.type) {
case "number": {
const minValidation = parameter.validations.find(
(v) => v.validation_min !== null,
);
const maxValidation = parameter.validations.find(
(v) => v.validation_max !== null,
);

if (
minValidation &&
minValidation.validation_min !== null &&
!maxValidation &&
Number(val) < minValidation.validation_min
) {
return ctx.createError({
path: ctx.path,
message:
parameterError(parameter, val) ??
`Value must be greater than ${minValidation.validation_min}.`,
});
}
value: Yup.string()
.test("verify with template", (val, ctx) => {
const name = ctx.parent.name;
const parameter = parameters.find(
(parameter) => parameter.name === name,
);
if (parameter) {
switch (parameter.type) {
case "number": {
const minValidation = parameter.validations.find(
(v) => v.validation_min !== null,
);
const maxValidation = parameter.validations.find(
(v) => v.validation_max !== null,
);

if (
!minValidation &&
maxValidation &&
maxValidation.validation_max !== null &&
Number(val) > maxValidation.validation_max
) {
return ctx.createError({
path: ctx.path,
message:
parameterError(parameter, val) ??
`Value must be less than ${maxValidation.validation_max}.`,
});
}
if (
minValidation &&
minValidation.validation_min !== null &&
!maxValidation &&
Number(val) < minValidation.validation_min
) {
return ctx.createError({
path: ctx.path,
message:
parameterError(parameter, val) ??
`Value must be greater than ${minValidation.validation_min}.`,
});
}

if (
minValidation &&
minValidation.validation_min !== null &&
maxValidation &&
maxValidation.validation_max !== null &&
(Number(val) < minValidation.validation_min ||
Number(val) > maxValidation.validation_max)
) {
return ctx.createError({
path: ctx.path,
message:
parameterError(parameter, val) ??
`Value must be between ${minValidation.validation_min} and ${maxValidation.validation_max}.`,
});
}
if (
!minValidation &&
maxValidation &&
maxValidation.validation_max !== null &&
Number(val) > maxValidation.validation_max
) {
return ctx.createError({
path: ctx.path,
message:
parameterError(parameter, val) ??
`Value must be less than ${maxValidation.validation_max}.`,
});
10000 }

const monotonic = parameter.validations.find(
(v) =>
v.validation_monotonic !== null &&
v.validation_monotonic !== "",
);
if (
minValidation &&
minValidation.validation_min !== null &&
maxValidation &&
maxValidation.validation_max !== null &&
(Number(val) < minValidation.validation_min ||
Number(val) > maxValidation.validation_max)
) {
return ctx.createError({
path: ctx.path,
message:
parameterError(parameter, val) ??
`Value must be between ${minValidation.validation_min} and ${maxValidation.validation_max}.`,
});
}

if (monotonic && lastBuildParameters) {
const lastBuildParameter = lastBuildParameters.find(
(last: { name: string }) => last.name === name,
const monotonic = parameter.validations.find(
(v) =>
v.validation_monotonic !== null &&
v.validation_monotonic !== "",
);
if (lastBuildParameter) {
switch (monotonic.validation_monotonic) {
case "increasing":
if (Number(lastBuildParameter.value) > Number(val)) {
return ctx.createError({
path: ctx.path,
message: `Value must only ever increase (last value was ${lastBuildParameter.value})`,
});
}
break;
case "decreasing":
if (Number(lastBuildParameter.value) < Number(val)) {
return ctx.createError({
path: ctx.path,
message: `Value must only ever decrease (last value was ${lastBuildParameter.value})`,
});
}
break;

if (monotonic && lastBuildParameters) {
const lastBuildParameter = lastBuildParameters.find(
(last: { name: string }) => last.name === name,
);
if (lastBuildParameter) {
switch (monotonic.validation_monotonic) {
case "increasing":
if (Number(lastBuildParameter.value) > Number(val)) {
return ctx.createError({
path: ctx.path,
message: `Value must only ever increase (last value was ${lastBuildParameter.value})`,
});
}
break;
case "decreasing":
if (Number(lastBuildParameter.value) < Number(val)) {
return ctx.createError({
path: ctx.path,
message: `Value must only ever decrease (last value was ${lastBuildParameter.value})`,
});
}
break;
}
}
}
break;
}
break;
}
case "string": {
const regex = parameter.validations.find(
(v) =>
v.validation_regex !== null && v.validation_regex !== "",
);
if (!regex || !regex.validation_regex) {
return true;
}
case "string": {
const regex = parameter.validations.find(
(v) =>
v.validation_regex !== null && v.validation_regex !== "",
);
if (!regex || !regex.validation_regex) {
return true;
}

if (val && !new RegExp(regex.validation_regex).test(val)) {
return ctx.createError({
path: ctx.path,
message: parameterError(parameter, val),
});
if (val && !new RegExp(regex.validation_regex).test(val)) {
return ctx.createError({
path: ctx.path,
message: parameterError(parameter, val),
});
}
break;
}
break;
}
}
}
return true;
}),
return true;
}),
}),
)
.required();
Expand Down
Loading
0