mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(Google Sheets Node): Return single row in read operation if combine conditions is OR and 'Return only First Matching Row' (#15095)
This commit is contained in:
@@ -11,7 +11,7 @@ export class GoogleSheets extends VersionedNodeType {
|
||||
name: 'googleSheets',
|
||||
icon: 'file:googleSheets.svg',
|
||||
group: ['input', 'output'],
|
||||
defaultVersion: 4.5,
|
||||
defaultVersion: 4.6,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Read, update and write data to Google Sheets',
|
||||
};
|
||||
@@ -26,6 +26,7 @@ export class GoogleSheets extends VersionedNodeType {
|
||||
4.3: new GoogleSheetsV2(baseDescription),
|
||||
4.4: new GoogleSheetsV2(baseDescription),
|
||||
4.5: new GoogleSheetsV2(baseDescription),
|
||||
4.6: new GoogleSheetsV2(baseDescription),
|
||||
};
|
||||
|
||||
super(nodeVersions, baseDescription);
|
||||
|
||||
@@ -103,7 +103,6 @@ describe('GoogleSheet', () => {
|
||||
});
|
||||
|
||||
describe('lookupValues', () => {
|
||||
it('should find matching rows with OR combination', async () => {
|
||||
const inputData = [
|
||||
['name', 'age', 'city'],
|
||||
['John', '30', 'NY'],
|
||||
@@ -111,6 +110,7 @@ describe('GoogleSheet', () => {
|
||||
['Bob', '30', 'SF'],
|
||||
];
|
||||
|
||||
it('should find matching rows with OR combination', async () => {
|
||||
const lookupValues = [{ lookupColumn: 'age', lookupValue: '30' }];
|
||||
|
||||
const result = await googleSheet.lookupValues({
|
||||
@@ -120,6 +120,7 @@ describe('GoogleSheet', () => {
|
||||
lookupValues,
|
||||
returnAllMatches: true,
|
||||
combineFilters: 'OR',
|
||||
nodeVersion: 4.5,
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
@@ -128,14 +129,46 @@ describe('GoogleSheet', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should find matching rows with AND combination', async () => {
|
||||
const inputData = [
|
||||
['name', 'age', 'city'],
|
||||
['John', '30', 'NY'],
|
||||
['Jane', '25', 'LA'],
|
||||
['Bob', '30', 'SF'],
|
||||
it('should find matching rows with OR combination and returnAllMatches is falsy at version 4.5', async () => {
|
||||
const lookupValues = [
|
||||
{ lookupColumn: 'age', lookupValue: '30' },
|
||||
{ lookupColumn: 'name', lookupValue: 'Jane' },
|
||||
];
|
||||
|
||||
const result = await googleSheet.lookupValues({
|
||||
inputData,
|
||||
keyRowIndex: 0,
|
||||
dataStartRowIndex: 1,
|
||||
lookupValues,
|
||||
combineFilters: 'OR',
|
||||
nodeVersion: 4.5,
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{ name: 'John', age: '30', city: 'NY' },
|
||||
{ name: 'Jane', age: '25', city: 'LA' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should find matching rows with OR combination and returnAllMatches is falsy at version 4.6', async () => {
|
||||
const lookupValues = [
|
||||
{ lookupColumn: 'age', lookupValue: '30' },
|
||||
{ lookupColumn: 'name', lookupValue: 'Jane' },
|
||||
];
|
||||
|
||||
const result = await googleSheet.lookupValues({
|
||||
inputData,
|
||||
keyRowIndex: 0,
|
||||
dataStartRowIndex: 1,
|
||||
lookupValues,
|
||||
combineFilters: 'OR',
|
||||
nodeVersion: 4.6,
|
||||
});
|
||||
|
||||
expect(result).toEqual([{ name: 'John', age: '30', city: 'NY' }]);
|
||||
});
|
||||
|
||||
it('should find matching rows with AND combination', async () => {
|
||||
const lookupValues = [
|
||||
{ lookupColumn: 'age', lookupValue: '30' },
|
||||
{ lookupColumn: 'city', lookupValue: 'NY' },
|
||||
@@ -148,21 +181,22 @@ describe('GoogleSheet', () => {
|
||||
lookupValues,
|
||||
returnAllMatches: true,
|
||||
combineFilters: 'AND',
|
||||
nodeVersion: 4.5,
|
||||
});
|
||||
|
||||
expect(result).toEqual([{ name: 'John', age: '30', city: 'NY' }]);
|
||||
});
|
||||
|
||||
it('should throw error for invalid key row', async () => {
|
||||
const inputData = [['name', 'age']];
|
||||
const lookupValues = [{ lookupColumn: 'age', lookupValue: '30' }];
|
||||
|
||||
await expect(
|
||||
googleSheet.lookupValues({
|
||||
inputData,
|
||||
inputData: [['name', 'age']],
|
||||
keyRowIndex: -1,
|
||||
dataStartRowIndex: 1,
|
||||
lookupValues,
|
||||
nodeVersion: 4.5,
|
||||
}),
|
||||
).rejects.toThrow('The key row does not exist');
|
||||
});
|
||||
|
||||
@@ -335,6 +335,7 @@ describe('Test Google Sheets, lookupValues', () => {
|
||||
],
|
||||
returnAllMatches: true,
|
||||
combineFilters: 'OR',
|
||||
nodeVersion: 4.5,
|
||||
});
|
||||
|
||||
expect(result).toBeDefined();
|
||||
@@ -397,6 +398,7 @@ describe('Test Google Sheets, lookupValues', () => {
|
||||
],
|
||||
returnAllMatches: true,
|
||||
combineFilters: 'AND',
|
||||
nodeVersion: 4.5,
|
||||
});
|
||||
|
||||
expect(result).toBeDefined();
|
||||
|
||||
@@ -268,6 +268,7 @@ export async function execute(
|
||||
lookupValues,
|
||||
returnAllMatches,
|
||||
combineFilters,
|
||||
nodeVersion,
|
||||
});
|
||||
} else {
|
||||
responseData = sheet.structureArrayDataByColumn(inputData, keyRowIndex, dataStartRowIndex);
|
||||
|
||||
@@ -9,7 +9,7 @@ export const versionDescription: INodeTypeDescription = {
|
||||
name: 'googleSheets',
|
||||
icon: 'file:googleSheets.svg',
|
||||
group: ['input', 'output'],
|
||||
version: [3, 4, 4.1, 4.2, 4.3, 4.4, 4.5],
|
||||
version: [3, 4, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6],
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Read, update and write data to Google Sheets',
|
||||
defaults: {
|
||||
|
||||
@@ -651,12 +651,14 @@ export class GoogleSheet {
|
||||
dataStartRowIndex,
|
||||
lookupValues,
|
||||
returnAllMatches,
|
||||
nodeVersion,
|
||||
combineFilters = 'OR',
|
||||
}: {
|
||||
inputData: string[][];
|
||||
keyRowIndex: number;
|
||||
dataStartRowIndex: number;
|
||||
lookupValues: ILookupValues[];
|
||||
nodeVersion: number;
|
||||
returnAllMatches?: boolean;
|
||||
combineFilters?: 'AND' | 'OR';
|
||||
}): Promise<IDataObject[]> {
|
||||
@@ -672,7 +674,7 @@ export class GoogleSheet {
|
||||
keys.push(inputData[keyRowIndex][columnIndex] || `col_${columnIndex}`);
|
||||
}
|
||||
|
||||
// Standardise values array, if rows is [[]], map it to [['']] (Keep the columns into consideration)
|
||||
// Standardize values array, if rows is [[]], map it to [['']] (Keep the columns into consideration)
|
||||
for (let rowIndex = 0; rowIndex < inputData?.length; rowIndex++) {
|
||||
if (inputData[rowIndex].length === 0) {
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
@@ -718,6 +720,9 @@ export class GoogleSheet {
|
||||
}
|
||||
|
||||
if (returnAllMatches !== true) {
|
||||
if (nodeVersion >= 4.6) {
|
||||
break lookupLoop;
|
||||
}
|
||||
continue lookupLoop;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user