mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
feat(core): Display conditions in displayOptions (no-changelog) (#7888)
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { Credentials } from 'n8n-core';
|
||||
import type { IDataObject, INodeProperties, INodePropertyOptions } from 'n8n-workflow';
|
||||
import type {
|
||||
DisplayCondition,
|
||||
IDataObject,
|
||||
INodeProperties,
|
||||
INodePropertyOptions,
|
||||
} from 'n8n-workflow';
|
||||
import * as Db from '@/Db';
|
||||
import type { ICredentialsDb } from '@/Interfaces';
|
||||
import { CredentialsEntity } from '@db/entities/CredentialsEntity';
|
||||
@@ -182,7 +187,7 @@ export function toJsonSchema(properties: INodeProperties[]): IDataObject {
|
||||
if (property.displayOptions?.show) {
|
||||
const dependantName = Object.keys(property.displayOptions?.show)[0] || '';
|
||||
const displayOptionsValues = property.displayOptions.show[dependantName];
|
||||
let dependantValue: string | number | boolean = '';
|
||||
let dependantValue: DisplayCondition | string | number | boolean = '';
|
||||
|
||||
if (displayOptionsValues && Array.isArray(displayOptionsValues) && displayOptionsValues[0]) {
|
||||
dependantValue = displayOptionsValues[0];
|
||||
@@ -193,12 +198,75 @@ export function toJsonSchema(properties: INodeProperties[]): IDataObject {
|
||||
}
|
||||
|
||||
if (!resolveProperties.includes(dependantName)) {
|
||||
let conditionalValue;
|
||||
if (typeof dependantValue === 'object' && dependantValue._cnd) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const [key, targetValue] = Object.entries(dependantValue._cnd)[0];
|
||||
|
||||
if (key === 'eq') {
|
||||
conditionalValue = {
|
||||
const: [targetValue],
|
||||
};
|
||||
} else if (key === 'not') {
|
||||
conditionalValue = {
|
||||
not: {
|
||||
const: [targetValue],
|
||||
},
|
||||
};
|
||||
} else if (key === 'gt') {
|
||||
conditionalValue = {
|
||||
type: 'number',
|
||||
exclusiveMinimum: [targetValue],
|
||||
};
|
||||
} else if (key === 'gte') {
|
||||
conditionalValue = {
|
||||
type: 'number',
|
||||
minimum: [targetValue],
|
||||
};
|
||||
} else if (key === 'lt') {
|
||||
conditionalValue = {
|
||||
type: 'number',
|
||||
exclusiveMaximum: [targetValue],
|
||||
};
|
||||
} else if (key === 'lte') {
|
||||
conditionalValue = {
|
||||
type: 'number',
|
||||
maximum: [targetValue],
|
||||
};
|
||||
} else if (key === 'startsWith') {
|
||||
conditionalValue = {
|
||||
type: 'string',
|
||||
pattern: `^${targetValue}`,
|
||||
};
|
||||
} else if (key === 'endsWith') {
|
||||
conditionalValue = {
|
||||
type: 'string',
|
||||
pattern: `${targetValue}$`,
|
||||
};
|
||||
} else if (key === 'includes') {
|
||||
conditionalValue = {
|
||||
type: 'string',
|
||||
pattern: `${targetValue}`,
|
||||
};
|
||||
} else if (key === 'regex') {
|
||||
conditionalValue = {
|
||||
type: 'string',
|
||||
pattern: `${targetValue}`,
|
||||
};
|
||||
} else {
|
||||
conditionalValue = {
|
||||
enum: [dependantValue],
|
||||
};
|
||||
}
|
||||
} else {
|
||||
conditionalValue = {
|
||||
enum: [dependantValue],
|
||||
};
|
||||
}
|
||||
propertyRequiredDependencies[dependantName] = {
|
||||
if: {
|
||||
properties: {
|
||||
[dependantName]: {
|
||||
enum: [dependantValue],
|
||||
},
|
||||
[dependantName]: conditionalValue,
|
||||
},
|
||||
},
|
||||
then: {
|
||||
|
||||
Reference in New Issue
Block a user