2
0

️ Add search input in blocks sidebar (#1677)

Hi, @baptisteArno Added the search input in blocks sidebar.
Resolve #359.

Works with tags and description as well.

---------

Co-authored-by: @Kavita2599 <kavita99@netart.io>
Co-authored-by: Baptiste Arnaud <baptiste.arnaud95@gmail.com>
This commit is contained in:
Kavita Rawat
2024-08-13 21:52:53 +05:30
committed by GitHub
parent 09890a756e
commit 98b2837576

View File

@ -7,6 +7,7 @@ import {
Portal, Portal,
Flex, Flex,
IconButton, IconButton,
Input,
Tooltip, Tooltip,
Fade, Fade,
useColorModeValue, 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 { LogicBlockType } from '@typebot.io/schemas/features/blocks/logic/constants'
import { BlockV6 } from '@typebot.io/schemas' import { BlockV6 } from '@typebot.io/schemas'
import { useDebouncedCallback } from 'use-debounce' 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 // Integration blocks migrated to forged blocks
const legacyIntegrationBlocks = [IntegrationBlockType.OPEN_AI] const legacyIntegrationBlocks = [IntegrationBlockType.OPEN_AI]
@ -39,6 +40,7 @@ export const BlocksSideBar = () => {
const [relativeCoordinates, setRelativeCoordinates] = useState({ x: 0, y: 0 }) const [relativeCoordinates, setRelativeCoordinates] = useState({ x: 0, y: 0 })
const [isLocked, setIsLocked] = useState(true) const [isLocked, setIsLocked] = useState(true)
const [isExtended, setIsExtended] = useState(true) const [isExtended, setIsExtended] = useState(true)
const [searchInput, setSearchInput] = useState('')
const closeSideBar = useDebouncedCallback(() => setIsExtended(false), 200) const closeSideBar = useDebouncedCallback(() => setIsExtended(false), 200)
@ -85,6 +87,26 @@ export const BlocksSideBar = () => {
closeSideBar() closeSideBar()
} }
const handleSearchInputChange = (event: {
target: { value: React.SetStateAction<string> }
}) => {
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 ( return (
<Flex <Flex
w="360px" w="360px"
@ -103,7 +125,7 @@ export const BlocksSideBar = () => {
rounded="lg" rounded="lg"
shadow="xl" shadow="xl"
borderWidth="1px" borderWidth="1px"
pt="2" pt="4"
pb="10" pb="10"
px="4" px="4"
bgColor={useColorModeValue('white', 'gray.900')} bgColor={useColorModeValue('white', 'gray.900')}
@ -111,7 +133,17 @@ export const BlocksSideBar = () => {
userSelect="none" userSelect="none"
overflowY="auto" overflowY="auto"
> >
<Flex justifyContent="flex-end"> <Flex
justifyContent="space-between"
w="full"
alignItems="center"
gap="3"
>
<Input
placeholder="Search"
value={searchInput}
onChange={handleSearchInputChange}
/>
<Tooltip <Tooltip
label={ label={
isLocked isLocked
@ -137,9 +169,17 @@ export const BlocksSideBar = () => {
{t('editor.sidebarBlocks.blockType.bubbles.heading')} {t('editor.sidebarBlocks.blockType.bubbles.heading')}
</Text> </Text>
<SimpleGrid columns={2} spacing="3"> <SimpleGrid columns={2} spacing="3">
{Object.values(BubbleBlockType).map((type) => ( {Object.values(BubbleBlockType)
<BlockCard key={type} type={type} onMouseDown={handleMouseDown} /> .filter((type) =>
))} type.toLowerCase().includes(searchInput.toLowerCase())
)
.map((type) => (
<BlockCard
key={type}
type={type}
onMouseDown={handleMouseDown}
/>
))}
</SimpleGrid> </SimpleGrid>
</Stack> </Stack>
@ -148,9 +188,17 @@ export const BlocksSideBar = () => {
{t('editor.sidebarBlocks.blockType.inputs.heading')} {t('editor.sidebarBlocks.blockType.inputs.heading')}
</Text> </Text>
<SimpleGrid columns={2} spacing="3"> <SimpleGrid columns={2} spacing="3">
{Object.values(InputBlockType).map((type) => ( {Object.values(InputBlockType)
<BlockCard key={type} type={type} onMouseDown={handleMouseDown} /> .filter((type) =>
))} type.toLowerCase().includes(searchInput.toLowerCase())
)
.map((type) => (
<BlockCard
key={type}
type={type}
onMouseDown={handleMouseDown}
/>
))}
</SimpleGrid> </SimpleGrid>
</Stack> </Stack>
@ -159,9 +207,17 @@ export const BlocksSideBar = () => {
{t('editor.sidebarBlocks.blockType.logic.heading')} {t('editor.sidebarBlocks.blockType.logic.heading')}
</Text> </Text>
<SimpleGrid columns={2} spacing="3"> <SimpleGrid columns={2} spacing="3">
{Object.values(LogicBlockType).map((type) => ( {Object.values(LogicBlockType)
<BlockCard key={type} type={type} onMouseDown={handleMouseDown} /> .filter((type) =>
))} type.toLowerCase().includes(searchInput.toLowerCase())
)
.map((type) => (
<BlockCard
key={type}
type={type}
onMouseDown={handleMouseDown}
/>
))}
</SimpleGrid> </SimpleGrid>
</Stack> </Stack>
@ -171,7 +227,10 @@ export const BlocksSideBar = () => {
</Text> </Text>
<SimpleGrid columns={2} spacing="3"> <SimpleGrid columns={2} spacing="3">
{Object.values(IntegrationBlockType) {Object.values(IntegrationBlockType)
.concat(forgedBlockIds as any) .filter((type) =>
type.toLowerCase().includes(searchInput.toLowerCase())
)
.concat(filteredForgedBlockIds as any)
.filter((type) => !legacyIntegrationBlocks.includes(type)) .filter((type) => !legacyIntegrationBlocks.includes(type))
.map((type) => ( .map((type) => (
<BlockCard <BlockCard