Skip to content

Commit

Permalink
fix(Google Sheets Node): Tweaks (#7357)
Browse files Browse the repository at this point in the history
Github issue / Community forum post (link here to close automatically):
  • Loading branch information
michael-radency authored Oct 17, 2023
1 parent a2d2e3d commit d8531a5
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 295 deletions.
3 changes: 2 additions & 1 deletion packages/nodes-base/nodes/Google/Sheet/GoogleSheets.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class GoogleSheets extends VersionedNodeType {
name: 'googleSheets',
icon: 'file:googleSheets.svg',
group: ['input', 'output'],
defaultVersion: 4,
defaultVersion: 4.1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Read, update and write data to Google Sheets',
};
Expand All @@ -21,6 +21,7 @@ export class GoogleSheets extends VersionedNodeType {
2: new GoogleSheetsV1(baseDescription),
3: new GoogleSheetsV2(baseDescription),
4: new GoogleSheetsV2(baseDescription),
4.1: new GoogleSheetsV2(baseDescription),
};

super(nodeVersions, baseDescription);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
import type { SheetProperties, ValueInputOption } from '../../helpers/GoogleSheets.types';
import type { GoogleSheet } from '../../helpers/GoogleSheet';
import { autoMapInputData, mapFields, untilSheetSelected } from '../../helpers/GoogleSheets.utils';
import {
autoMapInputData,
cellFormatDefault,
mapFields,
untilSheetSelected,
} from '../../helpers/GoogleSheets.utils';
import { cellFormat, handlingExtraData } from './commonDescription';

export const description: SheetProperties = [
Expand Down Expand Up @@ -131,7 +136,7 @@ export const description: SheetProperties = [
show: {
resource: ['sheet'],
operation: ['append'],
'@version': [4],
'@version': [4, 4.1],
},
hide: {
...untilSheetSelected,
Expand All @@ -154,7 +159,7 @@ export const description: SheetProperties = [
},
},
options: [
...cellFormat,
cellFormat,
{
displayName: 'Data Location on Sheet',
name: 'locationDefine',
Expand All @@ -181,7 +186,11 @@ export const description: SheetProperties = [
},
],
},
...handlingExtraData,
handlingExtraData,
{
...handlingExtraData,
displayOptions: { show: { '/columns.mappingMode': ['autoMapInputData'] } },
},
],
},
];
Expand Down Expand Up @@ -227,7 +236,7 @@ export async function execute(
setData,
sheetName,
headerRow,
(options.cellFormat as ValueInputOption) || 'RAW',
(options.cellFormat as ValueInputOption) || cellFormatDefault(nodeVersion),
false,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from '../../helpers/GoogleSheets.types';
import { NodeOperationError } from 'n8n-workflow';
import type { GoogleSheet } from '../../helpers/GoogleSheet';
import { untilSheetSelected } from '../../helpers/GoogleSheets.utils';
import { cellFormatDefault, untilSheetSelected } from '../../helpers/GoogleSheets.utils';
import { cellFormat, handlingExtraData, locationDefine } from './commonDescription';

export const description: SheetProperties = [
Expand Down Expand Up @@ -172,7 +172,7 @@ export const description: SheetProperties = [
show: {
resource: ['sheet'],
operation: ['appendOrUpdate'],
'@version': [4],
'@version': [4, 4.1],
},
hide: {
...untilSheetSelected,
Expand All @@ -194,7 +194,15 @@ export const description: SheetProperties = [
...untilSheetSelected,
},
},
options: [...cellFormat, ...locationDefine, ...handlingExtraData],
options: [
cellFormat,
locationDefine,
handlingExtraData,
{
...handlingExtraData,
displayOptions: { show: { '/columns.mappingMode': ['autoMapInputData'] } },
},
],
},
];

Expand All @@ -205,9 +213,16 @@ export async function execute(
sheetId: string,
): Promise<INodeExecutionData[]> {
const items = this.getInputData();
const valueInputMode = this.getNodeParameter('options.cellFormat', 0, 'RAW') as ValueInputOption;
const nodeVersion = this.getNode().typeVersion;

const range = `${sheetName}!A:Z`;

const valueInputMode = this.getNodeParameter(
'options.cellFormat',
0,
cellFormatDefault(nodeVersion),
) as ValueInputOption;

const options = this.getNodeParameter('options', 0, {});

const valueRenderMode = (options.valueRenderMode || 'UNFORMATTED_VALUE') as ValueRenderOption;
Expand Down Expand Up @@ -238,7 +253,7 @@ export async function execute(
}

columnNames = sheetData[headerRow];
const nodeVersion = this.getNode().typeVersion;

const newColumns = new Set<string>();

const columnsToMatchOn: string[] =
Expand Down Expand Up @@ -346,7 +361,7 @@ export async function execute(
await sheet.updateRows(
sheetName,
[columnNames.concat([...newColumns])],
(options.cellFormat as ValueInputOption) || 'RAW',
(options.cellFormat as ValueInputOption) || cellFormatDefault(nodeVersion),
headerRow + 1,
);
}
Expand Down
Loading

0 comments on commit d8531a5

Please sign in to comment.