mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Data Table Node): Add new filters to node operation conditions (no-changelog) (#18942)
Co-authored-by: Charlie Kolb <charlie@n8n.io>
This commit is contained in:
@@ -42,19 +42,95 @@ export async function tableSearch(
|
||||
}
|
||||
|
||||
export async function getDataTableColumns(this: ILoadOptionsFunctions) {
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased-id, n8n-nodes-base/node-param-display-name-miscased
|
||||
const returnData: INodePropertyOptions[] = [{ name: 'id - (number)', value: 'id' }];
|
||||
const returnData: Array<INodePropertyOptions & { type: string }> = [
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased-id, n8n-nodes-base/node-param-display-name-miscased
|
||||
{ name: 'id - (number)', value: 'id', type: 'number' },
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
||||
{ name: 'createdAt - (date)', value: 'createdAt', type: 'date' },
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
||||
{ name: 'updatedAt - (date)', value: 'updatedAt', type: 'date' },
|
||||
];
|
||||
const proxy = await getDataTableProxyLoadOptions(this);
|
||||
const columns = await proxy.getColumns();
|
||||
for (const column of columns) {
|
||||
returnData.push({
|
||||
name: `${column.name} - (${column.type})`,
|
||||
value: column.name,
|
||||
type: column.type,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
|
||||
const systemColumns = [
|
||||
{ name: 'id', type: 'number' },
|
||||
{ name: 'createdAt', type: 'date' },
|
||||
{ name: 'updatedAt', type: 'date' },
|
||||
] as const;
|
||||
|
||||
export async function getConditionsForColumn(this: ILoadOptionsFunctions) {
|
||||
const keyName = this.getCurrentNodeParameter('&keyName') as string;
|
||||
|
||||
// Base conditions available for all column types
|
||||
const baseConditions: INodePropertyOptions[] = [
|
||||
{ name: 'Equals', value: 'eq' },
|
||||
{ name: 'Not Equals', value: 'neq' },
|
||||
];
|
||||
|
||||
const comparableConditions: INodePropertyOptions[] = [
|
||||
{ name: 'Greater Than', value: 'gt' },
|
||||
{ name: 'Greater Than or Equal', value: 'gte' },
|
||||
{ name: 'Less Than', value: 'lt' },
|
||||
{ name: 'Less Than or Equal', value: 'lte' },
|
||||
];
|
||||
|
||||
const stringConditions: INodePropertyOptions[] = [
|
||||
{
|
||||
name: 'LIKE operator',
|
||||
value: 'like',
|
||||
description:
|
||||
'Case-sensitive pattern matching. Use % as wildcard (e.g., "%Mar%" to match "Anne-Marie").',
|
||||
},
|
||||
{
|
||||
name: 'ILIKE operator',
|
||||
value: 'ilike',
|
||||
description:
|
||||
'Case-insensitive pattern matching. Use % as wildcard (e.g., "%mar%" to match "Anne-Marie").',
|
||||
},
|
||||
];
|
||||
|
||||
const allConditions = [...baseConditions, ...comparableConditions, ...stringConditions];
|
||||
|
||||
// If no column is selected yet, return all conditions
|
||||
if (!keyName) {
|
||||
return allConditions;
|
||||
}
|
||||
|
||||
// Get column type to determine available conditions
|
||||
const column =
|
||||
systemColumns.find((col) => col.name === keyName) ??
|
||||
(await (await getDataTableProxyLoadOptions(this)).getColumns()).find(
|
||||
(col) => col.name === keyName,
|
||||
);
|
||||
|
||||
if (!column) {
|
||||
return baseConditions;
|
||||
}
|
||||
|
||||
const conditions = baseConditions;
|
||||
|
||||
// String columns get LIKE operators
|
||||
if (column.type === 'string') {
|
||||
conditions.push.apply(conditions, stringConditions);
|
||||
}
|
||||
|
||||
if (['number', 'date', 'string'].includes(column.type)) {
|
||||
conditions.push.apply(conditions, comparableConditions);
|
||||
}
|
||||
|
||||
return conditions;
|
||||
}
|
||||
|
||||
export async function getDataTables(this: ILoadOptionsFunctions): Promise<ResourceMapperFields> {
|
||||
const proxy = await getDataTableProxyLoadOptions(this);
|
||||
const result = await proxy.getColumns();
|
||||
|
||||
Reference in New Issue
Block a user