Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/src/common/MenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,15 @@ const MenuBar: React.FC<MenuBarProps> = function ({ filter, setFilter }) {
borderColor={
PythonFilter.fromFilterBoxInput(
filter,
)?.isFiltering()
)?.isFilteringModules()
? 'green'
: 'inherit'
}
spellCheck={false}
/>
{PythonFilter.fromFilterBoxInput(
filter,
)?.isFiltering() && (
)?.isFilteringModules() && (
<InputRightElement>
<Icon as={FaCheck} color="green.500" />
</InputRightElement>
Expand Down
7 changes: 5 additions & 2 deletions client/src/features/packageData/model/PythonClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class PythonClass extends PythonDeclaration {
}

filter(pythonFilter: PythonFilter | void): PythonClass {
if (!pythonFilter) {
if (!pythonFilter || !pythonFilter.isFilteringFunctions()) {
return this;
}

Expand All @@ -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(
Expand Down
18 changes: 17 additions & 1 deletion client/src/features/packageData/model/PythonFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,28 @@ export class PythonFilter {
);
}

isFiltering(): boolean {
isFilteringModules(): boolean {
return (
Boolean(this.pythonModule) ||
Boolean(this.pythonClass) ||
Boolean(this.pythonFunction) ||
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);
}
}
2 changes: 1 addition & 1 deletion client/src/features/packageData/model/PythonFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class PythonFunction extends PythonDeclaration {
}

filter(pythonFilter: PythonFilter | void): PythonFunction {
if (!pythonFilter) {
if (!pythonFilter || !pythonFilter.isFilteringParameters()) {
return this;
}

Expand Down
12 changes: 9 additions & 3 deletions client/src/features/packageData/model/PythonModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand All @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions client/src/features/packageData/model/PythonPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class PythonPackage extends PythonDeclaration {
}

filter(pythonFilter: PythonFilter | void): PythonPackage {
if (!pythonFilter) {
if (!pythonFilter || !pythonFilter.isFilteringModules()) {
return this;
}

Expand All @@ -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);
Expand Down
36 changes: 16 additions & 20 deletions client/src/features/packageData/treeView/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface TreeNodeProps extends ChildrenProp {
}

const TreeNode: React.FC<TreeNodeProps> = function ({
children,
declaration,
icon,
isExpandable,
Expand Down Expand Up @@ -47,25 +46,22 @@ const TreeNode: React.FC<TreeNodeProps> = function ({
};

return (
<>
<HStack
userSelect="none"
cursor="pointer"
color={color}
backgroundColor={backgroundColor}
paddingLeft={paddingLeft}
onClick={handleClick}
>
<VisibilityIndicator
hasChildren={isExpandable}
showChildren={showChildren}
isSelected={isSelected(declaration, currentPathname)}
/>
<Icon as={icon} />
<ChakraText>{declaration.name}</ChakraText>
</HStack>
{showChildren && children}
</>
<HStack
userSelect="none"
cursor="pointer"
color={color}
backgroundColor={backgroundColor}
paddingLeft={paddingLeft}
onClick={handleClick}
>
<VisibilityIndicator
hasChildren={isExpandable}
showChildren={showChildren}
isSelected={isSelected(declaration, currentPathname)}
/>
<Icon as={icon} />
<ChakraText>{declaration.name}</ChakraText>
</HStack>
);
};

Expand Down
13 changes: 8 additions & 5 deletions client/src/features/packageData/treeView/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const TreeView: React.FC<TreeViewProps> = 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
Expand Down Expand Up @@ -85,13 +85,16 @@ const TreeView: React.FC<TreeViewProps> = 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];
}
Expand Down