Skip to content

Commit

Permalink
fix(editor): fix node creator search when there's active subcategory (#…
Browse files Browse the repository at this point in the history
…4494)

* fix(editor): fix node creator search when there's active subcategory

* 🎨 Add intersection util and replace lodash one with it

* 🎨 Remove unused imports
  • Loading branch information
OlegIvaniv authored Nov 1, 2022
1 parent d1d1288 commit f244975
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import { INodeCreateElement, INodeItemProps, ISubcategoryItemProps, ICategoriesW
import { WEBHOOK_NODE_TYPE, HTTP_REQUEST_NODE_TYPE, ALL_NODE_FILTER, TRIGGER_NODE_FILTER, REGULAR_NODE_FILTER, NODE_TYPE_COUNT_MAPPER } from '@/constants';
import { matchesNodeType, matchesSelectType } from './helpers';
import { BaseTextKey } from '@/plugins/i18n';
import { intersection } from '@/utils';
import { sublimeSearch } from './sortUtils';
export default mixins(externalHooks, globalLinkActions).extend({
Expand Down Expand Up @@ -181,7 +182,10 @@ export default mixins(externalHooks, globalLinkActions).extend({
},
filteredNodeTypes(): INodeCreateElement[] {
const filter = this.searchFilter;
const searchableNodes = this.subcategorizedNodes.length > 0 ? this.subcategorizedNodes : this.searchItems;
const searchableNodes = this.subcategorizedNodes.length > 0 && this.activeSubcategory?.key !== '*'
? this.subcategorizedNodes
: this.searchItems;
let returnItems: INodeCreateElement[] = [];
if (this.defaultLocale !== 'en') {
Expand All @@ -196,15 +200,19 @@ export default mixins(externalHooks, globalLinkActions).extend({
}
const filteredNodeTypes = this.excludedCategories.length === 0
? returnItems
: this.filterOutNodexFromExcludedCategories(returnItems);
setTimeout(() => {
this.$externalHooks().run('nodeCreateList.filteredNodeTypesComputed', {
nodeFilter: this.nodeFilter,
result: returnItems,
result: filteredNodeTypes,
selectedType: this.selectedType,
});
}, 0);
return returnItems;
return filteredNodeTypes;
},
filteredAllNodeTypes(): INodeCreateElement[] {
if(this.filteredNodeTypes.length > 0) return [];
Expand Down Expand Up @@ -334,6 +342,16 @@ export default mixins(externalHooks, globalLinkActions).extend({
},
},
methods: {
filterOutNodexFromExcludedCategories(nodes: INodeCreateElement[]) {
return nodes.filter(node => {
const excludedCategoriesIntersect = intersection(
this.excludedCategories,
((node.properties as INodeItemProps)?.nodeType.codex?.categories || []),
);
return excludedCategoriesIntersect.length === 0;
});
},
switchToAllTabAndFilter() {
const currentFilter = this.nodeFilter;
this.$store.commit('nodeCreator/setShowTabs', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:initialActiveIndex="0"
:searchItems="searchItems"
:firstLevelItems="isRoot ? items : []"
:excludedCategories="[CORE_NODES_CATEGORY]"
:excludedCategories="isRoot ? [] : [CORE_NODES_CATEGORY]"
:initialActiveCategories="[COMMUNICATION_CATEGORY]"
>
<template #header>
Expand Down Expand Up @@ -53,7 +53,7 @@ export default mixins(externalHooks).extend({
computed: {
items() {
return [{
key: "core_nodes",
key: "*",
type: "subcategory",
title: this.$locale.baseText('nodeCreator.subcategoryNames.appTriggerNodes'),
properties: {
Expand Down
2 changes: 2 additions & 0 deletions packages/editor-ui/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ export const isEmpty = (value?: unknown): boolean => {
}
return false;
};

export const intersection = <T>(a: T[], b:T[]): T[] => a.filter(Set.prototype.has, new Set(b));

0 comments on commit f244975

Please sign in to comment.