Skip to content

Commit 1977f54

Browse files
committed
[FIX] Google Sheets - Using the sub-agent to create and populate a sheet returns errors
1 parent ebbc0e6 commit 1977f54

File tree

4 files changed

+45
-34
lines changed

4 files changed

+45
-34
lines changed

components/google_drive/common/utils.mjs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,17 @@ function truncatePath(pathArr) {
104104
*/
105105
function buildFilePaths(files = [], folders = []) {
106106
const folderIdToFolder = folders.reduce((acc, cur) => {
107-
acc[cur.id] = cur;
107+
if (cur?.id) {
108+
acc[cur.id] = cur;
109+
}
108110
return acc;
109111
}, {});
110112
const paths = {};
111113
// Recursive function that returns an array of file `id`s representing the path to a file if
112114
// requisite parent folders are available (in `file.parents`) to the requesting user, or an array
113115
// containing the file ID otherwise
114116
const pathToFile = (file) => {
115-
if (!file) {
117+
if (!file?.id) {
116118
// unretrieved folder or root folder
117119
return [];
118120
}
@@ -139,7 +141,9 @@ function buildFilePaths(files = [], folders = []) {
139141
];
140142
};
141143
files.forEach((file) => {
142-
paths[file.id] = pathToFile(file);
144+
if (file?.id) {
145+
paths[file.id] = pathToFile(file);
146+
}
143147
});
144148
return paths;
145149
}
@@ -154,7 +158,9 @@ function buildFilePaths(files = [], folders = []) {
154158
*/
155159
function buildFileNamePaths(files = [], folders = []) {
156160
const fileIdToFile = files.concat(folders).reduce((acc, cur) => {
157-
acc[cur.id] = cur;
161+
if (cur?.id) {
162+
acc[cur.id] = cur;
163+
}
158164
return acc;
159165
}, {});
160166
const fileIdToPath = buildFilePaths(files, folders);

components/google_drive/google_drive.app.mjs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,18 @@ export default {
127127
return [];
128128
}
129129
let parentFolders = await Promise.all(
130-
file.parents.map((parentId) => this.getFile(parentId, {
130+
(file.parents || []).map((parentId) => this.getFile(parentId, {
131131
fields: "id,name",
132132
})),
133133
);
134-
return parentFolders.map(({
135-
id, name,
136-
}) => ({
137-
value: id,
138-
label: name,
139-
}));
134+
return parentFolders
135+
.filter((folder) => folder?.id)
136+
.map(({
137+
id, name,
138+
}) => ({
139+
value: id,
140+
label: name,
141+
}));
140142
},
141143
},
142144
updateTypes: {
@@ -475,7 +477,7 @@ export default {
475477
},
476478
async _listDriveOptions(pageToken, myDrive = true) {
477479
const {
478-
drives,
480+
drives = [],
479481
nextPageToken,
480482
} = await this.listDrivesInPage(pageToken);
481483

@@ -493,10 +495,12 @@ export default {
493495
]
494496
: [];
495497
for (const d of drives) {
496-
options.push({
497-
label: d.name,
498-
value: d.id,
499-
});
498+
if (d?.id) {
499+
options.push({
500+
label: d.name,
501+
value: d.id,
502+
});
503+
}
500504
}
501505
return {
502506
options,
@@ -546,16 +550,18 @@ export default {
546550
*/
547551
async listFilesOptions(pageToken, extraOpts = {}) {
548552
const {
549-
files,
553+
files = [],
550554
nextPageToken,
551555
} = await this.listFilesInPage(
552556
pageToken,
553557
extraOpts,
554558
);
555-
const options = files.map((file) => ({
556-
label: file.name,
557-
value: file.id,
558-
}));
559+
const options = files
560+
.filter((file) => file?.id)
561+
.map((file) => ({
562+
label: file.name,
563+
value: file.id,
564+
}));
559565
return {
560566
options,
561567
context: {
@@ -611,19 +617,21 @@ export default {
611617
opts,
612618
);
613619
const [
614-
{ files: folders },
620+
{ files: folders = [] },
615621
{
616-
files, nextPageToken,
622+
files = [], nextPageToken,
617623
},
618624
] = await Promise.all([
619625
foldersPromise,
620626
filesPromise,
621627
]);
622628
const filePaths = this.getFilePaths(files, folders);
623-
const options = files.map((file) => ({
624-
label: filePaths[file.id],
625-
value: file.id,
626-
}));
629+
const options = files
630+
.filter((file) => file?.id)
631+
.map((file) => ({
632+
label: filePaths[file.id],
633+
value: file.id,
634+
}));
627635
return {
628636
options,
629637
context: {

components/google_drive/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/google_drive",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Pipedream Google_drive Components",
55
"main": "google_drive.app.mjs",
66
"keywords": [

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)