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

feat(core): Node hints improvements (no-changelog) #9387

Merged
merged 5 commits into from
May 22, 2024
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
4 changes: 2 additions & 2 deletions packages/design-system/src/css/_tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@
// Callout
--color-callout-info-border: var(--color-foreground-base);
--color-callout-info-background: var(--color-foreground-xlight);
--color-callout-info-font: var(--color-info);
--color-callout-info-icon: var(--color-info);
--color-callout-info-font: var(--color-text-base);
--color-callout-info-icon: var(--color-text-light);
--color-callout-success-border: var(--color-success-light-2);
--color-callout-success-background: var(--color-success-tint-2);
--color-callout-success-font: var(--color-success);
Expand Down
40 changes: 31 additions & 9 deletions packages/editor-ui/src/components/RunData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,24 @@ export default defineComponent({
showIoSearchNoMatchContent(): boolean {
return this.hasNodeRun && !this.inputData.length && this.search;
},
parentNodeOutputData(): INodeExecutionData[] {
const workflow = this.workflowsStore.getCurrentWorkflow();

const parentNode = workflow.getParentNodesByDepth(this.node.name)[0];
let parentNodeData: INodeExecutionData[] = [];

if (parentNode?.name) {
parentNodeData = this.nodeHelpers.getNodeInputData(
workflow.getNode(parentNode?.name),
this.runIndex,
this.outputIndex,
'input',
this.connectionType,
);
}

return parentNodeData;
},
},
watch: {
node(newNode: INodeUi, prevNode: INodeUi) {
Expand Down Expand Up @@ -1104,19 +1122,18 @@ export default defineComponent({
},
shouldHintBeDisplayed(hint: NodeHint): boolean {
const { location, whenToDisplay } = hint;

if (location) {
if (location === 'ndv') {
return true;
if (location === 'ndv' && !['input', 'output'].includes(this.paneType)) {
return false;
}
if (location === 'inputPane' && this.paneType === 'input') {
return true;
if (location === 'inputPane' && this.paneType !== 'input') {
return false;
}

if (location === 'outputPane' && this.paneType === 'output') {
return true;
if (location === 'outputPane' && this.paneType !== 'output') {
return false;
}

return false;
}

if (whenToDisplay === 'afterExecution' && !this.hasNodeRun) {
Expand All @@ -1136,7 +1153,12 @@ export default defineComponent({

if (workflowNode) {
const executionHints = this.executionHints;
const nodeHints = NodeHelpers.getNodeHints(workflow, workflowNode, this.nodeType);
const nodeHints = NodeHelpers.getNodeHints(workflow, workflowNode, this.nodeType, {
runExecutionData: this.workflowExecution?.data ?? null,
runIndex: this.runIndex,
connectionInputData: this.parentNodeOutputData,
});

return executionHints.concat(nodeHints).filter(this.shouldHintBeDisplayed);
}
}
Expand Down
17 changes: 15 additions & 2 deletions packages/nodes-base/nodes/Postgres/v2/actions/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { NodeExecutionOutput, NodeOperationError } from 'n8n-workflow';

import { configurePostgres } from '../transport';
import { configureQueryRunner } from '../helpers/utils';
Expand All @@ -17,7 +17,8 @@ export async function router(this: IExecuteFunctions): Promise<INodeExecutionDat

const credentials = (await this.getCredentials('postgres')) as PostgresNodeCredentials;
const options = this.getNodeParameter('options', 0, {}) as PostgresNodeOptions;
options.nodeVersion = this.getNode().typeVersion;
const node = this.getNode();
options.nodeVersion = node.typeVersion;
options.operation = operation;

const { db, pgp, sshClient } = await configurePostgres(credentials, options);
Expand Down Expand Up @@ -62,5 +63,17 @@ export async function router(this: IExecuteFunctions): Promise<INodeExecutionDat
if (!db.$pool.ending) await db.$pool.end();
}

if (operation === 'select' && items.length > 1 && !node.executeOnce) {
return new NodeExecutionOutput(
[returnData],
[
{
message: `This node ran ${items.length} times, once for each input item. To run for the first item only, enable 'execute once' in the node settings`,
location: 'outputPane',
},
],
);
}

return [returnData];
}
42 changes: 33 additions & 9 deletions packages/nodes-base/nodes/Transform/SplitOut/SplitOut.node.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import get from 'lodash/get';
import unset from 'lodash/unset';
import {
type IBinaryData,
NodeOperationError,
deepCopy,
type IDataObject,
type IExecuteFunctions,
type INodeExecutionData,
type INodeType,
type INodeTypeDescription,
import { NodeOperationError, deepCopy, NodeExecutionOutput } from 'n8n-workflow';
import type {
IBinaryData,
IDataObject,
IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeDescription,
NodeExecutionHint,
} from 'n8n-workflow';
import { prepareFieldsArray } from '../utils/utils';

Expand Down Expand Up @@ -111,6 +111,7 @@ export class SplitOut implements INodeType {
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const returnData: INodeExecutionData[] = [];
const items = this.getInputData();
const notFoundedFields: { [key: string]: boolean[] } = {};

for (let i = 0; i < items.length; i++) {
const fieldsToSplitOut = (this.getNodeParameter('fieldToSplitOut', i) as string)
Expand Down Expand Up @@ -160,6 +161,14 @@ export class SplitOut implements INodeType {

if (entityToSplit === undefined) {
entityToSplit = [];
if (!notFoundedFields[fieldToSplitOut]) {
notFoundedFields[fieldToSplitOut] = [];
}
notFoundedFields[fieldToSplitOut].push(false);
} else {
if (notFoundedFields[fieldToSplitOut]) {
notFoundedFields[fieldToSplitOut].push(true);
}
}

if (typeof entityToSplit !== 'object' || entityToSplit === null) {
Expand Down Expand Up @@ -254,6 +263,21 @@ export class SplitOut implements INodeType {
}
}

if (Object.keys(notFoundedFields).length) {
const hints: NodeExecutionHint[] = [];

for (const [field, values] of Object.entries(notFoundedFields)) {
if (values.every((value) => !value)) {
hints.push({
message: `The field '${field}' wasn't found in any input item`,
location: 'outputPane',
});
}
}

if (hints.length) return new NodeExecutionOutput([returnData], hints);
}

return [returnData];
}
}
38 changes: 32 additions & 6 deletions packages/workflow/src/NodeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import type {
GenericValue,
DisplayCondition,
NodeHint,
INodeExecutionData,
} from './Interfaces';
import {
isFilterValue,
Expand Down Expand Up @@ -1125,19 +1126,44 @@ export function getNodeHints(
workflow: Workflow,
node: INode,
nodeTypeData: INodeTypeDescription,
nodeInputData?: {
runExecutionData: IRunExecutionData | null;
runIndex: number;
connectionInputData: INodeExecutionData[];
},
): NodeHint[] {
const hints: NodeHint[] = [];

if (nodeTypeData?.hints?.length) {
for (const hint of nodeTypeData.hints) {
if (hint.displayCondition) {
try {
const display = (workflow.expression.getSimpleParameterValue(
node,
hint.displayCondition,
'internal',
{},
) || false) as boolean;
let display;

if (nodeInputData === undefined) {
display = (workflow.expression.getSimpleParameterValue(
node,
hint.displayCondition,
'internal',
{},
) || false) as boolean;
} else {
const { runExecutionData, runIndex, connectionInputData } = nodeInputData;
display = workflow.expression.getParameterValue(
hint.displayCondition,
runExecutionData ?? null,
runIndex,
0,
node.name,
connectionInputData,
'manual',
{},
);
}

if (typeof display === 'string' && display.trim() === 'true') {
display = true;
}

if (typeof display !== 'boolean') {
console.warn(
Expand Down
Loading