mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix: Helper to set proper operation for sendAndWait action (#16701)
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
|||||||
transformNodeType,
|
transformNodeType,
|
||||||
getRootSearchCallouts,
|
getRootSearchCallouts,
|
||||||
shouldShowCommunityNodeDetails,
|
shouldShowCommunityNodeDetails,
|
||||||
|
getHumanInTheLoopActions,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { useViewStacks } from '../composables/useViewStacks';
|
import { useViewStacks } from '../composables/useViewStacks';
|
||||||
import { useKeyboardNavigation } from '../composables/useKeyboardNavigation';
|
import { useKeyboardNavigation } from '../composables/useKeyboardNavigation';
|
||||||
@@ -40,7 +41,7 @@ import { useI18n } from '@n8n/i18n';
|
|||||||
import { getNodeIconSource } from '@/utils/nodeIcon';
|
import { getNodeIconSource } from '@/utils/nodeIcon';
|
||||||
|
|
||||||
import { useActions } from '../composables/useActions';
|
import { useActions } from '../composables/useActions';
|
||||||
import { SEND_AND_WAIT_OPERATION, type INodeParameters } from 'n8n-workflow';
|
import { type INodeParameters } from 'n8n-workflow';
|
||||||
|
|
||||||
import { isCommunityPackageName } from '@/utils/nodeTypesUtils';
|
import { isCommunityPackageName } from '@/utils/nodeTypesUtils';
|
||||||
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||||
@@ -102,10 +103,6 @@ function getFilteredActions(
|
|||||||
return nodeActions;
|
return nodeActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHumanInTheLoopActions(nodeActions: ActionTypeDescription[]) {
|
|
||||||
return nodeActions.filter((action) => action.actionKey === SEND_AND_WAIT_OPERATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSelected(item: INodeCreateElement) {
|
function onSelected(item: INodeCreateElement) {
|
||||||
if (item.type === 'subcategory') {
|
if (item.type === 'subcategory') {
|
||||||
const subcategoryKey = camelCase(item.properties.title);
|
const subcategoryKey = camelCase(item.properties.title);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
removeTrailingTrigger,
|
removeTrailingTrigger,
|
||||||
sortNodeCreateElements,
|
sortNodeCreateElements,
|
||||||
shouldShowCommunityNodeDetails,
|
shouldShowCommunityNodeDetails,
|
||||||
|
getHumanInTheLoopActions,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import {
|
import {
|
||||||
mockActionCreateElement,
|
mockActionCreateElement,
|
||||||
@@ -23,6 +24,8 @@ import { createTestingPinia } from '@pinia/testing';
|
|||||||
|
|
||||||
import { mock } from 'vitest-mock-extended';
|
import { mock } from 'vitest-mock-extended';
|
||||||
import type { ViewStack } from './composables/useViewStacks';
|
import type { ViewStack } from './composables/useViewStacks';
|
||||||
|
import { SEND_AND_WAIT_OPERATION } from 'n8n-workflow';
|
||||||
|
import { DISCORD_NODE_TYPE, MICROSOFT_TEAMS_NODE_TYPE } from '../../../constants';
|
||||||
|
|
||||||
vi.mock('@/stores/settings.store', () => ({
|
vi.mock('@/stores/settings.store', () => ({
|
||||||
useSettingsStore: vi.fn(() => ({ settings: {}, isAskAiEnabled: true })),
|
useSettingsStore: vi.fn(() => ({ settings: {}, isAskAiEnabled: true })),
|
||||||
@@ -379,4 +382,87 @@ describe('NodeCreator - utils', () => {
|
|||||||
expect(shouldShowCommunityNodeDetails(false, {})).toBe(false);
|
expect(shouldShowCommunityNodeDetails(false, {})).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getHumanInTheLoopActions', () => {
|
||||||
|
it('should return an empty array if no actions are passed in', () => {
|
||||||
|
const actions: ActionTypeDescription[] = [];
|
||||||
|
expect(getHumanInTheLoopActions(actions)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an empty array if no actions have the SEND_AND_WAIT_OPERATION actionKey', () => {
|
||||||
|
const actions: ActionTypeDescription[] = [
|
||||||
|
{
|
||||||
|
name: 'Test Action',
|
||||||
|
group: ['trigger'],
|
||||||
|
codex: {
|
||||||
|
label: 'Test Actions',
|
||||||
|
categories: ['Actions'],
|
||||||
|
},
|
||||||
|
iconUrl: 'icons/n8n-nodes-preview-test/dist/nodes/Test/test.svg',
|
||||||
|
outputs: ['main'],
|
||||||
|
defaults: {
|
||||||
|
name: 'TestAction',
|
||||||
|
},
|
||||||
|
actionKey: 'test',
|
||||||
|
description: 'Test action',
|
||||||
|
displayName: 'Test Action',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
expect(getHumanInTheLoopActions(actions)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the resource and operation for Discord actions', () => {
|
||||||
|
const actions: ActionTypeDescription[] = [
|
||||||
|
{
|
||||||
|
name: DISCORD_NODE_TYPE,
|
||||||
|
group: ['trigger'],
|
||||||
|
codex: {
|
||||||
|
label: 'Discord Actions',
|
||||||
|
categories: ['Actions'],
|
||||||
|
},
|
||||||
|
iconUrl: 'icons/n8n-nodes-preview-test/dist/nodes/Test/test.svg',
|
||||||
|
outputs: ['main'],
|
||||||
|
defaults: {
|
||||||
|
name: 'DiscordAction',
|
||||||
|
},
|
||||||
|
actionKey: SEND_AND_WAIT_OPERATION,
|
||||||
|
description: 'Discord action',
|
||||||
|
displayName: 'Discord Action',
|
||||||
|
values: {},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const result = getHumanInTheLoopActions(actions);
|
||||||
|
expect(result[0].values).toEqual({
|
||||||
|
resource: 'message',
|
||||||
|
operation: SEND_AND_WAIT_OPERATION,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the resource and operation for Microsoft Teams actions', () => {
|
||||||
|
const actions: ActionTypeDescription[] = [
|
||||||
|
{
|
||||||
|
name: MICROSOFT_TEAMS_NODE_TYPE,
|
||||||
|
group: ['trigger'],
|
||||||
|
codex: {
|
||||||
|
label: 'Microsoft Teams Actions',
|
||||||
|
categories: ['Actions'],
|
||||||
|
},
|
||||||
|
iconUrl: 'icons/n8n-nodes-preview-test/dist/nodes/Test/test.svg',
|
||||||
|
outputs: ['main'],
|
||||||
|
defaults: {
|
||||||
|
name: 'MicrosoftTeamsAction',
|
||||||
|
},
|
||||||
|
actionKey: SEND_AND_WAIT_OPERATION,
|
||||||
|
description: 'Microsoft Teams action',
|
||||||
|
displayName: 'Microsoft Teams Action',
|
||||||
|
values: {},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const result = getHumanInTheLoopActions(actions);
|
||||||
|
expect(result[0].values).toEqual({
|
||||||
|
resource: 'chatMessage',
|
||||||
|
operation: SEND_AND_WAIT_OPERATION,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import {
|
|||||||
AI_TRANSFORM_NODE_TYPE,
|
AI_TRANSFORM_NODE_TYPE,
|
||||||
CORE_NODES_CATEGORY,
|
CORE_NODES_CATEGORY,
|
||||||
DEFAULT_SUBCATEGORY,
|
DEFAULT_SUBCATEGORY,
|
||||||
|
DISCORD_NODE_TYPE,
|
||||||
HUMAN_IN_THE_LOOP_CATEGORY,
|
HUMAN_IN_THE_LOOP_CATEGORY,
|
||||||
|
MICROSOFT_TEAMS_NODE_TYPE,
|
||||||
} from '@/constants';
|
} from '@/constants';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
@@ -336,3 +338,27 @@ export const shouldShowCommunityNodeDetails = (communityNode: boolean, viewStack
|
|||||||
|
|
||||||
return communityNode && !viewStack.communityNodeDetails;
|
return communityNode && !viewStack.communityNodeDetails;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function getHumanInTheLoopActions(nodeActions: ActionTypeDescription[]) {
|
||||||
|
const actions = nodeActions.filter((action) => action.actionKey === SEND_AND_WAIT_OPERATION);
|
||||||
|
|
||||||
|
if (actions.length) {
|
||||||
|
const name = actions[0].name;
|
||||||
|
if (name === DISCORD_NODE_TYPE) {
|
||||||
|
actions[0].values = {
|
||||||
|
...actions[0].values,
|
||||||
|
resource: 'message',
|
||||||
|
operation: SEND_AND_WAIT_OPERATION,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (name === MICROSOFT_TEAMS_NODE_TYPE) {
|
||||||
|
actions[0].values = {
|
||||||
|
...actions[0].values,
|
||||||
|
resource: 'chatMessage',
|
||||||
|
operation: SEND_AND_WAIT_OPERATION,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user