feat(core): Refactor data table update row to use filters (no-changelog) (#19092)

This commit is contained in:
Daria
2025-09-04 18:25:29 +03:00
committed by GitHub
parent 2f2672c551
commit ed6f60f52e
18 changed files with 1421 additions and 233 deletions

View File

@@ -7,7 +7,7 @@ import {
} from 'n8n-workflow';
import { makeAddRow, getAddRow } from '../../common/addRow';
import { executeSelectMany, getSelectFields } from '../../common/selectMany';
import { getSelectFields, getSelectFilter } from '../../common/selectMany';
import { getDataTableProxyExecute } from '../../common/utils';
export const FIELD: string = 'update';
@@ -31,26 +31,16 @@ export async function execute(
const dataStoreProxy = await getDataTableProxyExecute(this, index);
const row = getAddRow(this, index);
const filter = getSelectFilter(this, index);
const matches = await executeSelectMany(this, index, dataStoreProxy, true);
const result = [];
for (const x of matches) {
const updatedRows = await dataStoreProxy.updateRows({
data: row,
filter: { id: x.json.id },
});
if (updatedRows.length !== 1) {
throw new NodeOperationError(this.getNode(), 'invariant broken');
}
// The input object gets updated in the api call, somehow
// And providing this column to the backend causes an unexpected column error
// So let's just re-delete the field until we have a more aligned API
delete row['updatedAt'];
result.push(updatedRows[0]);
if (filter.filters.length === 0) {
throw new NodeOperationError(this.getNode(), 'At least one condition is required');
}
return result.map((json) => ({ json }));
const updatedRows = await dataStoreProxy.updateRows({
data: row,
filter,
});
return updatedRows.map((json) => ({ json }));
}

View File

@@ -45,7 +45,10 @@ export async function execute(
for (const match of matches) {
const updatedRows = await dataStoreProxy.updateRows({
data: row,
filter: { id: match.json.id },
filter: {
type: 'and',
filters: [{ columnName: 'id', condition: 'eq', value: match.json.id }],
},
});
if (updatedRows.length !== 1) {
throw new NodeOperationError(this.getNode(), 'invariant broken');

View File

@@ -1,5 +1,6 @@
import { NodeOperationError } from 'n8n-workflow';
import type {
DataTableFilter,
DataStoreRowReturn,
IDataStoreProjectService,
IDisplayOptions,
@@ -94,7 +95,7 @@ export function getSelectFields(
];
}
export function getSelectFilter(ctx: IExecuteFunctions, index: number) {
export function getSelectFilter(ctx: IExecuteFunctions, index: number): DataTableFilter {
const fields = ctx.getNodeParameter('filters.conditions', index, []);
const matchType = ctx.getNodeParameter('matchType', index, ANY_CONDITION);
const node = ctx.getNode();

View File

@@ -2,7 +2,7 @@ import { DateTime } from 'luxon';
import type {
IDataObject,
INode,
ListDataStoreContentFilter,
DataTableFilter,
IDataStoreProjectAggregateService,
IDataStoreProjectService,
IExecuteFunctions,
@@ -82,7 +82,7 @@ export function isMatchType(obj: unknown): obj is FilterType {
export function buildGetManyFilter(
fieldEntries: FieldEntry[],
matchType: FilterType,
): ListDataStoreContentFilter {
): DataTableFilter {
const filters = fieldEntries.map((x) => {
switch (x.condition) {
case 'isEmpty':