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