Add the posiblity to set multi-select fields with the names (#1892)

*  Add the posiblity to set multi-select fields with the names

* 🐛 Fix issue with expressions

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ricardo Espinoza 2021-06-13 13:17:39 -04:00 committed by GitHub
parent 68914a1fcf
commit 233fc72dc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 30 additions and 13 deletions

View file

@ -11,7 +11,7 @@ import {
NodeApiError, NodeApiError,
} from 'n8n-workflow'; } from 'n8n-workflow';
import * as uuid from 'uuid/v4'; import { v4 as uuid } from 'uuid';
import { import {
snakeCase, snakeCase,

View file

@ -22,7 +22,7 @@ import {
recordOperations, recordOperations,
} from './RecordDescription'; } from './RecordDescription';
import * as uuid from 'uuid'; import { v4 as uuid } from 'uuid';
export class GoogleBigQuery implements INodeType { export class GoogleBigQuery implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {

View file

@ -34,7 +34,7 @@ import {
import * as moment from 'moment-timezone'; import * as moment from 'moment-timezone';
import * as uuid from 'uuid/v4'; import { v4 as uuid } from 'uuid';
export class GoogleCalendar implements INodeType { export class GoogleCalendar implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {

View file

@ -16,7 +16,7 @@ import {
googleApiRequestAllItems, googleApiRequestAllItems,
} from './GenericFunctions'; } from './GenericFunctions';
import uuid = require('uuid'); import { v4 as uuid } from 'uuid';
export class GoogleDrive implements INodeType { export class GoogleDrive implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {

View file

@ -12,7 +12,7 @@ import {
} from 'n8n-core'; } from 'n8n-core';
import * as _ from 'lodash'; import * as _ from 'lodash';
import * as uuid from 'uuid/v4'; import { v4 as uuid } from 'uuid';
interface MessageResponse { interface MessageResponse {

View file

@ -24,6 +24,8 @@ import {
import * as moment from 'moment-timezone'; import * as moment from 'moment-timezone';
import { validate as uuidValidate } from 'uuid';
export async function notionApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IPollFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any export async function notionApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IPollFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
try { try {
@ -244,9 +246,15 @@ function getPropertyKeyValue(value: any, type: string, timezone: string) {
}; };
break; break;
case 'multi_select': case 'multi_select':
const multiSelectValue = value.multiSelectValue;
result = { result = {
type: 'multi_select',
// tslint:disable-next-line: no-any // tslint:disable-next-line: no-any
type: 'multi_select', multi_select: value.multiSelectValue.filter((id: any) => id !== null).map((option: string) => ({ id: option })), multi_select: (Array.isArray(multiSelectValue) ? multiSelectValue : multiSelectValue.split(',').map(v => v.trim()))
// tslint:disable-next-line: no-any
.filter((value: any) => value !== null)
.map((option: string) =>
((!uuidValidate(option)) ? { name: option } : { id: option })),
}; };
break; break;
case 'email': case 'email':

View file

@ -47,6 +47,7 @@ import {
databasePageFields, databasePageFields,
databasePageOperations, databasePageOperations,
} from './DatabasePageDescription'; } from './DatabasePageDescription';
import { getServers } from 'dns';
export class Notion implements INodeType { export class Notion implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
@ -215,8 +216,16 @@ export class Notion implements INodeType {
const resource = this.getCurrentNodeParameter('resource') as string; const resource = this.getCurrentNodeParameter('resource') as string;
const operation = this.getCurrentNodeParameter('operation') as string; const operation = this.getCurrentNodeParameter('operation') as string;
const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`); const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`);
const useNames = (resource === 'databasePage' && operation === 'getAll'); if (resource === 'databasePage') {
return (properties[name][type].options).map((option: IDataObject) => ({ name: option.name, value: (['select', 'multi_select'].includes(type) && useNames) ? option.name : option.id })); if (['multi_select', 'select'].includes(type) && operation === 'getAll') {
return (properties[name][type].options)
.map((option: IDataObject) => ({ name: option.name, value: option.name }));
} else if (['multi_select'].includes(type) && ['create', 'update'].includes(operation)) {
return (properties[name][type].options)
.map((option: IDataObject) => ({ name: option.name, value: option.name }));
}
}
return (properties[name][type].options).map((option: IDataObject) => ({ name: option.name, value: option.id }));
}, },
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> { async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];

View file

@ -37,7 +37,7 @@ import {
ITrack, ITrack,
} from './TrackInterface'; } from './TrackInterface';
import * as uuid from 'uuid/v4'; import { v4 as uuid } from 'uuid';
export class Segment implements INodeType { export class Segment implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {

View file

@ -37,7 +37,7 @@ import {
commentFields, commentFields,
commentOperations commentOperations
} from './CommentDescription'; } from './CommentDescription';
import uuid = require('uuid'); import { v4 as uuid } from 'uuid';
import * as moment from 'moment'; import * as moment from 'moment';
export class Twist implements INodeType { export class Twist implements INodeType {

View file

@ -41,7 +41,7 @@ import {
import * as moment from 'moment-timezone'; import * as moment from 'moment-timezone';
import * as uuid from 'uuid/v4'; import { v4 as uuid } from 'uuid';
export class Wise implements INodeType { export class Wise implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {

View file

@ -599,7 +599,7 @@
"@types/request-promise-native": "~1.0.15", "@types/request-promise-native": "~1.0.15",
"@types/ssh2-sftp-client": "^5.1.0", "@types/ssh2-sftp-client": "^5.1.0",
"@types/tmp": "^0.2.0", "@types/tmp": "^0.2.0",
"@types/uuid": "^3.4.6", "@types/uuid": "^8.3.0",
"@types/xml2js": "^0.4.3", "@types/xml2js": "^0.4.3",
"gulp": "^4.0.0", "gulp": "^4.0.0",
"jest": "^26.4.2", "jest": "^26.4.2",
@ -656,7 +656,7 @@
"snowflake-sdk": "^1.5.3", "snowflake-sdk": "^1.5.3",
"ssh2-sftp-client": "^5.2.1", "ssh2-sftp-client": "^5.2.1",
"tmp-promise": "^3.0.2", "tmp-promise": "^3.0.2",
"uuid": "^3.4.0", "uuid": "^8.3.0",
"vm2": "^3.6.10", "vm2": "^3.6.10",
"xlsx": "^0.17.0", "xlsx": "^0.17.0",
"xml2js": "^0.4.23" "xml2js": "^0.4.23"