Skip to content

[Notion] emit original page, not modified #14160

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/notion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/notion",
"version": "0.2.1",
"version": "0.2.2",
"description": "Pipedream Notion Components",
"main": "notion.app.mjs",
"keywords": [
Expand Down
22 changes: 14 additions & 8 deletions components/notion/sources/updated-page/updated-page.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
key: "notion-updated-page",
name: "Updated Page in Database", /* eslint-disable-line pipedream/source-name */
description: "Emit new event when a page in a database is updated. To select a specific page, use `Updated Page ID` instead",
version: "0.1.1",
version: "0.1.2",
type: "source",
dedupe: "unique",
props: {
Expand Down Expand Up @@ -91,11 +91,13 @@ export default {
// Files & Media type:
// `url` and `expiry_time` are constantly updated by Notion, so ignore these fields
if (property.type === "files") {
for (const file of property.files) {
const modified = structuredClone(property);
for (const file of modified.files) {
if (file.type === "file") {
delete file.file;
}
}
return modified;
}
return property;
},
Expand Down Expand Up @@ -153,34 +155,38 @@ export default {

for (const propertyName of propertiesToCheck) {
const previousValue = structuredClone(propertyValues[page.id]?.[propertyName]);
const currentValue = this.maybeRemoveFileSubItems(page.properties[propertyName]);
// value used to compare and to save to this.db
const currentValueToSave = this.maybeRemoveFileSubItems(page.properties[propertyName]);
// (unmodified) value that should be emitted
const currentValueToEmit = page.properties[propertyName];

const pageExistsInDB = propertyValues[page.id] != null;
const propertyChanged = JSON.stringify(previousValue) !== JSON.stringify(currentValue);
const propertyChanged =
JSON.stringify(previousValue) !== JSON.stringify(currentValueToSave);

if (pageExistsInDB && propertyChanged) {
propertyHasChanged = true;
propertyValues[page.id] = {
...propertyValues[page.id],
[propertyName]: currentValue,
[propertyName]: currentValueToSave,
};
changes.push({
property: propertyName,
previousValue,
currentValue,
currentValue: currentValueToEmit,
});
}

if (!pageExistsInDB) {
isNewPage = true;
propertyHasChanged = true;
propertyValues[page.id] = {
[propertyName]: currentValue,
[propertyName]: currentValueToSave,
};
changes.push({
property: propertyName,
previousValue,
currentValue,
currentValue: currentValueToEmit,
});
}
}
Expand Down
Loading