From 4b874dfff483df2be8d400f568d1bbf1a56af79c Mon Sep 17 00:00:00 2001 From: Eric Nguyen Date: Mon, 19 Sep 2022 08:46:41 +0000 Subject: [PATCH] Merged PR 186: Implement filterlists --- src/Components/Category/Category.tsx | 4 +-- src/Components/Sidebar/Sidebar.tsx | 37 +++++++++++++++++++++++++-- src/Components/UI/UI.tsx | 1 + src/Interfaces/IAvailableContainer.ts | 12 +++++++++ src/index.scss | 4 ++- test-server/http.js | 2 ++ 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/Components/Category/Category.tsx b/src/Components/Category/Category.tsx index c8cdafa..29fc53e 100644 --- a/src/Components/Category/Category.tsx +++ b/src/Components/Category/Category.tsx @@ -4,7 +4,7 @@ import { ICategory } from '../../Interfaces/ICategory'; import { TruncateString } from '../../utils/stringtools'; interface ICategoryProps { - children: JSX.Element | JSX.Element[] + children: JSX.Element[] category: ICategory } @@ -22,7 +22,7 @@ export function Category(props: ICategoryProps): JSX.Element { title={categoryDisplayedText} >
setIsOpen(!isOpen)} > diff --git a/src/Components/Sidebar/Sidebar.tsx b/src/Components/Sidebar/Sidebar.tsx index 85fa2d1..40b01af 100644 --- a/src/Components/Sidebar/Sidebar.tsx +++ b/src/Components/Sidebar/Sidebar.tsx @@ -1,10 +1,13 @@ +import { EyeIcon, EyeOffIcon } from '@heroicons/react/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 @@ -21,6 +24,8 @@ interface SidebarCategory { } 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, @@ -41,12 +46,25 @@ export function Sidebar(props: ISidebarProps): JSX.Element { ); }); + 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; @@ -69,6 +89,7 @@ export function Sidebar(props: ISidebarProps): JSX.Element { console.error(`[Category] Category does not exists in configuration.Categories: ${componentOption.Category}`); return; } + category.children.push(componentButton); }); @@ -77,10 +98,22 @@ export function Sidebar(props: ISidebarProps): JSX.Element {
-
+
Components +
-
{rootElements}
diff --git a/src/Components/UI/UI.tsx b/src/Components/UI/UI.tsx index 702ced8..683872c 100644 --- a/src/Components/UI/UI.tsx +++ b/src/Components/UI/UI.tsx @@ -84,6 +84,7 @@ export function UI(props: IUIProps): JSX.Element { } }/> diff --git a/src/index.scss b/src/index.scss index b6bdcce..ddd5870 100644 --- a/src/index.scss +++ b/src/index.scss @@ -8,7 +8,9 @@ } .sidebar-component { - @apply transition-all px-2 py-6 text-sm rounded-lg bg-slate-300/80 hover:bg-blue-500 hover:text-slate-50 + @apply transition-all px-2 py-6 text-sm rounded-lg + bg-slate-300/80 hover:bg-blue-500 hover:text-slate-50 + disabled:bg-slate-400 disabled:text-slate-500 } .sidebar-component-left { diff --git a/test-server/http.js b/test-server/http.js index c170204..f7fce66 100644 --- a/test-server/http.js +++ b/test-server/http.js @@ -65,6 +65,7 @@ const GetSVGLayoutConfiguration = () => { { Type: 'Chassis', DisplayedText: 'Chassis?', + Whitelist: ["Trou"], MaxWidth: 500, MinWidth: 200, Width: 200, @@ -81,6 +82,7 @@ const GetSVGLayoutConfiguration = () => { }, { Type: 'Trou', + Blacklist: ["Chassis"], DefaultX: 0, DefaultY: 0, Margin: {