Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Fix opening of node creator for sub-nodes connection hint link #8809

Merged
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
20 changes: 20 additions & 0 deletions cypress/e2e/5-ndv.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,24 @@ describe('NDV', () => {
ndv.actions.changeNodeOperation('Update Row');
ndv.getters.resourceLocatorInput('documentId').find('input').should('have.value', TEST_DOC_ID);
});

it('Should open appropriate node creator after clicking on connection hint link', () => {
const nodeCreator = new NodeCreator();
const hintMapper = {
'Memory': 'AI Nodes',
'Output Parser': 'AI Nodes',
'Token Splitter': 'Document Loaders',
'Tool': 'AI Nodes',
'Embeddings': 'Vector Stores',
'Vector Store': 'Retrievers'
}
cy.createFixtureWorkflow('open_node_creator_for_connection.json', `open_node_creator_for_connection ${uuid()}`);

Object.entries(hintMapper).forEach(([node, group]) => {
workflowPage.actions.openNode(node);
cy.get('[data-action=openSelectiveNodeCreator]').contains('Insert one').click();
nodeCreator.getters.activeSubcategory().should('contain', group);
cy.realPress('Escape');
});
})
});
110 changes: 110 additions & 0 deletions cypress/fixtures/open_node_creator_for_connection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"name": "open_node_creator_for_connection",
"nodes": [
{
"parameters": {},
"id": "25ff0c17-7064-4e14-aec6-45c71d63201b",
"name": "When clicking \"Test workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
740,
520
]
},
{
"parameters": {},
"id": "49f376ca-845b-4737-aac0-073d0e4fa95c",
"name": "Token Splitter",
"type": "@n8n/n8n-nodes-langchain.textSplitterTokenSplitter",
"typeVersion": 1,
"position": [
1180,
540
]
},
{
"parameters": {},
"id": "d1db5111-4b01-4620-8ccb-a16ea576c363",
"name": "Memory",
"type": "@n8n/n8n-nodes-langchain.memoryXata",
"typeVersion": 1.2,
"position": [
940,
540
],
"credentials": {
"xataApi": {
"id": "q1ckaYlHTWCYDtF0",
"name": "Xata Api account"
}
}
},
{
"parameters": {},
"id": "b08b6d3a-bef8-42ac-9cef-ec9d4e5402b1",
"name": "Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"typeVersion": 1.1,
"position": [
1060,
540
]
},
{
"parameters": {},
"id": "ee557938-9cf1-4b78-afef-c783c52fd307",
"name": "Tool",
"type": "@n8n/n8n-nodes-langchain.toolWikipedia",
"typeVersion": 1,
"position": [
1300,
540
]
},
{
"parameters": {
"options": {}
},
"id": "814f2e9c-cc7b-4f3c-89b4-d6eb82bc24df",
"name": "Embeddings",
"type": "@n8n/n8n-nodes-langchain.embeddingsHuggingFaceInference",
"typeVersion": 1,
"position": [
1420,
540
]
},
{
"parameters": {
"tableName": {
"__rl": true,
"mode": "list",
"value": ""
},
"options": {}
},
"id": "e8569b0b-a580-4249-9c5e-f1feed5c644e",
"name": "Vector Store",
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
"typeVersion": 1,
"position": [
1540,
540
]
}
],
"pinData": {},
"connections": {},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "8e90604c-f7e9-489d-8e43-1cc699b7db04",
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4"
},
"id": "L3tgfoW660UOSuX6",
"tags": []
}
14 changes: 12 additions & 2 deletions packages/@n8n/nodes-langchain/utils/sharedFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ function determineArticle(nextWord: string): string {
const vowels = /^[aeiouAEIOU]/;
return vowels.test(nextWord) ? 'an' : 'a';
}
const getConnectionParameterString = (connectionType: string) => {
if (connectionType === '') return "data-action-parameter-creatorview='AI'";

return `data-action-parameter-connectiontype='${connectionType}'`;
};
const getAhref = (connectionType: { connection: string; locale: string }) =>
`<a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='${connectionType.connection}'>${connectionType.locale}</a>`;
`<a class="test" data-action='openSelectiveNodeCreator'${getConnectionParameterString(
connectionType.connection,
)}'>${connectionType.locale}</a>`;

export function getConnectionHintNoticeField(
connectionTypes: AllowedConnectionTypes[],
Expand All @@ -105,12 +112,15 @@ export function getConnectionHintNoticeField(

if (groupedConnections.size === 1) {
const [[connection, locales]] = Array.from(groupedConnections);

displayName = `This node must be connected to ${determineArticle(locales[0])} ${locales[0]
.toLowerCase()
.replace(
/^ai /,
'AI ',
)}. <a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='${connection}'>Insert one</a>`;
)}. <a data-action='openSelectiveNodeCreator' ${getConnectionParameterString(
connection,
)}>Insert one</a>`;
} else {
const ahrefs = Array.from(groupedConnections, ([connection, locales]) => {
// If there are multiple locales, join them with ' or '
Expand Down
Loading