import { EyeIcon, EyeSlashIcon } from '@heroicons/react/24/outline'; import * as React from 'react'; import { IAvailableContainer } from '../../Interfaces/IAvailableContainer'; import { ICategory } from '../../Interfaces/ICategory'; import { IContainerModel } from '../../Interfaces/IContainerModel'; import { TruncateString } from '../../utils/stringtools'; import { Category } from '../Category/Category'; interface ISidebarProps { selectedContainer: IContainerModel | undefined componentOptions: IAvailableContainer[] categories: ICategory[] isOpen: boolean buttonOnClick: (type: string) => void } function HandleDragStart(event: React.DragEvent): void { event.dataTransfer.setData('type', (event.target as HTMLButtonElement).id); } interface SidebarCategory { category: ICategory children: JSX.Element[] } export function Sidebar(props: ISidebarProps): JSX.Element { const [hideDisabled, setHideDisabled] = React.useState(false); const rootElements: Array = []; const categories = new Map(props.categories.map(category => [ category.Type, { category, children: [] } ])); // build the categories (sorted with categories first) categories.forEach((categoryWrapper, categoryName) => { rootElements.push( { categoryWrapper.children } ); }); const selectedContainer = props.selectedContainer; const config = props.componentOptions.find(option => option.Type === selectedContainer?.properties.type); // build the components props.componentOptions.forEach(componentOption => { if (componentOption.IsHidden === true) { return; } let disabled = false; if (config?.Whitelist !== undefined) { disabled = config.Whitelist?.find(type => type === componentOption.Type) === undefined; } else if (config?.Blacklist !== undefined) { disabled = config.Blacklist?.find(type => type === componentOption.Type) !== undefined ?? false; } if (disabled && hideDisabled) { return; } const componentButton = (); if (componentOption.Category === null || componentOption.Category === undefined) { rootElements.push(componentButton); return; } const category = categories.get(componentOption.Category); if (category === undefined) { console.error(`[Category] Category does not exists in configuration.Categories: ${componentOption.Category}`); return; } category.children.push(componentButton); }); const isOpenClasses = props.isOpen ? 'left-16' : '-left-64'; return (
Components
{rootElements}
); };