2
0

chore(editor): ♻️ Revert tables to arrays

Yet another refacto. I improved many many mechanisms on this one including dnd. It is now end 2 end tested 🎉
This commit is contained in:
Baptiste Arnaud
2022-02-04 19:00:08 +01:00
parent 8a350eee6c
commit 524ef0812c
123 changed files with 2998 additions and 3112 deletions

View File

@ -1,4 +1,4 @@
import { Table, Variable } from 'models'
import { Variable } from 'models'
import { isDefined } from 'utils'
const safeEval = eval
@ -11,16 +11,16 @@ export const parseVariables = ({
variables,
}: {
text?: string
variables: Table<Variable>
variables: Variable[]
}): string => {
if (!text || text === '') return ''
return text.replace(/\{\{(.*?)\}\}/g, (_, fullVariableString) => {
const matchedVarName = fullVariableString.replace(/{{|}}/g, '')
const matchedVariableId = variables.allIds.find((variableId) => {
const variable = variables.byId[variableId]
return matchedVarName === variable.name && isDefined(variable.value)
})
return variables.byId[matchedVariableId ?? '']?.value ?? ''
return (
variables.find((v) => {
return matchedVarName === v.name && isDefined(v.value)
})?.value ?? ''
)
})
}
@ -50,7 +50,7 @@ const countDecimals = (value: number) => {
export const parseVariablesInObject = (
object: { [key: string]: string | number },
variables: Table<Variable>
variables: Variable[]
) =>
Object.keys(object).reduce((newObj, key) => {
const currentValue = object[key]