mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
feat(Data Table Node): Add limit to get and change copy (no-changelog) (#19190)
This commit is contained in:
@@ -70,7 +70,7 @@ const errorMessage = computed<string>(() => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
// No data error message
|
// No data error message
|
||||||
if (props.fieldsToMap.length === 0) {
|
if (props.fieldsToMap.length === 0 && !props.typeOptions?.resourceMapper?.hideNoDataError) {
|
||||||
return (
|
return (
|
||||||
// Use custom error message if defined
|
// Use custom error message if defined
|
||||||
resourceMapperTypeOptions.value?.noFieldsError ||
|
resourceMapperTypeOptions.value?.noFieldsError ||
|
||||||
|
|||||||
@@ -17,7 +17,20 @@ const displayOptions: IDisplayOptions = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const description: INodeProperties[] = [...getSelectFields(displayOptions)];
|
export const description: INodeProperties[] = [
|
||||||
|
...getSelectFields(displayOptions),
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
},
|
||||||
|
displayOptions,
|
||||||
|
default: null,
|
||||||
|
description: 'Max number of results to return',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
export async function execute(
|
export async function execute(
|
||||||
this: IExecuteFunctions,
|
this: IExecuteFunctions,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export function makeAddRow(operation: string, displayOptions: IDisplayOptions) {
|
|||||||
typeOptions: {
|
typeOptions: {
|
||||||
loadOptionsDependsOn: [`${DATA_TABLE_ID_FIELD}.value`],
|
loadOptionsDependsOn: [`${DATA_TABLE_ID_FIELD}.value`],
|
||||||
resourceMapper: {
|
resourceMapper: {
|
||||||
valuesLabel: `Columns to ${operation}`,
|
valuesLabel: `Values to ${operation}`,
|
||||||
resourceMapperMethod: 'getDataTables',
|
resourceMapperMethod: 'getDataTables',
|
||||||
mode: 'add',
|
mode: 'add',
|
||||||
fieldWords: {
|
fieldWords: {
|
||||||
@@ -32,6 +32,7 @@ export function makeAddRow(operation: string, displayOptions: IDisplayOptions) {
|
|||||||
},
|
},
|
||||||
addAllFields: true,
|
addAllFields: true,
|
||||||
multiKeyMatch: true,
|
multiKeyMatch: true,
|
||||||
|
hideNoDataError: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
displayOptions,
|
displayOptions,
|
||||||
|
|||||||
@@ -44,17 +44,22 @@ export async function tableSearch(
|
|||||||
export async function getDataTableColumns(this: ILoadOptionsFunctions) {
|
export async function getDataTableColumns(this: ILoadOptionsFunctions) {
|
||||||
const returnData: Array<INodePropertyOptions & { type: string }> = [
|
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
|
// 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' },
|
{ name: 'id (number)', value: 'id', type: 'number' },
|
||||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
||||||
{ name: 'createdAt - (date)', value: 'createdAt', type: 'date' },
|
{ name: 'createdAt (date)', value: 'createdAt', type: 'date' },
|
||||||
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
|
||||||
{ name: 'updatedAt - (date)', value: 'updatedAt', type: 'date' },
|
{ name: 'updatedAt (date)', value: 'updatedAt', type: 'date' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const proxy = await getDataTableProxyLoadOptions(this);
|
const proxy = await getDataTableProxyLoadOptions(this);
|
||||||
|
if (!proxy) {
|
||||||
|
return returnData;
|
||||||
|
}
|
||||||
|
|
||||||
const columns = await proxy.getColumns();
|
const columns = await proxy.getColumns();
|
||||||
for (const column of columns) {
|
for (const column of columns) {
|
||||||
returnData.push({
|
returnData.push({
|
||||||
name: `${column.name} - (${column.type})`,
|
name: `${column.name} (${column.type})`,
|
||||||
value: column.name,
|
value: column.name,
|
||||||
type: column.type,
|
type: column.type,
|
||||||
});
|
});
|
||||||
@@ -69,6 +74,10 @@ const systemColumns = [
|
|||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export async function getConditionsForColumn(this: ILoadOptionsFunctions) {
|
export async function getConditionsForColumn(this: ILoadOptionsFunctions) {
|
||||||
|
const proxy = await getDataTableProxyLoadOptions(this);
|
||||||
|
if (!proxy) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
const keyName = this.getCurrentNodeParameter('&keyName') as string;
|
const keyName = this.getCurrentNodeParameter('&keyName') as string;
|
||||||
|
|
||||||
// Base conditions available for all column types
|
// Base conditions available for all column types
|
||||||
@@ -87,18 +96,8 @@ export async function getConditionsForColumn(this: ILoadOptionsFunctions) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const stringConditions: INodePropertyOptions[] = [
|
const stringConditions: INodePropertyOptions[] = [
|
||||||
{
|
{ name: 'Contains (Case-Sensitive)', value: 'like' },
|
||||||
name: 'LIKE operator',
|
{ name: 'Contains (Case-Insensitive)', value: 'ilike' },
|
||||||
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];
|
const allConditions = [...baseConditions, ...comparableConditions, ...stringConditions];
|
||||||
@@ -111,9 +110,7 @@ export async function getConditionsForColumn(this: ILoadOptionsFunctions) {
|
|||||||
// Get column type to determine available conditions
|
// Get column type to determine available conditions
|
||||||
const column =
|
const column =
|
||||||
systemColumns.find((col) => col.name === keyName) ??
|
systemColumns.find((col) => col.name === keyName) ??
|
||||||
(await (await getDataTableProxyLoadOptions(this)).getColumns()).find(
|
(await proxy.getColumns()).find((col) => col.name === keyName);
|
||||||
(col) => col.name === keyName,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!column) {
|
if (!column) {
|
||||||
return baseConditions;
|
return baseConditions;
|
||||||
@@ -135,6 +132,9 @@ export async function getConditionsForColumn(this: ILoadOptionsFunctions) {
|
|||||||
|
|
||||||
export async function getDataTables(this: ILoadOptionsFunctions): Promise<ResourceMapperFields> {
|
export async function getDataTables(this: ILoadOptionsFunctions): Promise<ResourceMapperFields> {
|
||||||
const proxy = await getDataTableProxyLoadOptions(this);
|
const proxy = await getDataTableProxyLoadOptions(this);
|
||||||
|
if (!proxy) {
|
||||||
|
return { fields: [] };
|
||||||
|
}
|
||||||
const result = await proxy.getColumns();
|
const result = await proxy.getColumns();
|
||||||
|
|
||||||
const fields: ResourceMapperField[] = [];
|
const fields: ResourceMapperField[] = [];
|
||||||
|
|||||||
@@ -122,33 +122,48 @@ export async function executeSelectMany(
|
|||||||
throw new NodeOperationError(ctx.getNode(), 'At least one condition is required');
|
throw new NodeOperationError(ctx.getNode(), 'At least one condition is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
let take = 1000;
|
const PAGE_SIZE = 1000;
|
||||||
const result: Array<{ json: DataStoreRowReturn }> = [];
|
const result: Array<{ json: DataStoreRowReturn }> = [];
|
||||||
let totalCount = undefined;
|
|
||||||
do {
|
const limit = ctx.getNodeParameter('limit', index, undefined);
|
||||||
const response = await dataStoreProxy.getManyRowsAndCount({
|
|
||||||
skip: result.length,
|
let expectedTotal: number | undefined;
|
||||||
take,
|
let skip = 0;
|
||||||
|
let take = PAGE_SIZE;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const { data, count } = await dataStoreProxy.getManyRowsAndCount({
|
||||||
|
skip,
|
||||||
|
take: limit ? Math.min(take, limit - result.length) : take,
|
||||||
filter,
|
filter,
|
||||||
});
|
});
|
||||||
const data = response.data.map((json) => ({ json }));
|
const wrapped = data.map((json) => ({ json }));
|
||||||
|
|
||||||
// Optimize common path of <1000 results
|
// Fast path: everything fits in a single page
|
||||||
if (response.count === response.data.length) {
|
if (skip === 0 && count === data.length) {
|
||||||
return data;
|
return wrapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalCount !== undefined && response.count !== totalCount) {
|
// Ensure the total doesn't change mid-pagination
|
||||||
|
if (expectedTotal !== undefined && count !== expectedTotal) {
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
ctx.getNode(),
|
ctx.getNode(),
|
||||||
'synchronization error: result count changed during pagination',
|
'synchronization error: result count changed during pagination',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
totalCount = response.count;
|
expectedTotal = count;
|
||||||
|
|
||||||
result.push.apply(result, data);
|
result.push.apply(result, wrapped);
|
||||||
take = Math.min(take, response.count - result.length);
|
|
||||||
} while (take > 0);
|
// Stop if we've hit the limit
|
||||||
|
if (limit && result.length >= limit) break;
|
||||||
|
|
||||||
|
// Stop if we've collected everything
|
||||||
|
if (result.length >= count) break;
|
||||||
|
|
||||||
|
skip = result.length;
|
||||||
|
take = Math.min(PAGE_SIZE, count - result.length);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export async function getDataTableProxyExecute(
|
|||||||
|
|
||||||
export async function getDataTableProxyLoadOptions(
|
export async function getDataTableProxyLoadOptions(
|
||||||
ctx: ILoadOptionsFunctions,
|
ctx: ILoadOptionsFunctions,
|
||||||
): Promise<IDataStoreProjectService> {
|
): Promise<IDataStoreProjectService | undefined> {
|
||||||
if (ctx.helpers.getDataStoreProxy === undefined)
|
if (ctx.helpers.getDataStoreProxy === undefined)
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
ctx.getNode(),
|
ctx.getNode(),
|
||||||
@@ -55,6 +55,10 @@ export async function getDataTableProxyLoadOptions(
|
|||||||
extractValue: true,
|
extractValue: true,
|
||||||
}) as string;
|
}) as string;
|
||||||
|
|
||||||
|
if (!dataStoreId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return await ctx.helpers.getDataStoreProxy(dataStoreId);
|
return await ctx.helpers.getDataStoreProxy(dataStoreId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1435,6 +1435,7 @@ export interface ResourceMapperTypeOptionsBase {
|
|||||||
noFieldsError?: string;
|
noFieldsError?: string;
|
||||||
multiKeyMatch?: boolean;
|
multiKeyMatch?: boolean;
|
||||||
supportAutoMap?: boolean;
|
supportAutoMap?: boolean;
|
||||||
|
hideNoDataError?: boolean; // Hide "No data found" error when no fields are available
|
||||||
matchingFieldsLabels?: {
|
matchingFieldsLabels?: {
|
||||||
title?: string;
|
title?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user