Skip to content

Commit

Permalink
Merge pull request #368 from TheTechCompany/staging
Browse files Browse the repository at this point in the history
Add nested value parser
  • Loading branch information
balbatross authored Aug 10, 2023
2 parents da86e79 + dfeb022 commit 3b7060f
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ export const useValues = (deviceId: string, program: {tags: any[], types: any[]}
type &&
typeof (type) === "string" &&
type.indexOf('[]') > -1
) {

){
if( typeof (value) === "object" &&
!Array.isArray(value) &&
Object.keys(value).map((x: any) => x % 1 == 0).indexOf(false) < 0
Expand All @@ -118,7 +117,27 @@ export const useValues = (deviceId: string, program: {tags: any[], types: any[]}
}else if(typeof(value) === 'string'){
value = value.split(',')
}

}else if(hasFields){

type?.fields?.forEach((field) => {

if (
field.type &&
typeof (field.type) === "string" &&
field.type.indexOf('[]') > -1
){
if( typeof (value[field.name]) === "object" &&
!Array.isArray(value[field.name]) &&
Object.keys(value[field.name]).map((x: any) => x % 1 == 0).indexOf(false) < 0
) {
value[field.name] = Object.keys(value[field.name]).map((x) => value[field.name][x]);
}else if(typeof(value[field.name]) === 'string'){
value[field.name] = value[field.name].split(',')
}
}

})

}

return {
Expand Down

0 comments on commit 3b7060f

Please sign in to comment.