Skip to content

Commit

Permalink
Fix wrong parsing of unitless sliders
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Oct 20, 2024
1 parent 3a14ee3 commit e94c90d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,35 @@ describe(symToStr({ computeHelmValues }), () => {
expect(got).toStrictEqual(expected);
});

it("Use default - real world case", () => {
const xOnyxiaContext = { s3: undefined };

const got = computeHelmValues({
"helmValuesSchema": {
"type": "object",
"properties": {
"gpu": {
"type": "string",
"default": "1",
"render": "slider",
"sliderMin": 1,
"sliderMax": 3,
"sliderUnit": ""
}
}
},
"helmValuesYaml": YAML.stringify({}),
xOnyxiaContext
});

const expected = {
"helmValues": { "gpu": "1" },
"isChartUsingS3": false
};

expect(got).toStrictEqual(expected);
});

it("Use values.yaml", () => {
const xOnyxiaContext = {
"a": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ function computeRootFormFieldGroup_rec(params: {
return value;
}
case "string": {
const xStr = value.slice(0, -(sliderUnit ?? "").length);
const xStr =
sliderUnit === undefined || sliderUnit === ""
? value
: value.slice(0, -sliderUnit.length);

const x = parseFloat(xStr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ export function mergeTemporaryRangeSliders(params: {

assert(helmValue.endsWith(unit));

helmValue_withoutUnit = helmValue.slice(0, -unit.length);
helmValue_withoutUnit =
unit === ""
? helmValue
: helmValue.slice(0, -unit.length);
}

const value = parseFloat(helmValue_withoutUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export function validateValueAgainstJSONSchema_noEnumCheck(params: {
return false;
}

const x = parseFloat(value.slice(0, -helmValuesSchema.sliderUnit.length));
const x = parseFloat(
helmValuesSchema.sliderUnit === ""
? value
: value.slice(0, -helmValuesSchema.sliderUnit.length)
);

if (isNaN(x)) {
return false;
Expand Down

0 comments on commit e94c90d

Please sign in to comment.