Skip to content

Commit

Permalink
Merge pull request #4797 from kishanprmr/gsheets-updated-trigger
Browse files Browse the repository at this point in the history
fix(google-sheets): fix empty row issue for updated trigger
  • Loading branch information
abuaboud committed May 28, 2024
2 parents 4df214e + b0a12a2 commit b55426a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 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.10.3"
"version": "0.10.4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,32 +101,40 @@ export const newOrUpdatedRowTrigger = createTrigger({
async onEnable(context) {
const spreadSheetId = context.propsValue.spreadsheet_id;
const sheetId = context.propsValue.sheet_id;
const triggerColumn = context.propsValue.trigger_column ;
const triggerColumn = context.propsValue.trigger_column ?? ALL_COLUMNS;

const sheetName = await getWorkSheetName(
context.auth,
spreadSheetId,
sheetId
);

const range =
triggerColumn === ALL_COLUMNS
? sheetName
: `${sheetName}!${triggerColumn}:${triggerColumn}`; // only fetch trigger column values

const sheetValues = await getWorkSheetValues(
context.auth,
spreadSheetId,
range
sheetName
);

const rowHashes = [];

// create initial row level hashes and used it to check updated row
for (const row of sheetValues) {
let targetValue;
if (triggerColumn === ALL_COLUMNS) {
targetValue = row;
} else {
const currentTriggerColumnValue = row[labelToColumn(triggerColumn)];

targetValue =
currentTriggerColumnValue !== undefined &&
currentTriggerColumnValue !== '' // if column value is empty
? [currentTriggerColumnValue]
: [];
}

const rowHash = crypto
.createHash('md5')
.update(JSON.stringify(row))
.update(JSON.stringify(targetValue))
.digest('hex');
rowHashes.push(rowHash);
}
Expand Down Expand Up @@ -210,7 +218,8 @@ export const newOrUpdatedRowTrigger = createTrigger({
currentRowValue[labelToColumn(triggerColumn)];

targetValue =
currentTriggerColumnValue !== undefined
currentTriggerColumnValue !== undefined &&
currentTriggerColumnValue !== ''
? [currentTriggerColumnValue]
: [];
}
Expand Down

0 comments on commit b55426a

Please sign in to comment.