From 0034a17b17d8975b12d3b3511693affdc05ced31 Mon Sep 17 00:00:00 2001 From: quansenB Date: Fri, 25 Oct 2019 16:15:01 +0200 Subject: [PATCH] revert to addition fields design choice --- .../ActiveCampaign/ActiveCampaign.node.ts | 313 ++++++------------ 1 file changed, 103 insertions(+), 210 deletions(-) diff --git a/packages/nodes-base/nodes/ActiveCampaign/ActiveCampaign.node.ts b/packages/nodes-base/nodes/ActiveCampaign/ActiveCampaign.node.ts index b9d28cf884..0af2409e16 100644 --- a/packages/nodes-base/nodes/ActiveCampaign/ActiveCampaign.node.ts +++ b/packages/nodes-base/nodes/ActiveCampaign/ActiveCampaign.node.ts @@ -528,23 +528,6 @@ export class ActiveCampaign implements INodeType { }, description: 'The title of the deal', }, - { - displayName: 'Description', - name: 'dealDescription', - type: 'string', - default: '', - displayOptions: { - show: { - operation: [ - 'create', - ], - resource: [ - 'deal', - ], - }, - }, - description: 'The description of the deal', - }, { displayName: 'Deal\'s contact ID', name: 'dealContactId', @@ -600,10 +583,10 @@ export class ActiveCampaign implements INodeType { description: 'The currency of the deal in 3-character ISO format', }, { - displayName: 'Deal group ID', - name: 'dealGroup', - type: 'string', - default: '', + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', displayOptions: { show: { operation: [ @@ -614,75 +597,51 @@ export class ActiveCampaign implements INodeType { ], }, }, - description: 'The group ID of the deal', - }, - { - displayName: 'Deal stage ID', - name: 'dealStage', - type: 'string', - default: '', - displayOptions: { - show: { - operation: [ - 'create', - ], - resource: [ - 'deal', - ], + default: {}, + options: [ + { + displayName: 'Description', + name: 'dealDescription', + type: 'string', + default: '', + description: 'The description of the deal', }, - }, - description: 'The stage ID of the deal', - }, - { - displayName: 'Deal owner ID', - name: 'dealOwner', - type: 'string', - default: '', - displayOptions: { - show: { - operation: [ - 'create', - ], - resource: [ - 'deal', - ], + { + displayName: 'Deal group ID', + name: 'dealGroup', + type: 'string', + default: '', + description: 'The group ID of the deal', }, - }, - description: 'The owner ID of the deal', - }, - { - displayName: 'Deal percentage', - name: 'dealPercentage', - type: 'number', - default: 0, - displayOptions: { - show: { - operation: [ - 'create', - ], - resource: [ - 'deal', - ], + { + displayName: 'Deal stage ID', + name: 'dealStage', + type: 'string', + default: '', + description: 'The stage ID of the deal', }, - }, - description: 'The percentage of the deal', - }, - { - displayName: 'Deal status', - name: 'dealStatus', - type: 'number', - default: 0, - displayOptions: { - show: { - operation: [ - 'create', - ], - resource: [ - 'deal', - ], + { + displayName: 'Deal owner ID', + name: 'dealOwner', + type: 'string', + default: '', + description: 'The owner ID of the deal', }, - }, - description: 'The status of the deal', + { + displayName: 'Deal percentage', + name: 'dealPercentage', + type: 'number', + default: 0, + description: 'The percentage of the deal', + }, + { + displayName: 'Deal status', + name: 'dealStatus', + type: 'number', + default: 0, + description: 'The status of the deal', + }, + ] }, // ---------------------------------- @@ -715,7 +674,7 @@ export class ActiveCampaign implements INodeType { displayOptions: { show: { operation: [ - 'update', + 'create', ], resource: [ 'deal', @@ -724,32 +683,16 @@ export class ActiveCampaign implements INodeType { }, description: 'The title of the deal', }, - { - displayName: 'Description', - name: 'dealDescription', - type: 'string', - default: '', - displayOptions: { - show: { - operation: [ - 'update', - ], - resource: [ - 'deal', - ], - }, - }, - description: 'The description of the deal', - }, { displayName: 'Deal\'s contact ID', name: 'dealContactId', type: 'number', default: 0, + required: true, displayOptions: { show: { operation: [ - 'update', + 'create', ], resource: [ 'deal', @@ -763,10 +706,11 @@ export class ActiveCampaign implements INodeType { name: 'dealValue', type: 'number', default: 0, + required: true, displayOptions: { show: { operation: [ - 'update', + 'create', ], resource: [ 'deal', @@ -780,10 +724,11 @@ export class ActiveCampaign implements INodeType { name: 'dealCurrency', type: 'string', default: '', + required: true, displayOptions: { show: { operation: [ - 'update', + 'create', ], resource: [ 'deal', @@ -793,89 +738,65 @@ export class ActiveCampaign implements INodeType { description: 'The currency of the deal in 3-character ISO format', }, { - displayName: 'Deal group ID', - name: 'dealGroup', - type: 'string', - default: '', + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', displayOptions: { show: { operation: [ - 'update', + 'create', ], resource: [ 'deal', ], }, }, - description: 'The group ID of the deal', - }, - { - displayName: 'Deal stage ID', - name: 'dealStage', - type: 'string', - default: '', - displayOptions: { - show: { - operation: [ - 'update', - ], - resource: [ - 'deal', - ], + default: {}, + options: [ + { + displayName: 'Description', + name: 'dealDescription', + type: 'string', + default: '', + description: 'The description of the deal', }, - }, - description: 'The stage ID of the deal', - }, - { - displayName: 'Deal owner ID', - name: 'dealOwner', - type: 'string', - default: '', - displayOptions: { - show: { - operation: [ - 'update', - ], - resource: [ - 'deal', - ], + { + displayName: 'Deal group ID', + name: 'dealGroup', + type: 'string', + default: '', + description: 'The group ID of the deal', }, - }, - description: 'The owner ID of the deal', - }, - { - displayName: 'Deal percentage', - name: 'dealPercentage', - type: 'number', - default: 0, - displayOptions: { - show: { - operation: [ - 'update', - ], - resource: [ - 'deal', - ], + { + displayName: 'Deal stage ID', + name: 'dealStage', + type: 'string', + default: '', + description: 'The stage ID of the deal', }, - }, - description: 'The percentage of the deal', - }, - { - displayName: 'Deal status', - name: 'dealStatus', - type: 'number', - default: 0, - displayOptions: { - show: { - operation: [ - 'update', - ], - resource: [ - 'deal', - ], + { + displayName: 'Deal owner ID', + name: 'dealOwner', + type: 'string', + default: '', + description: 'The owner ID of the deal', }, - }, - description: 'The status of the deal', + { + displayName: 'Deal percentage', + name: 'dealPercentage', + type: 'number', + default: 0, + description: 'The percentage of the deal', + }, + { + displayName: 'Deal status', + name: 'dealStatus', + type: 'number', + default: 0, + description: 'The status of the deal', + }, + ] }, @@ -1159,46 +1080,18 @@ export class ActiveCampaign implements INodeType { requestMethod = 'POST'; dataKey = 'deal'; - + body.deal = { title: this.getNodeParameter('dealTitle', i) as string, contact: this.getNodeParameter('dealContactId', i) as string, value: this.getNodeParameter('dealValue', i) as number, - currency: '', } as IDataObject; - let currency= this.getNodeParameter('dealCurrency', i) as string - if (currency.length === 3) { - currency = currency.toLowerCase(); - addAdditionalField(body.deal as IDataObject, currency) - } else { - throw new Error('Currency must be in 3-character ISO format') - } + let currency = this.getNodeParameter('dealCurrency', i).toString().toLowerCase() as string + addAdditionalField(body.deal as IDataObject, currency) - let description = this.getNodeParameter('dealDescription', i) as string; - if (description.length !== 0){ - addAdditionalField(body.deal as IDataObject, description) - } - - let group = this.getNodeParameter('dealGroup', i) as string; - if (group.length !== 0){ - addAdditionalField(body.deal as IDataObject, group) - } - - let stage = this.getNodeParameter('dealStage', i) as string; - if (stage.length !== 0){ - addAdditionalField(body.deal as IDataObject, stage) - } - - let percentage = this.getNodeParameter('dealPercentage', i) as number; - if (percentage !== 0){ - addAdditionalField(body.deal as IDataObject, percentage) - } - - let status = this.getNodeParameter('dealStatus', i) as number; - if (status !== 0){ - addAdditionalField(body.deal as IDataObject, status) - } + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + addAdditionalFields(body.deal as IDataObject, additionalFields); } else if (operation === 'delete') {