feat(n8n Form Node): Limit wait time parameters (#13160)

This commit is contained in:
Michael Kret
2025-02-19 13:47:19 +02:00
committed by GitHub
parent 301f5a50d9
commit 14b6f8b972
15 changed files with 261 additions and 149 deletions

View File

@@ -1,10 +1,8 @@
import {
ApplicationError,
NodeOperationError,
SEND_AND_WAIT_OPERATION,
tryToParseJsonToFormFields,
updateDisplayOptions,
WAIT_INDEFINITELY,
} from 'n8n-workflow';
import type {
INodeProperties,
@@ -14,6 +12,7 @@ import type {
FormFieldsParameter,
} from 'n8n-workflow';
import { limitWaitTimeProperties } from './descriptions';
import {
ACTION_RECORDED_PAGE,
BUTTON_STYLE_PRIMARY,
@@ -41,7 +40,7 @@ type FormResponseTypeOptions = {
const INPUT_FIELD_IDENTIFIER = 'field-0';
const limitWaitTimeProperties: INodeProperties = {
const limitWaitTimeOption: INodeProperties = {
displayName: 'Limit Wait Time',
name: 'limitWaitTime',
type: 'fixedCollection',
@@ -52,82 +51,7 @@ const limitWaitTimeProperties: INodeProperties = {
{
displayName: 'Values',
name: 'values',
values: [
{
displayName: 'Limit Type',
name: 'limitType',
type: 'options',
default: 'afterTimeInterval',
description:
'Sets the condition for the execution to resume. Can be a specified date or after some time.',
options: [
{
name: 'After Time Interval',
description: 'Waits for a certain amount of time',
value: 'afterTimeInterval',
},
{
name: 'At Specified Time',
description: 'Waits until the set date and time to continue',
value: 'atSpecifiedTime',
},
],
},
{
displayName: 'Amount',
name: 'resumeAmount',
type: 'number',
displayOptions: {
show: {
limitType: ['afterTimeInterval'],
},
},
typeOptions: {
minValue: 0,
numberPrecision: 2,
},
default: 1,
description: 'The time to wait',
},
{
displayName: 'Unit',
name: 'resumeUnit',
type: 'options',
displayOptions: {
show: {
limitType: ['afterTimeInterval'],
},
},
options: [
{
name: 'Minutes',
value: 'minutes',
},
{
name: 'Hours',
value: 'hours',
},
{
name: 'Days',
value: 'days',
},
],
default: 'hours',
description: 'Unit of the interval value',
},
{
displayName: 'Max Date and Time',
name: 'maxDateAndTime',
type: 'dateTime',
displayOptions: {
show: {
limitType: ['atSpecifiedTime'],
},
},
default: '',
description: 'Continue execution after the specified date and time',
},
],
values: limitWaitTimeProperties,
},
],
};
@@ -307,7 +231,7 @@ export function getSendAndWaitProperties(
type: 'collection',
placeholder: 'Add option',
default: {},
options: [limitWaitTimeProperties],
options: [limitWaitTimeOption],
displayOptions: {
show: {
responseType: ['approval'],
@@ -347,7 +271,7 @@ export function getSendAndWaitProperties(
type: 'string',
default: 'Submit',
},
limitWaitTimeProperties,
limitWaitTimeOption,
],
displayOptions: {
show: {
@@ -605,46 +529,3 @@ export function createEmail(context: IExecuteFunctions) {
return email;
}
export function configureWaitTillDate(context: IExecuteFunctions) {
let waitTill = WAIT_INDEFINITELY;
const limitWaitTime = context.getNodeParameter('options.limitWaitTime.values', 0, {}) as {
limitType?: string;
resumeAmount?: number;
resumeUnit?: string;
maxDateAndTime?: string;
};
if (Object.keys(limitWaitTime).length) {
try {
if (limitWaitTime.limitType === 'afterTimeInterval') {
let waitAmount = limitWaitTime.resumeAmount as number;
if (limitWaitTime.resumeUnit === 'minutes') {
waitAmount *= 60;
}
if (limitWaitTime.resumeUnit === 'hours') {
waitAmount *= 60 * 60;
}
if (limitWaitTime.resumeUnit === 'days') {
waitAmount *= 60 * 60 * 24;
}
waitAmount *= 1000;
waitTill = new Date(new Date().getTime() + waitAmount);
} else {
waitTill = new Date(limitWaitTime.maxDateAndTime as string);
}
if (isNaN(waitTill.getTime())) {
throw new ApplicationError('Invalid date format');
}
} catch (error) {
throw new NodeOperationError(context.getNode(), 'Could not configure Limit Wait Time', {
description: error.message,
});
}
}
return waitTill;
}