Skip to content

Commit

Permalink
Yaml decoding fix (#5531)
Browse files Browse the repository at this point in the history
### Description of the change

While working on #5436, I noticed some errors during the YAML parsing;
well not errors, but unexpected (for me) values being returned by the
`genIn` method. In collections, the returned thing is not a js object,
but a custom data type from the YAML library.

This PR is just to convert collections (YAML sequences and YAML maps)
back to plain js objects (even if the function says `toJSON()` 😅

### Benefits

We will be able to use arrays and object fields in the form.

### Possible drawbacks

N/A

### Applicable issues

- fixes #5519

### Additional information

> **Note**
> This PR is part of a series of PRs aimed at closing [this
milestone](https://github.com/vmware-tanzu/kubeapps/milestone/27). I
have split the changes to ease the review process, but as there are many
interrelated changes, the tests will be performed in a separate PR (on
top of the branch containing all the changes).
>  PR 2 out of 6

Signed-off-by: Antonio Gamez Diaz <[email protected]>
  • Loading branch information
antgamdia authored Oct 21, 2022
1 parent 00b62e0 commit bb64580
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dashboard/src/shared/yamlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ export function getPathValueInYamlNode(
path: string,
) {
const splittedPath = parsePath(path);
const value = values?.getIn(splittedPath);
let value = values?.getIn(splittedPath);

// if the value from getIn is an object, it means
// it is a YamlSeq or YamlMap, so we need to convert it
// back to a plain JS object
if (typeof value === "object") {
value = (value as any)?.toJSON();
}

return value;
}

Expand Down

0 comments on commit bb64580

Please sign in to comment.