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

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

* 🎨 Add intersection util and replace lodash one with it

* 🎨 Remove unused imports
This commit is contained in:
OlegIvaniv 2022-11-01 17:11:31 +01:00 committed by GitHub
parent d1d1288ba9
commit f24497589f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 5 deletions

View file

@ -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({
@ -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') {
@ -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 [];
@ -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);

View file

@ -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>
@ -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: {

View file

@ -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));