import React, { useState } from 'react'; import { DraggableBox } from './DraggableBox'; import Fuse from 'fuse.js'; import { isEmpty } from 'lodash'; export const WidgetManager = function WidgetManager({ componentTypes, zoomLevel, currentLayout }) { const [filteredComponents, setFilteredComponents] = useState(componentTypes); function filterComponents(value) { if (value != '') { const fuse = new Fuse(componentTypes, { keys: ['component'] }); const results = fuse.search(value); setFilteredComponents(results.map((result) => result.item)); } else { setFilteredComponents(componentTypes); } } function renderComponentCard(component, index) { return ( ); } function renderList(header, items) { if (isEmpty(items)) return null; return ( <> {header} {items.map((component, i) => renderComponentCard(component, i))} ); } function segregateSections() { if (filteredComponents.length === 0) { return (
{/*
*/}

No results found

Try adjusting your search or filter to find what you're looking for.

); } const commonSection = { title: 'commonly used', items: [] }; const formSection = { title: 'forms', items: [] }; const integrationSection = { title: 'integrations', items: [] }; const otherSection = { title: 'others', items: [] }; const commonItems = ['Table', 'Chart', 'Button', 'Text', 'Datepicker']; const formItems = [ 'TextInput', 'NumberInput', 'Textarea', 'Dropdown', 'Multiselect', 'RichTextEditor', 'Checkbox', 'Radio-button', 'Datepicker', ]; const integrationItems = ['Map']; filteredComponents.map((f) => { if (commonItems.includes(f.name)) commonSection.items.push(f); if (formItems.includes(f.name)) formSection.items.push(f); else if (integrationItems.includes(f.name)) integrationSection.items.push(f); else otherSection.items.push(f); }); return ( <> {renderList(commonSection.title, commonSection.items)} {renderList(formSection.title, formSection.items)} {renderList(otherSection.title, otherSection.items)} {renderList(integrationSection.title, integrationSection.items)} ); } return (
filterComponents(e.target.value)} />
{segregateSections()}
); };