mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat(Notion Node): Allow to ignore Notion URL properties if empty (#3564)
* Allows to ignore Notion URL properties if empty * Fixes linting * Fixes another linting error that was not caught locally * Reorders options alphabetically
This commit is contained in:
parent
577c73ee25
commit
6cb9aefb0b
|
@ -319,6 +319,19 @@ export const databasePageFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Email address',
|
description: 'Email address',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Ignore If Empty',
|
||||||
|
name: 'ignoreIfEmpty',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
type: [
|
||||||
|
'url',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'URL',
|
displayName: 'URL',
|
||||||
name: 'urlValue',
|
name: 'urlValue',
|
||||||
|
@ -732,6 +745,19 @@ export const databasePageFields = [
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Ignore If Empty',
|
||||||
|
name: 'ignoreIfEmpty',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
type: [
|
||||||
|
'url',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'URL',
|
displayName: 'URL',
|
||||||
name: 'urlValue',
|
name: 'urlValue',
|
||||||
|
|
|
@ -239,7 +239,9 @@ export function formatBlocks(blocks: IDataObject[]) {
|
||||||
|
|
||||||
// tslint:disable-next-line: no-any
|
// tslint:disable-next-line: no-any
|
||||||
function getPropertyKeyValue(value: any, type: string, timezone: string, version = 1) {
|
function getPropertyKeyValue(value: any, type: string, timezone: string, version = 1) {
|
||||||
|
const ignoreIfEmpty = <T>(v: T, cb: (v: T) => any) => !v && value.ignoreIfEmpty ? undefined : cb(v); // tslint:disable-line: no-any
|
||||||
let result = {};
|
let result = {};
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'rich_text':
|
case 'rich_text':
|
||||||
if (value.richText === false) {
|
if (value.richText === false) {
|
||||||
|
@ -255,7 +257,7 @@ function getPropertyKeyValue(value: any, type: string, timezone: string, version
|
||||||
result = { type: 'number', number: value.numberValue };
|
result = { type: 'number', number: value.numberValue };
|
||||||
break;
|
break;
|
||||||
case 'url':
|
case 'url':
|
||||||
result = { type: 'url', url: value.urlValue };
|
result = ignoreIfEmpty(value.urlValue, url => ({ type: 'url', url }));
|
||||||
break;
|
break;
|
||||||
case 'checkbox':
|
case 'checkbox':
|
||||||
result = { type: 'checkbox', checkbox: value.checkboxValue };
|
result = { type: 'checkbox', checkbox: value.checkboxValue };
|
||||||
|
@ -361,9 +363,13 @@ function getNameAndType(key: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapProperties(properties: IDataObject[], timezone: string, version = 1) {
|
export function mapProperties(properties: IDataObject[], timezone: string, version = 1) {
|
||||||
return properties.reduce((obj, value) => Object.assign(obj, {
|
return properties
|
||||||
[`${(value.key as string).split('|')[0]}`]: getPropertyKeyValue(value, (value.key as string).split('|')[1], timezone, version),
|
.filter((property): property is Record<string, { key: string; [k: string]: any }> => typeof property.key === 'string') // tslint:disable-line: no-any
|
||||||
}), {});
|
.map(property => [`${property.key.split('|')[0]}`, getPropertyKeyValue(property, property.key.split('|')[1], timezone, version)] as const)
|
||||||
|
.filter(([, value]) => value)
|
||||||
|
.reduce((obj, [key, value]) => Object.assign(obj, {
|
||||||
|
[key]: value,
|
||||||
|
}), {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapSorting(data: [{ key: string, type: string, direction: string, timestamp: boolean }]) {
|
export function mapSorting(data: [{ key: string, type: string, direction: string, timestamp: boolean }]) {
|
||||||
|
@ -425,7 +431,7 @@ function simplifyProperty(property: any) {
|
||||||
result = property.plain_text;
|
result = property.plain_text;
|
||||||
} else if (['rich_text', 'title'].includes(property.type)) {
|
} else if (['rich_text', 'title'].includes(property.type)) {
|
||||||
if (Array.isArray(property[type]) && property[type].length !== 0) {
|
if (Array.isArray(property[type]) && property[type].length !== 0) {
|
||||||
// tslint:disable-next-line: no-any
|
// tslint:disable-next-line: no-any
|
||||||
result = property[type].map((text: any) => simplifyProperty(text) as string).join('');
|
result = property[type].map((text: any) => simplifyProperty(text) as string).join('');
|
||||||
} else {
|
} else {
|
||||||
result = '';
|
result = '';
|
||||||
|
|
Loading…
Reference in a new issue