From 008fc5b2ec23bc3ce71462302554d41aa127b2ad Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Wed, 3 Nov 2021 17:33:55 +0100 Subject: [PATCH 1/2] fix: missing entries in selection view --- .../packageData/model/PythonPackage.ts | 2 +- .../packageData/treeView/TreeNode.tsx | 38 +++++++++---------- .../packageData/treeView/TreeView.tsx | 13 ++++--- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/client/src/features/packageData/model/PythonPackage.ts b/client/src/features/packageData/model/PythonPackage.ts index 0f6199130..4ae258c5c 100644 --- a/client/src/features/packageData/model/PythonPackage.ts +++ b/client/src/features/packageData/model/PythonPackage.ts @@ -31,7 +31,7 @@ export default class PythonPackage extends PythonDeclaration { } filter(pythonFilter: PythonFilter | void): PythonPackage { - if (!pythonFilter) { + if (!pythonFilter || !pythonFilter.isFiltering()) { return this; } diff --git a/client/src/features/packageData/treeView/TreeNode.tsx b/client/src/features/packageData/treeView/TreeNode.tsx index d7fc5178f..9d43dc8f3 100644 --- a/client/src/features/packageData/treeView/TreeNode.tsx +++ b/client/src/features/packageData/treeView/TreeNode.tsx @@ -1,4 +1,4 @@ -import { HStack, Icon, Text } from '@chakra-ui/react'; +import { HStack, Icon, Text as ChakraText } from '@chakra-ui/react'; import React from 'react'; import { IconType } from 'react-icons/lib'; import { useLocation } from 'react-router'; @@ -19,7 +19,6 @@ interface TreeNodeProps extends ChildrenProp { } const TreeNode: React.FC = function ({ - children, declaration, icon, isExpandable, @@ -47,25 +46,22 @@ const TreeNode: React.FC = function ({ }; return ( - <> - - - - {declaration.name} - - {showChildren && children} - + + + + {declaration.name} + ); }; diff --git a/client/src/features/packageData/treeView/TreeView.tsx b/client/src/features/packageData/treeView/TreeView.tsx index fce1c9fad..a43dcc08f 100644 --- a/client/src/features/packageData/treeView/TreeView.tsx +++ b/client/src/features/packageData/treeView/TreeView.tsx @@ -31,7 +31,7 @@ const TreeView: React.FC = memo(({ pythonPackage }) => { const dispatch = useAppDispatch(); const allExpanded = useAppSelector(selectAllExpandedInTreeView); - const children = walkChildrenWithPreOrder(allExpanded, pythonPackage); + const children = walkChildrenInPreorder(allExpanded, pythonPackage); const previousScrollOffset = useAppSelector(selectTreeViewScrollOffset); // Keep a reference to the last FixedSizeList before everything is dismounted @@ -85,13 +85,16 @@ const TreeView: React.FC = memo(({ pythonPackage }) => { ); }); -const walkChildrenWithPreOrder = function ( - allExpandedInTreeView: { [target: string]: true }, +const walkChildrenInPreorder = function ( + allExpandedItemsInTreeView: { [target: string]: true }, declaration: PythonDeclaration, ): PythonDeclaration[] { return declaration.children().flatMap((it) => { - if (allExpandedInTreeView[it.pathAsString()]) { - return [it, ...walkChildrenWithPreOrder(allExpandedInTreeView, it)]; + if (allExpandedItemsInTreeView[it.pathAsString()]) { + return [ + it, + ...walkChildrenInPreorder(allExpandedItemsInTreeView, it), + ]; } else { return [it]; } From 547616634672b1a061c4e4bffeec9c6c551e5a00 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Wed, 3 Nov 2021 17:57:20 +0100 Subject: [PATCH 2/2] fix: missing entries in selection view when filtering --- client/src/common/MenuBar.tsx | 10 ++++++---- .../features/packageData/model/PythonClass.ts | 7 +++++-- .../features/packageData/model/PythonFilter.ts | 18 +++++++++++++++++- .../packageData/model/PythonFunction.ts | 2 +- .../features/packageData/model/PythonModule.ts | 12 +++++++++--- .../packageData/model/PythonPackage.ts | 7 +++++-- 6 files changed, 43 insertions(+), 13 deletions(-) diff --git a/client/src/common/MenuBar.tsx b/client/src/common/MenuBar.tsx index 4e66823ba..2a2cb7171 100644 --- a/client/src/common/MenuBar.tsx +++ b/client/src/common/MenuBar.tsx @@ -21,7 +21,7 @@ import { PopoverContent, PopoverTrigger, Spacer, - Text, + Text as ChakraText, useColorMode, } from '@chakra-ui/react'; import React, { useRef } from 'react'; @@ -83,7 +83,9 @@ const MenuBar: React.FC = function ({ filter, setFilter }) { {part} )} - {!enableNavigation && {part}} + {!enableNavigation && ( + {part} + )} ))} @@ -143,7 +145,7 @@ const MenuBar: React.FC = function ({ filter, setFilter }) { borderColor={ PythonFilter.fromFilterBoxInput( filter, - )?.isFiltering() + )?.isFilteringModules() ? 'green' : 'inherit' } @@ -151,7 +153,7 @@ const MenuBar: React.FC = function ({ filter, setFilter }) { /> {PythonFilter.fromFilterBoxInput( filter, - )?.isFiltering() && ( + )?.isFilteringModules() && ( diff --git a/client/src/features/packageData/model/PythonClass.ts b/client/src/features/packageData/model/PythonClass.ts index 8761402c5..91ba54115 100644 --- a/client/src/features/packageData/model/PythonClass.ts +++ b/client/src/features/packageData/model/PythonClass.ts @@ -66,7 +66,7 @@ export default class PythonClass extends PythonDeclaration { } filter(pythonFilter: PythonFilter | void): PythonClass { - if (!pythonFilter) { + if (!pythonFilter || !pythonFilter.isFilteringFunctions()) { return this; } @@ -78,7 +78,10 @@ export default class PythonClass extends PythonDeclaration { .toLowerCase() .includes( (pythonFilter.pythonFunction || '').toLowerCase(), - ) && !isEmptyList(it.parameters), + ) && + // Don't exclude functions without parameters when we don't filter parameters + (!pythonFilter.isFilteringParameters() || + !isEmptyList(it.parameters)), ); return new PythonClass( diff --git a/client/src/features/packageData/model/PythonFilter.ts b/client/src/features/packageData/model/PythonFilter.ts index 818de954f..573893299 100644 --- a/client/src/features/packageData/model/PythonFilter.ts +++ b/client/src/features/packageData/model/PythonFilter.ts @@ -70,7 +70,7 @@ export class PythonFilter { ); } - isFiltering(): boolean { + isFilteringModules(): boolean { return ( Boolean(this.pythonModule) || Boolean(this.pythonClass) || @@ -78,4 +78,20 @@ export class PythonFilter { Boolean(this.pythonParameter) ); } + + isFilteringClasses(): boolean { + return ( + Boolean(this.pythonClass) || + Boolean(this.pythonFunction) || + Boolean(this.pythonParameter) + ); + } + + isFilteringFunctions(): boolean { + return Boolean(this.pythonFunction) || Boolean(this.pythonParameter); + } + + isFilteringParameters(): boolean { + return Boolean(this.pythonParameter); + } } diff --git a/client/src/features/packageData/model/PythonFunction.ts b/client/src/features/packageData/model/PythonFunction.ts index 22fbfef81..70fcba466 100644 --- a/client/src/features/packageData/model/PythonFunction.ts +++ b/client/src/features/packageData/model/PythonFunction.ts @@ -80,7 +80,7 @@ export default class PythonFunction extends PythonDeclaration { } filter(pythonFilter: PythonFilter | void): PythonFunction { - if (!pythonFilter) { + if (!pythonFilter || !pythonFilter.isFilteringParameters()) { return this; } diff --git a/client/src/features/packageData/model/PythonModule.ts b/client/src/features/packageData/model/PythonModule.ts index 356bc9a2c..f026c10f8 100644 --- a/client/src/features/packageData/model/PythonModule.ts +++ b/client/src/features/packageData/model/PythonModule.ts @@ -54,7 +54,8 @@ export default class PythonModule extends PythonDeclaration { } filter(pythonFilter: PythonFilter | void): PythonModule { - if (!pythonFilter) { + // isFilteringClasses is also true if we are filtering functions + if (!pythonFilter || !pythonFilter.isFilteringClasses()) { return this; } @@ -66,7 +67,10 @@ export default class PythonModule extends PythonDeclaration { .toLowerCase() .includes( (pythonFilter.pythonClass || '').toLowerCase(), - ) && !isEmptyList(it.methods), + ) && + // Don't exclude empty classes when we only filter modules or classes + (!pythonFilter.isFilteringFunctions() || + !isEmptyList(it.methods)), ); const functions = this.functions @@ -79,7 +83,9 @@ export default class PythonModule extends PythonDeclaration { .includes( (pythonFilter.pythonFunction || '').toLowerCase(), ) && - !isEmptyList(it.parameters), + // Don't exclude functions without parameters when we don't filter parameters + (!pythonFilter.isFilteringParameters() || + !isEmptyList(it.parameters)), ); return new PythonModule( diff --git a/client/src/features/packageData/model/PythonPackage.ts b/client/src/features/packageData/model/PythonPackage.ts index 4ae258c5c..11dddd2c8 100644 --- a/client/src/features/packageData/model/PythonPackage.ts +++ b/client/src/features/packageData/model/PythonPackage.ts @@ -31,7 +31,7 @@ export default class PythonPackage extends PythonDeclaration { } filter(pythonFilter: PythonFilter | void): PythonPackage { - if (!pythonFilter || !pythonFilter.isFiltering()) { + if (!pythonFilter || !pythonFilter.isFilteringModules()) { return this; } @@ -44,7 +44,10 @@ export default class PythonPackage extends PythonDeclaration { .includes( (pythonFilter.pythonModule || '').toLowerCase(), ) && - (!isEmptyList(it.classes) || !isEmptyList(it.functions)), + // Don't exclude empty modules when we only filter modules + (!pythonFilter.isFilteringClasses() || + !isEmptyList(it.classes) || + !isEmptyList(it.functions)), ); return new PythonPackage(this.name, modules);