Skip to content

Commit 25274cb

Browse files
authored
Miro Custom App - New Source item-position-changed (#8643)
* new source * pnpm-lock.yaml
1 parent d1a9c00 commit 25274cb

File tree

4 files changed

+117
-4
lines changed

4 files changed

+117
-4
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/miro_custom_app",
3-
"version": "0.0.3",
3+
"version": "0.1.0",
44
"description": "Pipedream Miro Developer App Components",
5-
"main": "dist/app/miro_custom_app.app.mjs",
5+
"main": "miro_custom_app.app.mjs",
66
"keywords": [
77
"pipedream",
88
"miro_custom_app"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/miro_custom_app",
1211
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^1.5.1"
1517
}
1618
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import miro from "../../miro_custom_app.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
props: {
6+
miro,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
methods: {
16+
async *paginate({
17+
resourceFn, args = {},
18+
}) {
19+
args = {
20+
...args,
21+
params: {
22+
...args.params,
23+
limit: 50,
24+
},
25+
};
26+
let total = 0;
27+
do {
28+
const {
29+
data, cursor,
30+
} = await resourceFn(args);
31+
for (const item of data) {
32+
yield item;
33+
}
34+
total = data?.length;
35+
args.params.cursor = cursor;
36+
} while (total === args.params.limit);
37+
},
38+
generateMeta() {
39+
throw new Error("generateMeta is not implemented");
40+
},
41+
},
42+
};
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "miro_custom_app-item-position-changed",
6+
name: "Item Position Changed",
7+
description: "Emit new event when an item's position changes in a Miro Custom App.",
8+
version: "0.0.1",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
...common.props,
13+
teamId: {
14+
propDefinition: [
15+
common.props.miro,
16+
"teamId",
17+
],
18+
},
19+
boardId: {
20+
propDefinition: [
21+
common.props.miro,
22+
"boardId",
23+
({ teamId }) => ({
24+
teamId,
25+
}),
26+
],
27+
},
28+
},
29+
methods: {
30+
...common.methods,
31+
_getPositions() {
32+
return this.db.get("positions") || {};
33+
},
34+
_setPositions(positions) {
35+
this.db.set("positions", positions);
36+
},
37+
generateMeta(item) {
38+
const ts = Date.parse(item.modifiedAt);
39+
return {
40+
id: `${item.id}-${ts}`,
41+
summary: `Item ${item.id} position changed`,
42+
ts,
43+
};
44+
},
45+
},
46+
async run() {
47+
const positions = this._getPositions();
48+
const newPositions = {};
49+
const items = this.paginate({
50+
resourceFn: this.miro.listItems,
51+
args: {
52+
boardId: this.boardId,
53+
},
54+
});
55+
for await (const item of items) {
56+
const position = JSON.stringify(item.position);
57+
if (positions[item.id] && positions[item.id] !== position) {
58+
const meta = this.generateMeta(item);
59+
this.$emit(item, meta);
60+
}
61+
newPositions[item.id] = position;
62+
}
63+
64+
this._setPositions(newPositions);
65+
},
66+
};

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)