Skip to content

Commit

Permalink
feat(Filter Node): Show discarded items
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Mar 31, 2023
1 parent 11692c5 commit f7f9d91
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 8 additions & 3 deletions packages/editor-ui/src/components/RunData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ import {
import {
DATA_PINNING_DOCS_URL,
DATA_EDITING_DOCS_URL,
NODE_TYPES_EXCLUDED_FROM_OUTPUT_NAME_APPEND,
LOCAL_STORAGE_PIN_DATA_DISCOVERY_NDV_FLAG,
LOCAL_STORAGE_PIN_DATA_DISCOVERY_CANVAS_FLAG,
MAX_DISPLAY_DATA_SIZE,
Expand Down Expand Up @@ -834,6 +835,7 @@ export default mixins(externalHooks, genericHelpers, nodeHelpers, pinData).exten
return name.charAt(0).toLocaleUpperCase() + name.slice(1);
}
const branches: ITab[] = [];
for (let i = 0; i <= this.maxOutputIndex; i++) {
if (this.overrideOutputs && !this.overrideOutputs.includes(i)) {
continue;
Expand All @@ -844,9 +846,12 @@ export default mixins(externalHooks, genericHelpers, nodeHelpers, pinData).exten
if (`${outputName}` === `${i}`) {
outputName = `${this.$locale.baseText('ndv.output')} ${outputName}`;
} else {
outputName = capitalize(
`${this.getOutputName(i)} ${this.$locale.baseText('ndv.output.branch')}`,
);
const appendBranchWord = NODE_TYPES_EXCLUDED_FROM_OUTPUT_NAME_APPEND.includes(
this.node?.type,
)
? ''
: ` ${this.$locale.baseText('ndv.output.branch')}`;
outputName = capitalize(`${this.getOutputName(i)}${appendBranchWord}`);
}
branches.push({
label: itemsCount ? `${outputName} (${itemsCount} ${items})` : outputName,
Expand Down
3 changes: 3 additions & 0 deletions packages/editor-ui/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const CALENDLY_TRIGGER_NODE_TYPE = 'n8n-nodes-base.calendlyTrigger';
export const CODE_NODE_TYPE = 'n8n-nodes-base.code';
export const CRON_NODE_TYPE = 'n8n-nodes-base.cron';
export const CLEARBIT_NODE_TYPE = 'n8n-nodes-base.clearbit';
export const FILTER_NODE_TYPE = 'n8n-nodes-base.filter';
export const FUNCTION_NODE_TYPE = 'n8n-nodes-base.function';
export const GITHUB_TRIGGER_NODE_TYPE = 'n8n-nodes-base.githubTrigger';
export const GIT_NODE_TYPE = 'n8n-nodes-base.git';
Expand Down Expand Up @@ -540,3 +541,5 @@ export const ONBOARDING_EXPERIMENT = {
};

export const EXPERIMENTS_TO_TRACK = [ASSUMPTION_EXPERIMENT.name, ONBOARDING_EXPERIMENT.name];

export const NODE_TYPES_EXCLUDED_FROM_OUTPUT_NAME_APPEND = [FILTER_NODE_TYPE];
16 changes: 12 additions & 4 deletions packages/nodes-base/nodes/Filter/Filter.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class Filter implements INodeType {
},
inputs: ['main'],
outputs: ['main'],
outputNames: ['Kept', 'Discarded'],
properties: [
{
displayName: 'Conditions',
Expand Down Expand Up @@ -305,7 +306,8 @@ export class Filter implements INodeType {
};

async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const returnData: INodeExecutionData[] = [];
const returnDataTrue: INodeExecutionData[] = [];
const returnDataFalse: INodeExecutionData[] = [];

const items = this.getInputData();

Expand Down Expand Up @@ -340,21 +342,27 @@ export class Filter implements INodeType {

// If the operation is "OR" it means the item did match one condition no ned to check further
if (compareResult && combineConditions === 'OR') {
returnData.push(item);
returnDataTrue.push(item);
continue itemLoop;
}

// If the operation is "AND" it means the item failed one condition no ned to check further
if (!compareResult && combineConditions === 'AND') {
returnDataFalse.push(item);
continue itemLoop;
}
}
}

// If the operation is "AND" it means the item did match all conditions
if (combineConditions === 'AND') returnData.push(item);
if (combineConditions === 'AND') {
returnDataTrue.push(item);
} else {
// If the operation is "OR" it means the the item did not match any condition.
returnDataFalse.push(item);
}
}

return [returnData];
return [returnDataTrue, returnDataFalse];
}
}

0 comments on commit f7f9d91

Please sign in to comment.