Skip to content

Commit

Permalink
M #-: Fix apiResponse data handling (#3268)
Browse files Browse the repository at this point in the history
- If the API response returns only 1 object, it won't be array wrapped,
  causing issues when formatting the response to a dataset. Now
  transformApiResponseToDataset always casts the response to an array.

Signed-off-by: Victor Hansson <vhansson@opennebula.io>
  • Loading branch information
vichansson authored Oct 18, 2024
1 parent 48f508e commit 51ef95d
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ export const transformApiResponseToDataset = (
depth = 0,
dataArrayPath
) => {
const dataArray =
const dataArray = _.castArray(
(_.isEmpty(apiResponse)
? []
: dataArrayPath
? _.get(apiResponse, dataArrayPath)
: findFirstArray(apiResponse, depth)) ?? []
)

const flattenObject = (obj, prefix = '') =>
Object.keys(obj).reduce((acc, k) => {
Expand Down

0 comments on commit 51ef95d

Please sign in to comment.