🚸 (setVariable) Rename Today setVar type to Now
This commit is contained in:
@@ -57,7 +57,7 @@ export const Select = <T extends Item>({
|
|||||||
typeof item === 'string'
|
typeof item === 'string'
|
||||||
? selectedItem === item
|
? selectedItem === item
|
||||||
: selectedItem === item.value
|
: selectedItem === item.value
|
||||||
)
|
) ?? selectedItem
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Text } from '@chakra-ui/react'
|
import { Tag, Text } from '@chakra-ui/react'
|
||||||
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
|
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
|
||||||
import { SetVariableBlock, Variable } from '@typebot.io/schemas'
|
import { SetVariableBlock, Variable } from '@typebot.io/schemas'
|
||||||
import { byId, isEmpty } from '@typebot.io/lib'
|
import { byId, isEmpty } from '@typebot.io/lib'
|
||||||
@@ -9,21 +9,34 @@ export const SetVariableContent = ({ block }: { block: SetVariableBlock }) => {
|
|||||||
typebot?.variables.find(byId(block.options.variableId))?.name ?? ''
|
typebot?.variables.find(byId(block.options.variableId))?.name ?? ''
|
||||||
return (
|
return (
|
||||||
<Text color={'gray.500'} noOfLines={4}>
|
<Text color={'gray.500'} noOfLines={4}>
|
||||||
{variableName === '' && isEmpty(block.options.expressionToEvaluate)
|
{variableName === '' && isEmpty(block.options.expressionToEvaluate) ? (
|
||||||
? 'Click to edit...'
|
'Click to edit...'
|
||||||
: getExpression(typebot?.variables ?? [])(block.options)}
|
) : (
|
||||||
|
<Expression
|
||||||
|
options={block.options}
|
||||||
|
variables={typebot?.variables ?? []}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getExpression =
|
const Expression = ({
|
||||||
(variables: Variable[]) =>
|
options,
|
||||||
(options: SetVariableBlock['options']): string | null => {
|
variables,
|
||||||
|
}: {
|
||||||
|
options: SetVariableBlock['options']
|
||||||
|
variables: Variable[]
|
||||||
|
}): JSX.Element | null => {
|
||||||
const variableName = variables.find(byId(options.variableId))?.name ?? ''
|
const variableName = variables.find(byId(options.variableId))?.name ?? ''
|
||||||
switch (options.type) {
|
switch (options.type) {
|
||||||
case 'Custom':
|
case 'Custom':
|
||||||
case undefined:
|
case undefined:
|
||||||
return `${variableName} = ${options.expressionToEvaluate}`
|
return (
|
||||||
|
<Text>
|
||||||
|
{variableName} = {options.expressionToEvaluate}
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
case 'Map item with same index': {
|
case 'Map item with same index': {
|
||||||
const baseItemVariable = variables.find(
|
const baseItemVariable = variables.find(
|
||||||
byId(options.mapListItemParams?.baseItemVariableId)
|
byId(options.mapListItemParams?.baseItemVariableId)
|
||||||
@@ -34,17 +47,27 @@ const getExpression =
|
|||||||
const targetListVariable = variables.find(
|
const targetListVariable = variables.find(
|
||||||
byId(options.mapListItemParams?.targetListVariableId)
|
byId(options.mapListItemParams?.targetListVariableId)
|
||||||
)
|
)
|
||||||
return `${variableName} = item in ${targetListVariable?.name} with same index as ${baseItemVariable?.name} in ${baseListVariable?.name}`
|
return (
|
||||||
|
<Text>
|
||||||
|
{variableName} = item in ${targetListVariable?.name} with same index
|
||||||
|
as ${baseItemVariable?.name} in ${baseListVariable?.name}
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
case 'Empty':
|
case 'Empty':
|
||||||
return `Reset ${variableName}`
|
return <Text>Reset {variableName}</Text>
|
||||||
case 'Random ID':
|
case 'Random ID':
|
||||||
case 'Today':
|
case 'Today':
|
||||||
|
case 'Now':
|
||||||
case 'Tomorrow':
|
case 'Tomorrow':
|
||||||
case 'User ID':
|
case 'User ID':
|
||||||
case 'Moment of the day':
|
case 'Moment of the day':
|
||||||
case 'Yesterday': {
|
case 'Yesterday': {
|
||||||
return `${variableName} = ${options.type}`
|
return (
|
||||||
|
<Text>
|
||||||
|
{variableName} = <Tag colorScheme="purple">System.{options.type}</Tag>
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import { Alert, AlertIcon, FormLabel, Stack, Tag, Text } from '@chakra-ui/react'
|
import { Alert, AlertIcon, FormLabel, Stack, Tag, Text } from '@chakra-ui/react'
|
||||||
import { CodeEditor } from '@/components/inputs/CodeEditor'
|
import { CodeEditor } from '@/components/inputs/CodeEditor'
|
||||||
import { SetVariableOptions, Variable, valueTypes } from '@typebot.io/schemas'
|
import {
|
||||||
|
SetVariableOptions,
|
||||||
|
Variable,
|
||||||
|
hiddenTypes,
|
||||||
|
valueTypes,
|
||||||
|
} from '@typebot.io/schemas'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { VariableSearchInput } from '@/components/inputs/VariableSearchInput'
|
import { VariableSearchInput } from '@/components/inputs/VariableSearchInput'
|
||||||
import { SwitchWithLabel } from '@/components/inputs/SwitchWithLabel'
|
import { SwitchWithLabel } from '@/components/inputs/SwitchWithLabel'
|
||||||
@@ -11,6 +16,8 @@ type Props = {
|
|||||||
onOptionsChange: (options: SetVariableOptions) => void
|
onOptionsChange: (options: SetVariableOptions) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setVarTypes = valueTypes.filter((type) => !hiddenTypes.includes(type))
|
||||||
|
|
||||||
export const SetVariableSettings = ({ options, onOptionsChange }: Props) => {
|
export const SetVariableSettings = ({ options, onOptionsChange }: Props) => {
|
||||||
const updateVariableId = (variable?: Variable) =>
|
const updateVariableId = (variable?: Variable) =>
|
||||||
onOptionsChange({ ...options, variableId: variable?.id })
|
onOptionsChange({ ...options, variableId: variable?.id })
|
||||||
@@ -40,7 +47,7 @@ export const SetVariableSettings = ({ options, onOptionsChange }: Props) => {
|
|||||||
</Text>
|
</Text>
|
||||||
<Select
|
<Select
|
||||||
selectedItem={options.type ?? 'Custom'}
|
selectedItem={options.type ?? 'Custom'}
|
||||||
items={valueTypes}
|
items={setVarTypes}
|
||||||
onSelect={updateValueType}
|
onSelect={updateValueType}
|
||||||
/>
|
/>
|
||||||
<SetVariableValue options={options} onOptionsChange={onOptionsChange} />
|
<SetVariableValue options={options} onOptionsChange={onOptionsChange} />
|
||||||
@@ -144,6 +151,7 @@ const SetVariableValue = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
case 'Random ID':
|
case 'Random ID':
|
||||||
|
case 'Now':
|
||||||
case 'Today':
|
case 'Today':
|
||||||
case 'Tomorrow':
|
case 'Tomorrow':
|
||||||
case 'User ID':
|
case 'User ID':
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ const getExpressionToEvaluate =
|
|||||||
(resultId: string | undefined) =>
|
(resultId: string | undefined) =>
|
||||||
(options: SetVariableBlock['options']): string | null => {
|
(options: SetVariableBlock['options']): string | null => {
|
||||||
switch (options.type) {
|
switch (options.type) {
|
||||||
|
case 'Now':
|
||||||
case 'Today':
|
case 'Today':
|
||||||
return 'new Date().toISOString()'
|
return 'new Date().toISOString()'
|
||||||
case 'Tomorrow': {
|
case 'Tomorrow': {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export const valueTypes = [
|
|||||||
'Custom',
|
'Custom',
|
||||||
'Empty',
|
'Empty',
|
||||||
'User ID',
|
'User ID',
|
||||||
|
'Now',
|
||||||
'Today',
|
'Today',
|
||||||
'Yesterday',
|
'Yesterday',
|
||||||
'Tomorrow',
|
'Tomorrow',
|
||||||
@@ -14,6 +15,8 @@ export const valueTypes = [
|
|||||||
'Map item with same index',
|
'Map item with same index',
|
||||||
] as const
|
] as const
|
||||||
|
|
||||||
|
export const hiddenTypes = ['Today']
|
||||||
|
|
||||||
export const setVariableOptionsSchema = z.object({
|
export const setVariableOptionsSchema = z.object({
|
||||||
variableId: z.string().optional(),
|
variableId: z.string().optional(),
|
||||||
expressionToEvaluate: z.string().optional(),
|
expressionToEvaluate: z.string().optional(),
|
||||||
|
|||||||
Reference in New Issue
Block a user