feat(editor): Add isEmpty on DateTime, add is empty to all types in filter component (#9645)

This commit is contained in:
Elias Meire
2024-06-07 13:25:22 +02:00
committed by GitHub
parent 44ecab73d7
commit eccc637b63
7 changed files with 206 additions and 4 deletions

View File

@@ -352,7 +352,7 @@ compact.doc = {
isEmpty.doc = {
name: 'isEmpty',
description: 'Returns <code>true</code> if the array has no elements',
description: 'Returns <code>true</code> if the array has no elements or is <code>null</code>',
examples: [
{ example: '[].isEmpty()', evaluated: 'true' },
{ example: "['quick', 'brown', 'fox'].isEmpty()", evaluated: 'false' },

View File

@@ -278,6 +278,15 @@ function toBoolean() {
return undefined;
}
// Only null/undefined return true, this is handled in ExpressionExtension.ts
function isEmpty(): boolean {
return false;
}
function isNotEmpty(): boolean {
return true;
}
endOfMonth.doc = {
name: 'endOfMonth',
returnType: 'DateTime',
@@ -547,7 +556,7 @@ diffToNow.doc = {
evaluated: '371.9',
},
{
example: "dt = '2023-03-30T18:49:07.234.toDateTime()\ndt.diffToNow(['months', 'days'])",
example: "dt = '2023-03-30T18:49:07.234'.toDateTime()\ndt.diffToNow(['months', 'days'])",
evaluated: '{ months: 12, days: 5.9 }',
},
],
@@ -565,6 +574,30 @@ diffToNow.doc = {
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/dates/#date-diffToNow',
};
isEmpty.doc = {
name: 'isEmpty',
description:
'Returns <code>false</code> for all DateTimes. Returns <code>true</code> for <code>null</code>.',
examples: [
{ example: "dt = '2023-03-30T18:49:07.234'.toDateTime()\ndt.isEmpty()", evaluated: 'false' },
{ example: 'dt = null\ndt.isEmpty()', evaluated: 'true' },
],
returnType: 'boolean',
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-isEmpty',
};
isNotEmpty.doc = {
name: 'isNotEmpty',
description:
'Returns <code>true</code> for all DateTimes. Returns <code>false</code> for <code>null</code>.',
examples: [
{ example: "dt = '2023-03-30T18:49:07.234'.toDateTime()\ndt.isNotEmpty()", evaluated: 'true' },
{ example: 'dt = null\ndt.isNotEmpty()', evaluated: 'false' },
],
returnType: 'boolean',
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-isNotEmpty',
};
export const dateExtensions: ExtensionMap = {
typeName: 'Date',
functions: {
@@ -584,5 +617,7 @@ export const dateExtensions: ExtensionMap = {
toInt,
toFloat,
toBoolean,
isEmpty,
isNotEmpty,
},
};

View File

@@ -110,7 +110,8 @@ export function toDateTime() {
isEmpty.doc = {
name: 'isEmpty',
description: 'Returns <code>true</code> if the Object has no keys (fields) set',
description:
'Returns <code>true</code> if the Object has no keys (fields) set or is <code>null</code>',
examples: [
{ example: "({'name': 'Nathan'}).isEmpty()", evaluated: 'false' },
{ example: '({}).isEmpty()', evaluated: 'true' },

View File

@@ -676,7 +676,7 @@ isUrl.doc = {
isEmpty.doc = {
name: 'isEmpty',
description: 'Returns <code>true</code> if the string has no characters.',
description: 'Returns <code>true</code> if the string has no characters or is <code>null</code>',
section: 'validation',
returnType: 'boolean',
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/strings/#string-isEmpty',