Skip to content

Commit ff5cef8

Browse files
authored
Microsoft Excel: fixing timeout listing folders (#14068)
1 parent aba7264 commit ff5cef8

File tree

6 files changed

+90
-40
lines changed

6 files changed

+90
-40
lines changed

components/microsoft_excel/actions/add-a-worksheet-tablerow/add-a-worksheet-tablerow.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import microsoftExcel from "../../microsoft_excel.app.mjs";
44
export default {
55
key: "microsoft_excel-add-a-worksheet-tablerow",
66
name: "Add A Worksheet Tablerow",
7-
version: "0.0.2",
7+
version: "0.0.3",
88
description: "Adds rows to the end of specific table. [See the documentation](https://learn.microsoft.com/en-us/graph/api/tablerowcollection-add?view=graph-rest-1.0&tabs=http)",
99
type: "action",
1010
props: {

components/microsoft_excel/actions/update-worksheet-tablerow/update-worksheet-tablerow.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import microsoftExcel from "../../microsoft_excel.app.mjs";
33
export default {
44
key: "microsoft_excel-update-worksheet-tablerow",
55
name: "Update Worksheet Tablerow",
6-
version: "0.0.2",
6+
version: "0.0.3",
77
description: "Update the properties of tablerow object. `(Only for work or school account)` [See the documentation](https://learn.microsoft.com/en-us/graph/api/tablerow-update?view=graph-rest-1.0&tabs=http)",
88
type: "action",
99
props: {

components/microsoft_excel/microsoft_excel.app.mjs

Lines changed: 83 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
label: "Folder Id",
1010
description: "The ID of the folder where the item is located.",
1111
async options() {
12-
const folders = await this.listFolders();
12+
const folders = await this.listFolderOptions();
1313
return [
1414
"root",
1515
...folders,
@@ -120,38 +120,6 @@ export default {
120120
path: `subscriptions/${hookId}`,
121121
});
122122
},
123-
async listFolders({
124-
folderId = null,
125-
prefix = "", ...args
126-
} = {}) {
127-
const foldersArray = [];
128-
const { value: items } = await this._makeRequest({
129-
path: folderId
130-
? `/me/drive/items/${folderId}/children`
131-
: "me/drive/root/children",
132-
...args,
133-
});
134-
135-
const folders = items.filter((item) => item.folder);
136-
for (const {
137-
id, name, folder: { childCount = null },
138-
} of folders) {
139-
foldersArray.push({
140-
value: id,
141-
label: `${prefix}${name}`,
142-
});
143-
144-
if (childCount) {
145-
const children = await this.listFolders({
146-
folderId: id,
147-
prefix: prefix + "-",
148-
});
149-
foldersArray.push(...children);
150-
}
151-
}
152-
153-
return foldersArray;
154-
},
155123
listItems({
156124
folderId, ...args
157125
}) {
@@ -196,5 +164,87 @@ export default {
196164
...args,
197165
});
198166
},
167+
batch(args = {}) {
168+
return this._makeRequest({
169+
method: "POST",
170+
path: "$batch",
171+
...args,
172+
});
173+
},
174+
async listFolderOptions({
175+
folderId = null, prefix = "", batchLimit = 20, ...args
176+
} = {}) {
177+
const options = [];
178+
const stack = [
179+
{
180+
folderId,
181+
prefix,
182+
},
183+
];
184+
const history = [];
185+
186+
try {
187+
while (stack.length) {
188+
const currentBatch = [];
189+
while (stack.length && currentBatch.length < batchLimit) {
190+
const {
191+
folderId,
192+
prefix,
193+
} = stack.shift();
194+
history.push({
195+
folderId,
196+
prefix,
197+
});
198+
currentBatch.push({
199+
id: folderId || "root",
200+
method: "GET",
201+
url: folderId
202+
? `/me/drive/items/${folderId}/children?$filter=folder ne null`
203+
: "/me/drive/root/children?$filter=folder ne null",
204+
});
205+
}
206+
207+
const { responses: batchResponses } =
208+
await this.batch({
209+
...args,
210+
data: {
211+
...args?.data,
212+
requests: currentBatch,
213+
},
214+
});
215+
216+
batchResponses.forEach(({
217+
id, status, body,
218+
}) => {
219+
if (status === 200) {
220+
body.value.forEach((item) => {
221+
const {
222+
id, name, folder: { childCount }, parentReference: { id: parentId },
223+
} = item;
224+
const prefix = history.find(({ folderId }) => folderId === parentId)?.prefix || "";
225+
const currentLabel = `${prefix}${name}`;
226+
options.push({
227+
value: id,
228+
label: currentLabel,
229+
});
230+
231+
if (childCount) {
232+
stack.push({
233+
folderId: id,
234+
prefix: `${currentLabel}/`,
235+
});
236+
}
237+
});
238+
} else {
239+
console.error(`Error in batch request ${id}:`, JSON.stringify(body));
240+
}
241+
});
242+
}
243+
} catch (error) {
244+
console.error("Error listing folders:", error);
245+
}
246+
247+
return options;
248+
},
199249
},
200250
};

components/microsoft_excel/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/microsoft_excel",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Pipedream Microsoft Excel Components",
55
"main": "microsoft_excel.app.mjs",
66
"keywords": [
@@ -13,7 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.5.1",
16+
"@pipedream/platform": "^3.0.1",
1717
"moment": "^2.29.4"
1818
}
1919
}

components/microsoft_excel/sources/new-item-updated/new-item-updated.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "microsoft_excel-new-item-updated",
88
name: "New Item Updated (Instant)",
99
description: "Emit new event when an item is updated.",
10-
version: "0.0.2",
10+
version: "0.0.3",
1111
type: "source",
1212
props: {
1313
microsoftExcel,

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)