mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(Google Sheets Node): Add "By Name" option to selector for Sheets (#8241)
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
@@ -1,24 +1,26 @@
|
||||
import get from 'lodash/get';
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IDataObject,
|
||||
IPollFunctions,
|
||||
INode,
|
||||
IPollFunctions,
|
||||
} from 'n8n-workflow';
|
||||
import { ApplicationError, NodeOperationError } from 'n8n-workflow';
|
||||
import { utils as xlsxUtils } from 'xlsx';
|
||||
import get from 'lodash/get';
|
||||
import { apiRequest } from '../transport';
|
||||
import type {
|
||||
ILookupValues,
|
||||
ISheetUpdateData,
|
||||
ResourceLocator,
|
||||
SheetCellDecoded,
|
||||
SheetRangeData,
|
||||
SheetRangeDecoded,
|
||||
SpreadSheetResponse,
|
||||
ValueInputOption,
|
||||
ValueRenderOption,
|
||||
} from './GoogleSheets.types';
|
||||
import { removeEmptyColumns } from './GoogleSheets.utils';
|
||||
import { getSheetId, removeEmptyColumns } from './GoogleSheets.utils';
|
||||
|
||||
export class GoogleSheet {
|
||||
id: string;
|
||||
@@ -116,32 +118,35 @@ export class GoogleSheet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of a sheet from a sheet id
|
||||
* Returns the sheet within a spreadsheet based on name or ID
|
||||
*/
|
||||
async spreadsheetGetSheetNameById(node: INode, sheetId: string) {
|
||||
async spreadsheetGetSheet(node: INode, mode: ResourceLocator, value: string) {
|
||||
const query = {
|
||||
fields: 'sheets.properties',
|
||||
};
|
||||
|
||||
const response = await apiRequest.call(
|
||||
const response = (await apiRequest.call(
|
||||
this.executeFunctions,
|
||||
'GET',
|
||||
`/v4/spreadsheets/${this.id}`,
|
||||
{},
|
||||
query,
|
||||
);
|
||||
)) as SpreadSheetResponse;
|
||||
|
||||
const foundItem = response.sheets.find(
|
||||
(item: { properties: { sheetId: number } }) => item.properties.sheetId === +sheetId,
|
||||
);
|
||||
const foundItem = response.sheets.find((item) => {
|
||||
if (mode === 'name') return item.properties.title === value;
|
||||
return item.properties.sheetId === getSheetId(value);
|
||||
});
|
||||
|
||||
if (!foundItem?.properties?.title) {
|
||||
throw new NodeOperationError(node, `Sheet with ID ${sheetId} not found`, {
|
||||
level: 'warning',
|
||||
});
|
||||
throw new NodeOperationError(
|
||||
node,
|
||||
`Sheet with ${mode === 'name' ? 'name' : 'ID'} ${value} not found`,
|
||||
{ level: 'warning' },
|
||||
);
|
||||
}
|
||||
|
||||
return foundItem.properties.title;
|
||||
return foundItem.properties;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user