Skip to content

Commit

Permalink
🐛 (sheets) Fix empty and unique filter
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 26, 2023
1 parent 75f9da0 commit 154271c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,42 @@ 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,
content: item,
})),
}
}
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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())
}
}
}
6 changes: 2 additions & 4 deletions apps/viewer/src/features/chat/helpers/executeGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

4 comments on commit 154271c

@vercel
Copy link

@vercel vercel bot commented on 154271c May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

app.typebot.io
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 154271c May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-typebot-io.vercel.app
docs.typebot.io
docs-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 154271c May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 154271c May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

bii.bj
1stop.au
wasap.nl
yobot.me
klujo.com
wassep.io
lb.ticketfute.com
ov1.wpwakanda.com
ov2.wpwakanda.com
ov3.wpwakanda.com
support.triplo.ai
viewer.typebot.io
welcome.triplo.ai
1988.bouclidom.com
amancarseat.online
andreimayer.com.br
bot.danyservice.it
bot.iconicbrows.it
bot.lucide.contact
bot.neferlopez.com
bot.planoja.com.br
bots.robomotion.io
cadu.uninta.edu.br
chat.hand-made.one
chat.tuanpakya.com
chat.webisharp.com
dicanatural.online
digitalhelp.com.au
goalsettingbot.com
noticiasnet.online
pant.maxbot.com.br
pantherview.cr8.ai
positivobra.com.br
rollingball.cr8.ai
survey.digienge.io
this-is-a-test.com
zap.techadviser.in
ai.digitaldaftar.in
bot.boston-voip.com
bot.cabinpromos.com
bot.carnaval.studio
bot.digitalbled.com
bot.dsignagency.com
bot.enthrallart.com
bot.eventhub.com.au
bot.jepierre.com.br
bot.leadgenpod.site
bot.ltmidias.com.br
bot.viralsangat.com
bot.winglabs.com.br
carsalesenquiry.com
chat.marius.digital
chat.sr7digital.com
chatbot.matthesv.de
chatbot.repplai.com
demo.botscientis.us
demo.wemakebots.xyz
hrbot.robomotion.io
inearephones.cr8.ai
kbsub.wpwakanda.com
limitenahora.com.br
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
order.maitempah.com
profileadscloud.com
query.forgetsql.com
quest.wpwakanda.com
support.wawplus.com
survey1.digienge.io
surveys.essiell.com
test.botscientis.us
test.getreview.help
test.reventepro.com
typebot.stillio.com
wordsandimagery.com
88584434.therpm.club
92109660.therpm.club
abbonamento.bwell.it
assistent.m-vogel.de
bium.gratirabbit.com
bot.ansuraniphone.my
bot.barrettamario.it
bot.cotemeuplano.com
bot.leadbooster.help
bot.mycompay.reviews
chat.hayurihijab.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
forms.bonanza.design
hello.advergreen.com
kuiz.sistemniaga.com
menu.numero-primo.it
menukb.wpwakanda.com
offer.botscientis.us
sellmycarglasgow.com
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com

Please sign in to comment.