From 98b2837576d76d3b0b050d5797a38d0a61f937f2 Mon Sep 17 00:00:00 2001 From: Kavita Rawat <99713335+KavitaR45@users.noreply.github.com> Date: Tue, 13 Aug 2024 21:52:53 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Add=20search=20input=20in?= =?UTF-8?q?=20blocks=20sidebar=20(#1677)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi, @baptisteArno Added the search input in blocks sidebar. Resolve #359. Works with tags and description as well. --------- Co-authored-by: @Kavita2599 Co-authored-by: Baptiste Arnaud --- .../editor/components/BlocksSideBar.tsx | 85 ++++++++++++++++--- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/apps/builder/src/features/editor/components/BlocksSideBar.tsx b/apps/builder/src/features/editor/components/BlocksSideBar.tsx index e49541660..d9689e243 100644 --- a/apps/builder/src/features/editor/components/BlocksSideBar.tsx +++ b/apps/builder/src/features/editor/components/BlocksSideBar.tsx @@ -7,6 +7,7 @@ import { Portal, Flex, IconButton, + Input, Tooltip, Fade, useColorModeValue, @@ -24,7 +25,7 @@ import { IntegrationBlockType } from '@typebot.io/schemas/features/blocks/integr import { LogicBlockType } from '@typebot.io/schemas/features/blocks/logic/constants' import { BlockV6 } from '@typebot.io/schemas' import { useDebouncedCallback } from 'use-debounce' -import { forgedBlockIds } from '@typebot.io/forge-repository/constants' +import { forgedBlocks } from '@typebot.io/forge-repository/definitions' // Integration blocks migrated to forged blocks const legacyIntegrationBlocks = [IntegrationBlockType.OPEN_AI] @@ -39,6 +40,7 @@ export const BlocksSideBar = () => { const [relativeCoordinates, setRelativeCoordinates] = useState({ x: 0, y: 0 }) const [isLocked, setIsLocked] = useState(true) const [isExtended, setIsExtended] = useState(true) + const [searchInput, setSearchInput] = useState('') const closeSideBar = useDebouncedCallback(() => setIsExtended(false), 200) @@ -85,6 +87,26 @@ export const BlocksSideBar = () => { closeSideBar() } + const handleSearchInputChange = (event: { + target: { value: React.SetStateAction } + }) => { + setSearchInput(event.target.value) + } + const blocksArray = Object.values(forgedBlocks) + + const filteredForgedBlockIds = blocksArray + .filter((block) => { + return ( + block.id.toLowerCase().includes(searchInput.toLowerCase()) || + (block.tags && + block.tags.some((tag: string) => + tag.toLowerCase().includes(searchInput.toLowerCase()) + )) || + block.name.toLowerCase().includes(searchInput.toLowerCase()) + ) + }) + .map((block) => block.id) + return ( { rounded="lg" shadow="xl" borderWidth="1px" - pt="2" + pt="4" pb="10" px="4" bgColor={useColorModeValue('white', 'gray.900')} @@ -111,7 +133,17 @@ export const BlocksSideBar = () => { userSelect="none" overflowY="auto" > - + + { {t('editor.sidebarBlocks.blockType.bubbles.heading')} - {Object.values(BubbleBlockType).map((type) => ( - - ))} + {Object.values(BubbleBlockType) + .filter((type) => + type.toLowerCase().includes(searchInput.toLowerCase()) + ) + .map((type) => ( + + ))} @@ -148,9 +188,17 @@ export const BlocksSideBar = () => { {t('editor.sidebarBlocks.blockType.inputs.heading')} - {Object.values(InputBlockType).map((type) => ( - - ))} + {Object.values(InputBlockType) + .filter((type) => + type.toLowerCase().includes(searchInput.toLowerCase()) + ) + .map((type) => ( + + ))} @@ -159,9 +207,17 @@ export const BlocksSideBar = () => { {t('editor.sidebarBlocks.blockType.logic.heading')} - {Object.values(LogicBlockType).map((type) => ( - - ))} + {Object.values(LogicBlockType) + .filter((type) => + type.toLowerCase().includes(searchInput.toLowerCase()) + ) + .map((type) => ( + + ))} @@ -171,7 +227,10 @@ export const BlocksSideBar = () => { {Object.values(IntegrationBlockType) - .concat(forgedBlockIds as any) + .filter((type) => + type.toLowerCase().includes(searchInput.toLowerCase()) + ) + .concat(filteredForgedBlockIds as any) .filter((type) => !legacyIntegrationBlocks.includes(type)) .map((type) => (