2
0

Remove empty strings from variable parsing when possible

This commit is contained in:
Baptiste Arnaud
2024-04-18 10:17:25 +02:00
parent fb847e17dd
commit 3ca1a2f0d6
7 changed files with 34 additions and 17 deletions

View File

@ -8,9 +8,11 @@ export const parseDateInput =
const variables = state.typebotsQueue[0].typebot.variables
if (!block.options) return deepParseVariables(variables)(block)
return {
...deepParseVariables(variables)(block),
...block,
options: {
...deepParseVariables(variables)(block.options),
...deepParseVariables(variables, { removeEmptyStrings: true })(
block.options
),
min: parseDateLimit(
block.options.min,
block.options.hasTime,

View File

@ -21,7 +21,7 @@ export const getRow = async (
const logs: ChatLog[] = []
const { variables } = state.typebotsQueue[0].typebot
const { sheetId, cellsToExtract, filter, ...parsedOptions } =
deepParseVariables(variables)(options)
deepParseVariables(variables, { removeEmptyStrings: true })(options)
if (!sheetId) return { outgoingEdgeId }
const doc = await getAuthenticatedGoogleDoc({

View File

@ -17,8 +17,9 @@ export const updateRow = async (
}: { outgoingEdgeId?: string; options: GoogleSheetsUpdateRowOptions }
): Promise<ExecuteIntegrationResponse> => {
const { variables } = state.typebotsQueue[0].typebot
const { sheetId, filter, ...parsedOptions } =
deepParseVariables(variables)(options)
const { sheetId, filter, ...parsedOptions } = deepParseVariables(variables, {
removeEmptyStrings: true,
})(options)
const referenceCell =
'referenceCell' in parsedOptions && parsedOptions.referenceCell

View File

@ -226,7 +226,8 @@ export const parseInput =
}
case InputBlockType.NUMBER: {
const parsedBlock = deepParseVariables(
state.typebotsQueue[0].typebot.variables
state.typebotsQueue[0].typebot.variables,
{ removeEmptyStrings: true }
)({
...block,
prefilledValue: getPrefilledInputValue(
@ -254,7 +255,8 @@ export const parseInput =
}
case InputBlockType.RATING: {
const parsedBlock = deepParseVariables(
state.typebotsQueue[0].typebot.variables
state.typebotsQueue[0].typebot.variables,
{ removeEmptyStrings: true }
)({
...block,
prefilledValue: getPrefilledInputValue(
@ -272,7 +274,9 @@ export const parseInput =
}
}
default: {
return deepParseVariables(state.typebotsQueue[0].typebot.variables)({
return deepParseVariables(state.typebotsQueue[0].typebot.variables, {
removeEmptyStrings: true,
})({
...block,
runtimeOptions: await computeRuntimeOptions(state)(block),
prefilledValue: getPrefilledInputValue(

View File

@ -118,7 +118,8 @@ export const executeForgedBlock = async (
: undefined
const parsedOptions = deepParseVariables(
state.typebotsQueue[0].typebot.variables
state.typebotsQueue[0].typebot.variables,
{ removeEmptyStrings: true }
)(block.options)
await action?.run?.server?.({
credentials: credentialsData ?? {},

View File

@ -55,7 +55,9 @@ export const parseBubbleBlock = (
}
case BubbleBlockType.EMBED: {
const message = deepParseVariables(variables)(block)
const message = deepParseVariables(variables, {
removeEmptyStrings: true,
})(block)
return {
...message,
content: {
@ -69,7 +71,9 @@ export const parseBubbleBlock = (
}
case BubbleBlockType.VIDEO: {
const parsedContent = block.content
? deepParseVariables(variables)(block.content)
? deepParseVariables(variables, { removeEmptyStrings: true })(
block.content
)
: undefined
return {
@ -85,7 +89,7 @@ export const parseBubbleBlock = (
}
}
default:
return deepParseVariables(variables)(block)
return deepParseVariables(variables, { removeEmptyStrings: true })(block)
}
}

View File

@ -154,7 +154,8 @@ export const startSession = async ({
typebot: {
id: typebot.id,
settings: deepParseVariables(
initialState.typebotsQueue[0].typebot.variables
initialState.typebotsQueue[0].typebot.variables,
{ removeEmptyStrings: true }
)(typebot.settings),
theme: sanitizeAndParseTheme(typebot.theme, {
variables: initialState.typebotsQueue[0].typebot.variables,
@ -257,7 +258,8 @@ export const startSession = async ({
typebot: {
id: typebot.id,
settings: deepParseVariables(
newSessionState.typebotsQueue[0].typebot.variables
newSessionState.typebotsQueue[0].typebot.variables,
{ removeEmptyStrings: true }
)(typebot.settings),
theme: sanitizeAndParseTheme(typebot.theme, {
variables: initialState.typebotsQueue[0].typebot.variables,
@ -274,7 +276,8 @@ export const startSession = async ({
typebot: {
id: typebot.id,
settings: deepParseVariables(
newSessionState.typebotsQueue[0].typebot.variables
newSessionState.typebotsQueue[0].typebot.variables,
{ removeEmptyStrings: true }
)(typebot.settings),
theme: sanitizeAndParseTheme(typebot.theme, {
variables: initialState.typebotsQueue[0].typebot.variables,
@ -451,9 +454,11 @@ const sanitizeAndParseTheme = (
{ variables }: { variables: Variable[] }
): Theme => ({
general: theme.general
? deepParseVariables(variables)(theme.general)
? deepParseVariables(variables, { removeEmptyStrings: true })(theme.general)
: undefined,
chat: theme.chat
? deepParseVariables(variables, { removeEmptyStrings: true })(theme.chat)
: undefined,
chat: theme.chat ? deepParseVariables(variables)(theme.chat) : undefined,
customCss: theme.customCss
? removeLiteBadgeCss(parseVariables(variables)(theme.customCss))
: undefined,