Skip to content

Commit

Permalink
Invert logic to simplify flow
Browse files Browse the repository at this point in the history
  • Loading branch information
acolver committed Oct 3, 2023
1 parent 133d7d0 commit 80c7f96
Showing 1 changed file with 33 additions and 35 deletions.
68 changes: 33 additions & 35 deletions radlab-ui/webapp/src/utils/terraform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ const mapHclToUIVar = (
default: hclVar.default
? hclVar.default
: formatType(hclVar.type) === "bool"
? false
: hclVar.default === ""
? ""
: null,
? false
: hclVar.default === ""
? ""
: null,
required: mandatory,
group,
order,
Expand Down Expand Up @@ -269,42 +269,40 @@ export const checkDependsOnValid = (
dependsOnVarData: string | null,
userAnswerData: FormikValues,
) => {
if (dependsOnVarData) {
const dependsOnDataOperatorFormats = dependsOnVarData
.replaceAll("&&", " && ")
.replaceAll("||", " || ")

const dependsOnDataAnswerMatchRes = dependsOnDataOperatorFormats
.split(" ")
.map((dependsOnDataOperatorFormat) => {
const checkDependsNameVar = dependsOnDataOperatorFormat.split("==")
let getwithAnswerMatch
if (checkDependsNameVar.length === 2) {
//@ts-ignore
getwithAnswerMatch = `${userAnswerData[checkDependsNameVar[0]]} == ${
checkDependsNameVar[1]
if (!dependsOnVarData) {
return false
}

const dependsOnDataOperatorFormats = dependsOnVarData
.replaceAll("&&", " && ")
.replaceAll("||", " || ")

const dependsOnDataAnswerMatchRes = dependsOnDataOperatorFormats
.split(" ")
.map((dependsOnDataOperatorFormat) => {
const checkDependsNameVar = dependsOnDataOperatorFormat.split("==")
let getwithAnswerMatch
if (checkDependsNameVar.length === 2) {
getwithAnswerMatch = `${userAnswerData[checkDependsNameVar[0]!]} == ${checkDependsNameVar[1]!
}`
} else {
getwithAnswerMatch = checkDependsNameVar[0]
}
} else {
getwithAnswerMatch = checkDependsNameVar[0]
}

return getwithAnswerMatch
})
.join(" ")
return getwithAnswerMatch
})
.join(" ")

const formatDependsOnDataAnswerMatchRes = `(${dependsOnDataAnswerMatchRes.replaceAll(
" && ",
") && (",
)})`
const formatDependsOnDataAnswerMatchRes = `(${dependsOnDataAnswerMatchRes.replaceAll(
" && ",
") && (",
)})`

const dependsOnDataAnswerMatchEvalute = eval(
formatDependsOnDataAnswerMatchRes,
)
const dependsOnDataAnswerMatchEvalute = eval(
formatDependsOnDataAnswerMatchRes,
)

return dependsOnDataAnswerMatchEvalute
} else {
return false
}
return dependsOnDataAnswerMatchEvalute
}

export const formatRelevantVariables = (
Expand Down

0 comments on commit 80c7f96

Please sign in to comment.