Skip to content

Commit

Permalink
Merge pull request #4359 from kishanprmr/google-sheet
Browse files Browse the repository at this point in the history
fix(google-sheets): Add row count condition in case of manual row deletion.
  • Loading branch information
abuaboud committed Apr 6, 2024
2 parents 59040ed + 1df7605 commit 1744ce8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/pieces/community/google-sheets/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-google-sheets",
"version": "0.9.0"
"version": "0.9.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const insertRowAction = createAction({
required: false,
}),
first_row_headers: Property.Checkbox({
displayName: 'Are the First row Headers?',
displayName: 'Does the first row contain headers?',
description: 'If the first row is headers',
required: true,
defaultValue: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const updateRowAction = createAction({
required: true,
}),
first_row_headers: Property.Checkbox({
displayName: 'Are the First row Headers?',
displayName: 'Does the first row contain headers?',
description: 'If the first row is headers',
required: true,
defaultValue: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const newRowAddedTrigger = createTrigger({
description: 'Triggers when a new row is added to bottom of a spreadsheet.',
props: {
info: Property.MarkDown({
value: 'Please note that there might be a delay of up to 3 minutes for the trigger to be fired, due to a delay from Google.'
value:
'Please note that there might be a delay of up to 3 minutes for the trigger to be fired, due to a delay from Google.',
}),
spreadsheet_id: googleSheetsCommon.spreadsheet_id,
sheet_id: googleSheetsCommon.sheet_id,
Expand Down Expand Up @@ -79,7 +80,7 @@ export const newRowAddedTrigger = createTrigger({

// fetch old row count for worksheet
const oldRowCount = (await context.store.get(
`${context.propsValue.sheet_id}`
`${sheet_id}`
)) as number;

// fetch current row count for worksheet
Expand All @@ -96,7 +97,11 @@ export const newRowAddedTrigger = createTrigger({
const currentRowCount = currentRowValues.length;

// if no new rows return
if (oldRowCount === currentRowCount) {
if (oldRowCount >= currentRowCount) {
if(oldRowCount > currentRowCount) {
// Some rows were deleted
await context.store.put(`${sheet_id}`, currentRowCount);
}
return [];
}

Expand Down Expand Up @@ -162,7 +167,9 @@ export const newRowAddedTrigger = createTrigger({
);

// transform row values
const transformedRowValues = transformWorkSheetValues(currentSheetValues, 0).slice(-5).reverse();
const transformedRowValues = transformWorkSheetValues(currentSheetValues, 0)
.slice(-5)
.reverse();

return transformedRowValues;
},
Expand Down Expand Up @@ -287,4 +294,4 @@ function hashObject(obj: Record<string, unknown>): string {
const hash = crypto.createHash('sha256');
hash.update(JSON.stringify(obj));
return hash.digest('hex');
}
}

0 comments on commit 1744ce8

Please sign in to comment.