🐛 (sheets) Fix empty and unique filter
This commit is contained in:
@ -41,13 +41,14 @@ export const RowsFilterComparisonItem = ({
|
||||
items={Object.values(ComparisonOperators)}
|
||||
placeholder="Select an operator"
|
||||
/>
|
||||
{item.comparisonOperator !== ComparisonOperators.IS_SET && (
|
||||
<TextInput
|
||||
defaultValue={item.value ?? ''}
|
||||
onChange={handleChangeValue}
|
||||
placeholder="Type a value..."
|
||||
/>
|
||||
)}
|
||||
{item.comparisonOperator !== ComparisonOperators.IS_SET &&
|
||||
item.comparisonOperator !== ComparisonOperators.IS_EMPTY && (
|
||||
<TextInput
|
||||
defaultValue={item.value ?? ''}
|
||||
onChange={handleChangeValue}
|
||||
placeholder="Type a value..."
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
)
|
||||
}
|
||||
|
@ -6,20 +6,23 @@ import {
|
||||
} from '@typebot.io/schemas'
|
||||
import { isDefined } from '@typebot.io/lib'
|
||||
import { deepParseVariables } from '@/features/variables/deepParseVariable'
|
||||
import { transformStringVariablesToList } from '@/features/variables/transformVariablesToList'
|
||||
import { updateVariables } from '@/features/variables/updateVariables'
|
||||
|
||||
export const injectVariableValuesInButtonsInputBlock =
|
||||
(variables: SessionState['typebot']['variables']) =>
|
||||
(block: ChoiceInputBlock): ChoiceInputBlock => {
|
||||
(state: SessionState) =>
|
||||
async (block: ChoiceInputBlock): Promise<ChoiceInputBlock> => {
|
||||
if (block.options.dynamicVariableId) {
|
||||
const variable = variables.find(
|
||||
const variable = state.typebot.variables.find(
|
||||
(variable) =>
|
||||
variable.id === block.options.dynamicVariableId &&
|
||||
isDefined(variable.value)
|
||||
) as VariableWithValue | undefined
|
||||
if (!variable || typeof variable.value === 'string') return block
|
||||
if (!variable) return block
|
||||
const value = await getVariableValue(state)(variable)
|
||||
return {
|
||||
...block,
|
||||
items: variable.value.filter(isDefined).map((item, idx) => ({
|
||||
items: value.filter(isDefined).map((item, idx) => ({
|
||||
id: idx.toString(),
|
||||
type: ItemType.BUTTON,
|
||||
blockId: block.id,
|
||||
@ -27,5 +30,18 @@ export const injectVariableValuesInButtonsInputBlock =
|
||||
})),
|
||||
}
|
||||
}
|
||||
return deepParseVariables(variables)(block)
|
||||
return deepParseVariables(state.typebot.variables)(block)
|
||||
}
|
||||
|
||||
const getVariableValue =
|
||||
(state: SessionState) =>
|
||||
async (variable: VariableWithValue): Promise<(string | null)[]> => {
|
||||
if (!Array.isArray(variable.value)) {
|
||||
const [transformedVariable] = transformStringVariablesToList(
|
||||
state.typebot.variables
|
||||
)([variable.id])
|
||||
await updateVariables(state)([transformedVariable])
|
||||
return transformedVariable.value as string[]
|
||||
}
|
||||
return variable.value
|
||||
}
|
||||
|
@ -35,10 +35,11 @@ const matchComparison = (
|
||||
inputValue?: string,
|
||||
comparisonOperator?: ComparisonOperators,
|
||||
value?: string
|
||||
): boolean => {
|
||||
if (!inputValue || !comparisonOperator || !value) return false
|
||||
): boolean | undefined => {
|
||||
if (!comparisonOperator) return false
|
||||
switch (comparisonOperator) {
|
||||
case ComparisonOperators.CONTAINS: {
|
||||
if (!inputValue || !value) return false
|
||||
return inputValue.toLowerCase().includes(value.toLowerCase())
|
||||
}
|
||||
case ComparisonOperators.EQUAL: {
|
||||
@ -48,9 +49,11 @@ const matchComparison = (
|
||||
return inputValue !== value
|
||||
}
|
||||
case ComparisonOperators.GREATER: {
|
||||
if (!inputValue || !value) return false
|
||||
return parseFloat(inputValue) > parseFloat(value)
|
||||
}
|
||||
case ComparisonOperators.LESS: {
|
||||
if (!inputValue || !value) return false
|
||||
return parseFloat(inputValue) < parseFloat(value)
|
||||
}
|
||||
case ComparisonOperators.IS_SET: {
|
||||
@ -60,13 +63,16 @@ const matchComparison = (
|
||||
return !isDefined(inputValue) || inputValue.length === 0
|
||||
}
|
||||
case ComparisonOperators.STARTS_WITH: {
|
||||
if (!inputValue || !value) return false
|
||||
return inputValue.toLowerCase().startsWith(value.toLowerCase())
|
||||
}
|
||||
case ComparisonOperators.ENDS_WITH: {
|
||||
if (!inputValue || !value) return false
|
||||
return inputValue.toLowerCase().endsWith(value.toLowerCase())
|
||||
}
|
||||
case ComparisonOperators.NOT_CONTAINS: {
|
||||
return !inputValue.toLowerCase().includes(value.toLowerCase())
|
||||
if (!inputValue || !value) return false
|
||||
return !inputValue?.toLowerCase().includes(value.toLowerCase())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -184,13 +184,11 @@ const parseBubbleBlock =
|
||||
}
|
||||
|
||||
const injectVariablesValueInBlock =
|
||||
(state: Pick<SessionState, 'result' | 'typebot'>) =>
|
||||
(state: SessionState) =>
|
||||
async (block: InputBlock): Promise<ChatReply['input']> => {
|
||||
switch (block.type) {
|
||||
case InputBlockType.CHOICE: {
|
||||
return injectVariableValuesInButtonsInputBlock(state.typebot.variables)(
|
||||
block
|
||||
)
|
||||
return injectVariableValuesInButtonsInputBlock(state)(block)
|
||||
}
|
||||
case InputBlockType.PICTURE_CHOICE: {
|
||||
return injectVariableValuesInPictureChoiceBlock(
|
||||
|
Reference in New Issue
Block a user