mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
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:
parent
d1d1288ba9
commit
f24497589f
|
@ -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 { 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 { matchesNodeType, matchesSelectType } from './helpers';
|
||||||
import { BaseTextKey } from '@/plugins/i18n';
|
import { BaseTextKey } from '@/plugins/i18n';
|
||||||
|
import { intersection } from '@/utils';
|
||||||
import { sublimeSearch } from './sortUtils';
|
import { sublimeSearch } from './sortUtils';
|
||||||
|
|
||||||
export default mixins(externalHooks, globalLinkActions).extend({
|
export default mixins(externalHooks, globalLinkActions).extend({
|
||||||
|
@ -181,7 +182,10 @@ export default mixins(externalHooks, globalLinkActions).extend({
|
||||||
},
|
},
|
||||||
filteredNodeTypes(): INodeCreateElement[] {
|
filteredNodeTypes(): INodeCreateElement[] {
|
||||||
const filter = this.searchFilter;
|
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[] = [];
|
let returnItems: INodeCreateElement[] = [];
|
||||||
if (this.defaultLocale !== 'en') {
|
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(() => {
|
setTimeout(() => {
|
||||||
this.$externalHooks().run('nodeCreateList.filteredNodeTypesComputed', {
|
this.$externalHooks().run('nodeCreateList.filteredNodeTypesComputed', {
|
||||||
nodeFilter: this.nodeFilter,
|
nodeFilter: this.nodeFilter,
|
||||||
result: returnItems,
|
result: filteredNodeTypes,
|
||||||
selectedType: this.selectedType,
|
selectedType: this.selectedType,
|
||||||
});
|
});
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
return returnItems;
|
return filteredNodeTypes;
|
||||||
},
|
},
|
||||||
filteredAllNodeTypes(): INodeCreateElement[] {
|
filteredAllNodeTypes(): INodeCreateElement[] {
|
||||||
if(this.filteredNodeTypes.length > 0) return [];
|
if(this.filteredNodeTypes.length > 0) return [];
|
||||||
|
@ -334,6 +342,16 @@ export default mixins(externalHooks, globalLinkActions).extend({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
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() {
|
switchToAllTabAndFilter() {
|
||||||
const currentFilter = this.nodeFilter;
|
const currentFilter = this.nodeFilter;
|
||||||
this.$store.commit('nodeCreator/setShowTabs', true);
|
this.$store.commit('nodeCreator/setShowTabs', true);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
:initialActiveIndex="0"
|
:initialActiveIndex="0"
|
||||||
:searchItems="searchItems"
|
:searchItems="searchItems"
|
||||||
:firstLevelItems="isRoot ? items : []"
|
:firstLevelItems="isRoot ? items : []"
|
||||||
:excludedCategories="[CORE_NODES_CATEGORY]"
|
:excludedCategories="isRoot ? [] : [CORE_NODES_CATEGORY]"
|
||||||
:initialActiveCategories="[COMMUNICATION_CATEGORY]"
|
:initialActiveCategories="[COMMUNICATION_CATEGORY]"
|
||||||
>
|
>
|
||||||
<template #header>
|
<template #header>
|
||||||
|
@ -53,7 +53,7 @@ export default mixins(externalHooks).extend({
|
||||||
computed: {
|
computed: {
|
||||||
items() {
|
items() {
|
||||||
return [{
|
return [{
|
||||||
key: "core_nodes",
|
key: "*",
|
||||||
type: "subcategory",
|
type: "subcategory",
|
||||||
title: this.$locale.baseText('nodeCreator.subcategoryNames.appTriggerNodes'),
|
title: this.$locale.baseText('nodeCreator.subcategoryNames.appTriggerNodes'),
|
||||||
properties: {
|
properties: {
|
||||||
|
|
|
@ -56,3 +56,5 @@ export const isEmpty = (value?: unknown): boolean => {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const intersection = <T>(a: T[], b:T[]): T[] => a.filter(Set.prototype.has, new Set(b));
|
||||||
|
|
Loading…
Reference in a new issue