… string variables <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ### Summary by CodeRabbit - Refactor: Updated `GoogleSheetsNodeContent` component to use the `options` prop instead of `action`, and integrated the `useTypebot` hook for better functionality. - Style: Improved UI text and layout in `GoogleSheetsSettings.tsx`, enhancing user experience when selecting rows. - Refactor: Simplified rendering logic in `BlockNodeContent.tsx` by directly calling `GoogleSheetsNodeContent` component, improving code readability. - Bug Fix: Enhanced `injectVariableValuesInPictureChoiceBlock` function to handle different types of values for titles, descriptions, and picture sources, fixing issues with variable value injection. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
import {
|
|
VariableWithValue,
|
|
ItemType,
|
|
PictureChoiceBlock,
|
|
Variable,
|
|
} from '@typebot.io/schemas'
|
|
import { isDefined } from '@typebot.io/lib'
|
|
import { filterPictureChoiceItems } from './filterPictureChoiceItems'
|
|
import { deepParseVariables } from '../../../variables/deepParseVariables'
|
|
|
|
export const injectVariableValuesInPictureChoiceBlock =
|
|
(variables: Variable[]) =>
|
|
(block: PictureChoiceBlock): PictureChoiceBlock => {
|
|
if (
|
|
block.options.dynamicItems?.isEnabled &&
|
|
block.options.dynamicItems.pictureSrcsVariableId
|
|
) {
|
|
const pictureSrcsVariable = variables.find(
|
|
(variable) =>
|
|
variable.id === block.options.dynamicItems?.pictureSrcsVariableId &&
|
|
isDefined(variable.value)
|
|
) as VariableWithValue | undefined
|
|
if (!pictureSrcsVariable) return block
|
|
const titlesVariable = block.options.dynamicItems.titlesVariableId
|
|
? (variables.find(
|
|
(variable) =>
|
|
variable.id === block.options.dynamicItems?.titlesVariableId &&
|
|
isDefined(variable.value)
|
|
) as VariableWithValue | undefined)
|
|
: undefined
|
|
const titlesVariableValues =
|
|
typeof titlesVariable?.value === 'string'
|
|
? [titlesVariable.value]
|
|
: titlesVariable?.value
|
|
const descriptionsVariable = block.options.dynamicItems
|
|
.descriptionsVariableId
|
|
? (variables.find(
|
|
(variable) =>
|
|
variable.id ===
|
|
block.options.dynamicItems?.descriptionsVariableId &&
|
|
isDefined(variable.value)
|
|
) as VariableWithValue | undefined)
|
|
: undefined
|
|
const descriptionsVariableValues =
|
|
typeof descriptionsVariable?.value === 'string'
|
|
? [descriptionsVariable.value]
|
|
: descriptionsVariable?.value
|
|
|
|
const variableValues =
|
|
typeof pictureSrcsVariable.value === 'string'
|
|
? [pictureSrcsVariable.value]
|
|
: pictureSrcsVariable.value
|
|
|
|
return {
|
|
...block,
|
|
items: variableValues.filter(isDefined).map((pictureSrc, idx) => ({
|
|
id: idx.toString(),
|
|
type: ItemType.PICTURE_CHOICE,
|
|
blockId: block.id,
|
|
pictureSrc,
|
|
title: titlesVariableValues?.[idx] ?? '',
|
|
description: descriptionsVariableValues?.[idx] ?? '',
|
|
})),
|
|
}
|
|
}
|
|
return deepParseVariables(variables)(
|
|
filterPictureChoiceItems(variables)(block)
|
|
)
|
|
}
|