mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(Data Table Node): Add isEmpty and isNotEmpty operations (no-changelog) (#19046)
This commit is contained in:
@@ -5,8 +5,13 @@ export const ALL_FILTERS = 'allFilters';
|
||||
|
||||
export type FilterType = typeof ANY_FILTER | typeof ALL_FILTERS;
|
||||
|
||||
export type FieldEntry = {
|
||||
keyName: string;
|
||||
condition: 'eq' | 'neq' | 'like' | 'ilike' | 'gt' | 'gte' | 'lt' | 'lte';
|
||||
keyValue: DataStoreColumnJsType;
|
||||
};
|
||||
export type FieldEntry =
|
||||
| {
|
||||
keyName: string;
|
||||
condition: 'isEmpty' | 'isNotEmpty';
|
||||
}
|
||||
| {
|
||||
keyName: string;
|
||||
condition: 'eq' | 'neq' | 'like' | 'ilike' | 'gt' | 'gte' | 'lt' | 'lte';
|
||||
keyValue: DataStoreColumnJsType;
|
||||
};
|
||||
|
||||
@@ -75,6 +75,8 @@ export async function getConditionsForColumn(this: ILoadOptionsFunctions) {
|
||||
const baseConditions: INodePropertyOptions[] = [
|
||||
{ name: 'Equals', value: 'eq' },
|
||||
{ name: 'Not Equals', value: 'neq' },
|
||||
{ name: 'Is Empty', value: 'isEmpty' },
|
||||
{ name: 'Is Not Empty', value: 'isNotEmpty' },
|
||||
];
|
||||
|
||||
const comparableConditions: INodePropertyOptions[] = [
|
||||
|
||||
@@ -78,6 +78,11 @@ export function getSelectFields(
|
||||
name: 'keyValue',
|
||||
type: 'string',
|
||||
default: '',
|
||||
displayOptions: {
|
||||
hide: {
|
||||
condition: ['isEmpty', 'isNotEmpty'],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -89,13 +94,14 @@ export function getSelectFields(
|
||||
|
||||
export function getSelectFilter(ctx: IExecuteFunctions, index: number) {
|
||||
const fields = ctx.getNodeParameter('filters.conditions', index, []);
|
||||
const matchType = ctx.getNodeParameter('matchType', index, []);
|
||||
const matchType = ctx.getNodeParameter('matchType', index, 'anyFilter');
|
||||
const node = ctx.getNode();
|
||||
|
||||
if (!isMatchType(matchType)) {
|
||||
throw new NodeOperationError(ctx.getNode(), 'unexpected match type');
|
||||
throw new NodeOperationError(node, 'unexpected match type');
|
||||
}
|
||||
if (!isFieldArray(fields)) {
|
||||
throw new NodeOperationError(ctx.getNode(), 'unexpected fields input');
|
||||
throw new NodeOperationError(node, 'unexpected fields input');
|
||||
}
|
||||
|
||||
return buildGetManyFilter(fields, matchType);
|
||||
|
||||
@@ -72,7 +72,7 @@ export async function getDataTableAggregateProxy(
|
||||
|
||||
export function isFieldEntry(obj: unknown): obj is FieldEntry {
|
||||
if (obj === null || typeof obj !== 'object') return false;
|
||||
return 'keyName' in obj && 'condition' in obj && 'keyValue' in obj;
|
||||
return 'keyName' in obj && 'condition' in obj; // keyValue is optional
|
||||
}
|
||||
|
||||
export function isMatchType(obj: unknown): obj is FilterType {
|
||||
@@ -83,11 +83,28 @@ export function buildGetManyFilter(
|
||||
fieldEntries: FieldEntry[],
|
||||
matchType: FilterType,
|
||||
): ListDataStoreContentFilter {
|
||||
const filters = fieldEntries.map((x) => ({
|
||||
columnName: x.keyName,
|
||||
condition: x.condition,
|
||||
value: x.keyValue,
|
||||
}));
|
||||
const filters = fieldEntries.map((x) => {
|
||||
switch (x.condition) {
|
||||
case 'isEmpty':
|
||||
return {
|
||||
columnName: x.keyName,
|
||||
condition: 'eq' as const,
|
||||
value: null,
|
||||
};
|
||||
case 'isNotEmpty':
|
||||
return {
|
||||
columnName: x.keyName,
|
||||
condition: 'neq' as const,
|
||||
value: null,
|
||||
};
|
||||
default:
|
||||
return {
|
||||
columnName: x.keyName,
|
||||
condition: x.condition,
|
||||
value: x.keyValue,
|
||||
};
|
||||
}
|
||||
});
|
||||
return { type: matchType === 'allFilters' ? 'and' : 'or', filters };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user