2
0

🚸 Better random IDs generation in setVariable

This commit is contained in:
Baptiste Arnaud
2023-09-26 10:04:28 +02:00
parent 801fea860a
commit a176e23cc8

View File

@@ -5,6 +5,7 @@ import { parseScriptToExecuteClientSideAction } from '../script/executeScript'
import { parseGuessedValueType } from '../../../variables/parseGuessedValueType' import { parseGuessedValueType } from '../../../variables/parseGuessedValueType'
import { parseVariables } from '../../../variables/parseVariables' import { parseVariables } from '../../../variables/parseVariables'
import { updateVariablesInSession } from '../../../variables/updateVariablesInSession' import { updateVariablesInSession } from '../../../variables/updateVariablesInSession'
import { createId } from '@paralleldrive/cuid2'
export const executeSetVariable = ( export const executeSetVariable = (
state: SessionState, state: SessionState,
@@ -92,13 +93,10 @@ const getExpressionToEvaluate =
return 'new Date(Date.now() - 86400000).toISOString()' return 'new Date(Date.now() - 86400000).toISOString()'
} }
case 'Random ID': { case 'Random ID': {
return 'Math.random().toString(36).substring(2, 15)' return `"${createId()}"`
} }
case 'User ID': { case 'User ID': {
return ( return state.typebotsQueue[0].resultId ?? `"${createId()}"`
state.typebotsQueue[0].resultId ??
'Math.random().toString(36).substring(2, 15)'
)
} }
case 'Map item with same index': { case 'Map item with same index': {
return `const itemIndex = ${options.mapListItemParams?.baseListVariableId}.indexOf(${options.mapListItemParams?.baseItemVariableId}) return `const itemIndex = ${options.mapListItemParams?.baseListVariableId}.indexOf(${options.mapListItemParams?.baseItemVariableId})