Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1f3ed28

Browse files
committed
STOP IT
1 parent 8a6b2f5 commit 1f3ed28

File tree

3 files changed

+105
-104
lines changed

3 files changed

+105
-104
lines changed

site/src/modules/workspaces/DynamicParameter/DynamicParameter.tsx

Lines changed: 103 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ import {
4646
TriangleAlert,
4747
} from "lucide-react";
4848
import { type FC, useEffect, useId, useRef, useState } from "react";
49-
import { maskText } from "utils/text";
5049
import type { AutofillBuildParameter } from "utils/richParameters";
50+
import { maskText } from "utils/text";
5151
import * as Yup from "yup";
5252

5353
interface DynamicParameterProps {
@@ -782,119 +782,120 @@ export const useValidationSchemaForDynamicParameters = (
782782
.of(
783783
Yup.object().shape({
784784
name: Yup.string().required(),
785-
value: Yup.string().test("verify with template", (val, ctx) => {
786-
const name = ctx.parent.name;
787-
const parameter = parameters.find(
788-
(parameter) => parameter.name === name,
789-
);
790-
if (parameter) {
791-
switch (parameter.type) {
792-
case "number": {
793-
const minValidation = parameter.validations.find(
794-
(v) => v.validation_min !== null,
795-
);
796-
const maxValidation = parameter.validations.find(
797-
(v) => v.validation_max !== null,
798-
);
799-
800-
if (
801-
minValidation &&
802-
minValidation.validation_min !== null &&
803-
!maxValidation &&
804-
Number(val) < minValidation.validation_min
805-
) {
806-
return ctx.createError({
807-
path: ctx.path,
808-
message:
809-
parameterError(parameter, val) ??
810-
`Value must be greater than ${minValidation.validation_min}.`,
811-
});
812-
}
785+
value: Yup.string()
786+
.test("verify with template", (val, ctx) => {
787+
const name = ctx.parent.name;
788+
const parameter = parameters.find(
789+
(parameter) => parameter.name === name,
790+
);
791+
if (parameter) {
792+
switch (parameter.type) {
793+
case "number": {
794+
const minValidation = parameter.validations.find(
795+
(v) => v.validation_min !== null,
796+
);
797+
const maxValidation = parameter.validations.find(
798+
(v) => v.validation_max !== null,
799+
);
813800

814-
if (
815-
!minValidation &&
816-
maxValidation &&
817-
maxValidation.validation_max !== null &&
818-
Number(val) > maxValidation.validation_max
819-
) {
820-
return ctx.createError({
821-
path: ctx.path,
822-
message:
823-
parameterError(parameter, val) ??
824-
`Value must be less than ${maxValidation.validation_max}.`,
825-
});
826-
}
801+
if (
802+
minValidation &&
803+
minValidation.validation_min !== null &&
804+
!maxValidation &&
805+
Number(val) < minValidation.validation_min
806+
) {
807+
return ctx.createError({
808+
path: ctx.path,
809+
message:
810+
parameterError(parameter, val) ??
811+
`Value must be greater than ${minValidation.validation_min}.`,
812+
});
813+
}
827814

828-
if (
829-
minValidation &&
830-
minValidation.validation_min !== null &&
831-
maxValidation &&
832-
maxValidation.validation_max !== null &&
833-
(Number(val) < minValidation.validation_min ||
834-
Number(val) > maxValidation.validation_max)
835-
) {
836-
return ctx.createError({
837-
path: ctx.path,
838-
message:
839-
parameterError(parameter, val) ??
840-
`Value must be between ${minValidation.validation_min} and ${maxValidation.validation_max}.`,
841-
});
842-
}
815+
if (
816+
!minValidation &&
817+
maxValidation &&
818+
maxValidation.validation_max !== null &&
819+
Number(val) > maxValidation.validation_max
820+
) {
821+
return ctx.createError({
822+
path: ctx.path,
823+
message:
824+
parameterError(parameter, val) ??
825+
`Value must be less than ${maxValidation.validation_max}.`,
826+
});
827+
}
843828

844-
const monotonic = parameter.validations.find(
845-
(v) =>
846-
v.validation_monotonic !== null &&
847-
v.validation_monotonic !== "",
848-
);
829+
if (
830+
minValidation &&
831+
minValidation.validation_min !== null &&
832+
maxValidation &&
833+
maxValidation.validation_max !== null &&
834+
(Number(val) < minValidation.validation_min ||
835+
Number(val) > maxValidation.validation_max)
836+
) {
837+
return ctx.createError({
838+
path: ctx.path,
839+
message:
840+
parameterError(parameter, val) ??
841+
`Value must be between ${minValidation.validation_min} and ${maxValidation.validation_max}.`,
842+
});
843+
}
849844

850-
if (monotonic && lastBuildParameters) {
851-
const lastBuildParameter = lastBuildParameters.find(
852-
(last: { name: string }) => last.name === name,
845+
const monotonic = parameter.validations.find(
846+
(v) =>
847+
v.validation_monotonic !== null &&
848+
v.validation_monotonic !== "",
853849
);
854-
if (lastBuildParameter) {
855-
switch (monotonic.validation_monotonic) {
856-
case "increasing":
857-
if (Number(lastBuildParameter.value) > Number(val)) {
858-
return ctx.createError({
859-
path: ctx.path,
860-
message: `Value must only ever increase (last value was ${lastBuildParameter.value})`,
861-
});
862-
}
863-
break;
864-
case "decreasing":
865-
if (Number(lastBuildParameter.value) < Number(val)) {
866-
return ctx.createError({
867-
path: ctx.path,
868-
message: `Value must only ever decrease (last value was ${lastBuildParameter.value})`,
869-
});
870-
}
871-
break;
850+
851+
if (monotonic && lastBuildParameters) {
852+
const lastBuildParameter = lastBuildParameters.find(
853+
(last: { name: string }) => last.name === name,
854+
);
855+
if (lastBuildParameter) {
856+
switch (monotonic.validation_monotonic) {
857+
case "increasing":
858+
if (Number(lastBuildParameter.value) > Number(val)) {
859+
return ctx.createError({
860+
path: ctx.path,
861+
message: `Value must only ever increase (last value was ${lastBuildParameter.value})`,
862+
});
863+
}
864+
break;
865+
case "decreasing":
866+
if (Number(lastBuildParameter.value) < Number(val)) {
867+
return ctx.createError({
868+
path: ctx.path,
869+
message: `Value must only ever decrease (last value was ${lastBuildParameter.value})`,
870+
});
871+
}
872+
break;
873+
}
872874
}
873875
}
876+
break;
874877
}
875-
break;
876-
}
877-
case "string": {
878-
const regex = parameter.validations.find(
879-
(v) =>
880-
v.validation_regex !== null && v.validation_regex !== "",
881-
);
882-
if (!regex || !regex.validation_regex) {
883-
return true;
884-
}
878+
case "string": {
879+
const regex = parameter.validations.find(
880+
(v) =>
881+
v.validation_regex !== null && v.validation_regex !== "",
882+
);
883+
if (!regex || !regex.validation_regex) {
884+
return true;
885+
}
885886

886-
if (val && !new RegExp(regex.validation_regex).test(val)) {
887-
return ctx.createError({
888-
path: ctx.path,
889-
message: parameterError(parameter, val),
890-
});
887+
if (val && !new RegExp(regex.validation_regex).test(val)) {
888+
return ctx.createError({
889+
path: ctx.path,
890+
message: parameterError(parameter, val),
891+
});
892+
}
893+
break;
891894
}
892-
break;
893895
}
894896
}
895-
}
896-
return true;
897-
}),
897+
return true;
898+
}),
898899
}),
899900
)
900901
.required();

site/src/pages/TaskPage/TaskPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { Helmet } from "react-helmet-async";
1414
import { useQuery } from "react-query";
1515
import { useParams } from "react-router-dom";
1616
import { Link as RouterLink } from "react-router-dom";
17-
import { ellipsizeText } from "utils/text";
1817
import { pageTitle } from "utils/page";
18+
import { ellipsizeText } from "utils/text";
1919
import {
2020
ActiveTransition,
2121
WorkspaceBuildProgress,

site/src/utils/text.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ellipsizeText, maskText } from "./text";
21
import type { Nullable } from "./nullable";
2+
import { ellipsizeText, maskText } from "./text";
33

44
describe("ellipsizeText", () => {
55
it.each([

0 commit comments

Comments
 (0)