first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
||||
|
||||
import { generatePairedItemData, wrapData } from '../../../../../../utils/utilities';
|
||||
import type { GoogleSheet } from '../../helpers/GoogleSheet';
|
||||
import type { SheetProperties } from '../../helpers/GoogleSheets.types';
|
||||
import { getColumnNumber, untilSheetSelected } from '../../helpers/GoogleSheets.utils';
|
||||
|
||||
export const description: SheetProperties = [
|
||||
{
|
||||
displayName: 'To Delete',
|
||||
name: 'toDelete',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Rows',
|
||||
value: 'rows',
|
||||
description: 'Rows to delete',
|
||||
},
|
||||
{
|
||||
name: 'Columns',
|
||||
value: 'columns',
|
||||
description: 'Columns to delete',
|
||||
},
|
||||
],
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sheet'],
|
||||
operation: ['delete'],
|
||||
},
|
||||
hide: {
|
||||
...untilSheetSelected,
|
||||
},
|
||||
},
|
||||
default: 'rows',
|
||||
description: 'What to delete',
|
||||
},
|
||||
{
|
||||
displayName: 'Start Row Number',
|
||||
name: 'startIndex',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
default: 2,
|
||||
description: 'The row number to delete from, The first row is 2',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sheet'],
|
||||
operation: ['delete'],
|
||||
toDelete: ['rows'],
|
||||
},
|
||||
hide: {
|
||||
...untilSheetSelected,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Number of Rows to Delete',
|
||||
name: 'numberToDelete',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
default: 1,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sheet'],
|
||||
operation: ['delete'],
|
||||
toDelete: ['rows'],
|
||||
},
|
||||
hide: {
|
||||
...untilSheetSelected,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Start Column',
|
||||
name: 'startIndex',
|
||||
type: 'string',
|
||||
default: 'A',
|
||||
description: 'The column to delete',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sheet'],
|
||||
operation: ['delete'],
|
||||
toDelete: ['columns'],
|
||||
},
|
||||
hide: {
|
||||
...untilSheetSelected,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Number of Columns to Delete',
|
||||
name: 'numberToDelete',
|
||||
type: 'number',
|
||||
typeOptions: {
|
||||
minValue: 1,
|
||||
},
|
||||
default: 1,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sheet'],
|
||||
operation: ['delete'],
|
||||
toDelete: ['columns'],
|
||||
},
|
||||
hide: {
|
||||
...untilSheetSelected,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
sheet: GoogleSheet,
|
||||
sheetName: string,
|
||||
): Promise<INodeExecutionData[]> {
|
||||
const items = this.getInputData();
|
||||
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const requests: IDataObject[] = [];
|
||||
let startIndex, endIndex, numberToDelete;
|
||||
const deleteType = this.getNodeParameter('toDelete', i) as string;
|
||||
|
||||
if (deleteType === 'rows') {
|
||||
startIndex = this.getNodeParameter('startIndex', i) as number;
|
||||
// We start from 1 now...
|
||||
startIndex--;
|
||||
numberToDelete = this.getNodeParameter('numberToDelete', i) as number;
|
||||
if (numberToDelete === 1) {
|
||||
endIndex = startIndex + 1;
|
||||
} else {
|
||||
endIndex = startIndex + numberToDelete;
|
||||
}
|
||||
requests.push({
|
||||
deleteDimension: {
|
||||
range: {
|
||||
sheetId: sheetName,
|
||||
dimension: 'ROWS',
|
||||
startIndex,
|
||||
endIndex,
|
||||
},
|
||||
},
|
||||
});
|
||||
} else if (deleteType === 'columns') {
|
||||
startIndex = this.getNodeParameter('startIndex', i) as string;
|
||||
numberToDelete = this.getNodeParameter('numberToDelete', i) as number;
|
||||
startIndex = getColumnNumber(startIndex) - 1;
|
||||
if (numberToDelete === 1) {
|
||||
endIndex = startIndex + 1;
|
||||
} else {
|
||||
endIndex = startIndex + numberToDelete;
|
||||
}
|
||||
requests.push({
|
||||
deleteDimension: {
|
||||
range: {
|
||||
sheetId: sheetName,
|
||||
dimension: 'COLUMNS',
|
||||
startIndex,
|
||||
endIndex,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
await sheet.spreadsheetBatchUpdate(requests);
|
||||
}
|
||||
|
||||
const itemData = generatePairedItemData(this.getInputData().length);
|
||||
const returnData = this.helpers.constructExecutionMetaData(wrapData({ success: true }), {
|
||||
itemData,
|
||||
});
|
||||
|
||||
return returnData;
|
||||
}
|
||||
Reference in New Issue
Block a user