diff --git a/packages/engine-frontend/components/IntegrationSearch.tsx b/packages/engine-frontend/components/IntegrationSearch.tsx index bfe42808..c453089c 100644 --- a/packages/engine-frontend/components/IntegrationSearch.tsx +++ b/packages/engine-frontend/components/IntegrationSearch.tsx @@ -1,8 +1,9 @@ 'use client' import {Loader, Search} from 'lucide-react' -import React from 'react' -import {Input} from '@openint/ui' +import {useState} from 'react' +import {Input, parseCategory} from '@openint/ui' +import {CheckboxFilter} from '@openint/ui/components/CheckboxFilter' import {ConnectionCard} from '@openint/ui/domain-components/ConnectionCard' import type {ConnectorConfig} from '../hocs/WithConnectConfig' import type {ConnectEventType} from '../hocs/WithConnectorConnect' @@ -25,7 +26,8 @@ export function IntegrationSearch({ type: ConnectEventType }) => void }) { - const [searchText, setSearchText] = React.useState('') + const [searchText, setSearchText] = useState('') + const [categoryFilter, setCategoryFilter] = useState([]) const listIntegrationsRes = _trpcReact.listConfiguredIntegrations.useQuery({ connector_config_ids: connectorConfigs.map((ccfg) => ccfg.id), @@ -36,24 +38,34 @@ export function IntegrationSearch({ ccfg: connectorConfigs.find((ccfg) => ccfg.id === int.connector_config_id)!, })) + const categories = Array.from( + new Set(connectorConfigs.flatMap((ccfg) => ccfg.verticals)), + ) + const intsByCategory = ints?.reduce( (acc, int) => { int.ccfg.verticals.forEach((vertical) => { - acc[vertical] = (acc[vertical] || []).concat(int) + if (categoryFilter.length === 0 || categoryFilter.includes(vertical)) { + acc[vertical] = (acc[vertical] || []).concat(int) + } }) return acc }, {} as Record, ) + const onApplyFilter = (selected: string[]) => { + setCategoryFilter(selected) + } + return (
{/* Search integrations */}
-
-
+
+
{/* top-2.5 is not working for some reason due to tailwind setup */} - + setSearchText(e.target.value)} />
- + {categories.length > 1 && ( + + )} +
{/* Search results */} {listIntegrationsRes.isLoading ? ( -
+
) : (
- {Object.entries(intsByCategory ?? {}).map( - ([category, categoryInts]) => ( -
-

- {category.length < 5 - ? category.toUpperCase() - : category - .split('-') - .map( - (word) => - word.charAt(0).toUpperCase() + word.slice(1), - ) - .join(' ')} -

-
- {categoryInts.map((int) => ( - { - onEvent?.({ - type: e.type, - integration: { - connectorConfigId: int.connector_config_id, - id: int.id, - }, - }) - }}> - {({openConnect}) => ( - - )} - - ))} + {(ints && ints.length > 0) || + Object.keys(intsByCategory ?? {}).length > 0 ? ( + Object.entries(intsByCategory ?? {}).map( + ([category, categoryInts]) => ( +
+

+ {parseCategory(category)} +

+
+ {categoryInts.map((int) => ( + { + onEvent?.({ + type: e.type, + integration: { + connectorConfigId: int.connector_config_id, + id: int.id, + }, + }) + }}> + {({openConnect}) => ( + + )} + + ))} +
-
- ), + ), + ) + ) : ( +
+

+ No available connectors, please check that you have configured + connectors available or review your filter values. +

+
)}
)} diff --git a/packages/ui/components/CheckboxFilter.tsx b/packages/ui/components/CheckboxFilter.tsx index 9d37ebf5..89daac84 100644 --- a/packages/ui/components/CheckboxFilter.tsx +++ b/packages/ui/components/CheckboxFilter.tsx @@ -3,13 +3,14 @@ import {useState} from 'react' import {Button} from '../shadcn/Button' import {Checkbox} from '../shadcn/Checkbox' import {Popover, PopoverContent, PopoverTrigger} from '../shadcn/Popover' +import {parseCategory} from '../utils' export function CheckboxFilter({ options, onApply, }: { options: string[] - onApply: () => void + onApply: (selected: string[]) => void }) { const [checkedState, setCheckedState] = useState>( options.reduce( @@ -37,7 +38,7 @@ export function CheckboxFilter({ Category - +
{options.map((option) => (
{checkedState[option] && ( @@ -80,14 +81,37 @@ export function CheckboxFilter({ htmlFor={option} className="cursor-pointer text-sm font-semibold"> {' '} - {option} + {parseCategory(option)}
))} {/* Added a visible divider here */}
-
- +
diff --git a/packages/ui/utils.ts b/packages/ui/utils.ts index 2ae4bafb..f6f76550 100644 --- a/packages/ui/utils.ts +++ b/packages/ui/utils.ts @@ -13,3 +13,12 @@ export function getValidChildren(children: React.ReactNode) { React.isValidElement(child), ) as React.ReactElement[] } + +export function parseCategory(category: string) { + return category.length < 5 + ? category.toUpperCase() + : category + .split('-') + .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(' ') +}