Skip to content

Commit 1b11b0b

Browse files
authored
Google Docs Usability Audit / Improvements (#13960)
* versions, descriptions, summaries * update actions * new sources * pnpm-lock.yaml * update filename * add doc links * fix
1 parent 13522fb commit 1b11b0b

File tree

13 files changed

+322
-148
lines changed

13 files changed

+322
-148
lines changed

components/google_docs/actions/append-image/append-image.mjs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import googleDocs from "../../google_docs.app.mjs";
33
export default {
44
key: "google_docs-append-image",
55
name: "Append Image to Document",
6-
description: "Appends an image to the end of a document. [See the docs](https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertInlineImageRequest)",
7-
version: "0.0.3",
6+
description: "Appends an image to the end of a document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertInlineImageRequest)",
7+
version: "0.0.4",
88
type: "action",
99
props: {
1010
googleDocs,
@@ -28,13 +28,11 @@ export default {
2828
},
2929
},
3030
async run({ $ }) {
31-
const image = {
31+
await this.googleDocs.appendImage(this.docId, {
3232
uri: this.imageUri,
33-
};
34-
const { data } = await this.googleDocs.appendImage(this.docId, image, this.appendAtBeginning);
35-
$.export("$summary", "Successfully appended image to doc");
36-
return {
37-
documentId: data.documentId,
38-
};
33+
}, this.appendAtBeginning);
34+
const doc = this.googleDocs.getDocument(this.docId);
35+
$.export("$summary", `Successfully appended image to document with ID: ${this.docId}`);
36+
return doc;
3937
},
4038
};

components/google_docs/actions/append-text/append-text.mjs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import googleDocs from "../../google_docs.app.mjs";
33
export default {
44
key: "google_docs-append-text",
55
name: "Append Text",
6-
description: "Append text to an existing document. [See the docs](https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertTextRequest)",
7-
version: "0.1.2",
6+
description: "Append text to an existing document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertTextRequest)",
7+
version: "0.1.3",
88
type: "action",
99
props: {
1010
googleDocs,
@@ -28,13 +28,11 @@ export default {
2828
},
2929
},
3030
async run({ $ }) {
31-
const text = {
31+
await this.googleDocs.insertText(this.docId, {
3232
text: this.text,
33-
};
34-
await this.googleDocs.insertText(this.docId, text, this.appendAtBeginning);
35-
$.export("$summary", "Successfully appended text to doc");
36-
return {
37-
documentId: this.docId,
38-
};
33+
}, this.appendAtBeginning);
34+
const doc = this.googleDocs.getDocument(this.docId);
35+
$.export("$summary", `Successfully appended text to document with ID: ${this.docId}`);
36+
return doc;
3937
},
4038
};

components/google_docs/actions/create-document-from-text/create-document-from-text.mjs

Lines changed: 0 additions & 30 deletions
This file was deleted.

components/google_docs/actions/create-document/create-document.mjs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,59 @@ import googleDocs from "../../google_docs.app.mjs";
33
export default {
44
key: "google_docs-create-document",
55
name: "Create a New Document",
6-
description: "Create a new, empty document. To add content after creating the document, pass the document ID exported by this step to the Append Text action. [See the docs](https://developers.google.com/docs/api/reference/rest/v1/documents/create)",
7-
version: "0.1.2",
6+
description: "Create a new document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/create)",
7+
version: "0.1.3",
88
type: "action",
99
props: {
1010
googleDocs,
11-
title: "string",
11+
title: {
12+
type: "string",
13+
label: "Title",
14+
description: "Title of the new document",
15+
},
16+
text: {
17+
propDefinition: [
18+
googleDocs,
19+
"text",
20+
],
21+
optional: true,
22+
},
23+
folderId: {
24+
propDefinition: [
25+
googleDocs,
26+
"folderId",
27+
],
28+
optional: true,
29+
},
1230
},
1331
async run({ $ }) {
14-
const createdDoc = await this.googleDocs.createEmptyDoc(this.title);
15-
$.export("$summary", "Successfully created doc");
16-
return createdDoc;
32+
// Create Doc
33+
const { documentId } = await this.googleDocs.createEmptyDoc(this.title);
34+
35+
// Insert text
36+
if (this.text) {
37+
await this.googleDocs.insertText(documentId, {
38+
text: this.text,
39+
});
40+
}
41+
42+
// Move file
43+
if (this.folderId) {
44+
// Get file to get parents to remove
45+
const file = await this.googleDocs.getFile(documentId);
46+
47+
// Move file, removing old parents, adding new parent folder
48+
await this.googleDocs.updateFile(documentId, {
49+
fields: "*",
50+
removeParents: file.parents.join(","),
51+
addParents: this.folderId,
52+
});
53+
}
54+
55+
// Get updated doc resource to return
56+
const doc = await this.googleDocs.getDocument(documentId);
57+
58+
$.export("$summary", `Successfully created document with ID: ${documentId}`);
59+
return doc;
1760
},
1861
};

components/google_docs/actions/get-document/get-document.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import googleDocs from "../../google_docs.app.mjs";
33
export default {
44
key: "google_docs-get-document",
55
name: "Get Document",
6-
description: "Get the contents of the latest version of a document. [See the docs](https://developers.google.com/docs/api/reference/rest/v1/documents/get)",
7-
version: "0.1.1",
6+
description: "Get the contents of the latest version of a document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/get)",
7+
version: "0.1.2",
88
type: "action",
99
props: {
1010
googleDocs,
@@ -15,7 +15,9 @@ export default {
1515
],
1616
},
1717
},
18-
async run() {
19-
return this.googleDocs.getDocument(this.docId);
18+
async run({ $ }) {
19+
const response = await this.googleDocs.getDocument(this.docId);
20+
$.export("$summary", `Successfully retrieved document with ID: ${this.docId}`);
21+
return response;
2022
},
2123
};

components/google_docs/actions/replace-image/replace-image.mjs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import googleDocs from "../../google_docs.app.mjs";
33
export default {
44
key: "google_docs-replace-image",
55
name: "Replace Image",
6-
description: "Replace image in a existing document. [See the docs](https://developers.google.com/docs/api/reference/rest/v1/documents/request#ReplaceImageRequest)",
7-
version: "0.0.3",
6+
description: "Replace image in a existing document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/request#ReplaceImageRequest)",
7+
version: "0.0.4",
88
type: "action",
99
props: {
1010
googleDocs,
@@ -37,9 +37,8 @@ export default {
3737
uri: this.imageUri,
3838
};
3939
await this.googleDocs.replaceImage(this.docId, image);
40-
$.export("$summary", "Successfully replaced image in doc");
41-
return {
42-
documentId: this.docId,
43-
};
40+
const doc = this.googleDocs.getDocument(this.docId);
41+
$.export("$summary", `Successfully replaced image in doc with ID: ${this.docId}`);
42+
return doc;
4443
},
4544
};

components/google_docs/actions/replace-text/replace-text.mjs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import googleDocs from "../../google_docs.app.mjs";
33
export default {
44
key: "google_docs-replace-text",
55
name: "Replace Text",
6-
description: "Replace all instances of matched text in a existing document. [See the docs](https://developers.google.com/docs/api/reference/rest/v1/documents/request#ReplaceAllTextRequest)",
7-
version: "0.0.3",
6+
description: "Replace all instances of matched text in an existing document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/request#ReplaceAllTextRequest)",
7+
version: "0.0.4",
88
type: "action",
99
props: {
1010
googleDocs,
@@ -45,9 +45,8 @@ export default {
4545
},
4646
};
4747
await this.googleDocs.replaceText(this.docId, text);
48-
$.export("$summary", "Successfully replaced text in doc");
49-
return {
50-
documentId: this.docId,
51-
};
48+
const doc = this.googleDocs.getDocument(this.docId);
49+
$.export("$summary", `Successfully replaced text in doc with ID: ${this.docId}`);
50+
return doc;
5251
},
5352
};

components/google_docs/google_docs.app.mjs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ export default {
99
docId: {
1010
type: "string",
1111
label: "Document",
12-
description: "Select a document or enter a custom expression to pass a value from a previous step (e.g., `{{steps.foo.$return_value.documentId}}`) or to manually enter a static ID (e.g., `1KuEN7k8jVP3Qi0_svM5OO8oEuiLkq0csihobF67eat8`).",
12+
description: "Search for and select a document. You can also use a custom expression to pass a value from a previous step (e.g., `{{steps.foo.$return_value.documentId}}`) or you can enter a static ID (e.g., `1KuEN7k8jVP3Qi0_svM5OO8oEuiLkq0csihobF67eat8`).",
13+
useQuery: true,
1314
async options({
14-
prevContext, driveId,
15+
prevContext, driveId, query,
1516
}) {
1617
const { nextPageToken } = prevContext;
17-
return this.listDocsOptions(driveId, nextPageToken);
18+
return this.listDocsOptions(driveId, query, nextPageToken);
1819
},
1920
},
2021
imageId: {
@@ -128,8 +129,11 @@ export default {
128129
async replaceImage(documentId, image) {
129130
return this._batchUpdate(documentId, "replaceImage", image);
130131
},
131-
async listDocsOptions(driveId, pageToken = null) {
132-
const q = "mimeType='application/vnd.google-apps.document'";
132+
async listDocsOptions(driveId, query, pageToken = null) {
133+
let q = "mimeType='application/vnd.google-apps.document'";
134+
if (query) {
135+
q = `${q} and name contains '${query}'`;
136+
}
133137
let request = {
134138
q,
135139
};

components/google_docs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/google_docs",
3-
"version": "0.3.6",
3+
"version": "0.4.0",
44
"description": "Pipedream Google_docs Components",
55
"main": "google_docs.app.mjs",
66
"keywords": [
@@ -13,6 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@googleapis/docs": "^0.2.0"
16+
"@googleapis/docs": "^3.3.0"
1717
}
1818
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import newFilesInstant from "../../../google_drive/sources/new-files-instant/new-files-instant.mjs";
2+
import googleDrive from "../../google_docs.app.mjs";
3+
import { MY_DRIVE_VALUE } from "../../../google_drive/common/constants.mjs";
4+
5+
export default {
6+
...newFilesInstant,
7+
props: {
8+
googleDrive,
9+
db: "$.service.db",
10+
http: "$.interface.http",
11+
timer: newFilesInstant.props.timer,
12+
folders: {
13+
propDefinition: [
14+
googleDrive,
15+
"folderId",
16+
],
17+
type: "string[]",
18+
description: "(Optional) The folders you want to watch. Leave blank to watch for any new document.",
19+
optional: true,
20+
},
21+
},
22+
hooks: {
23+
...newFilesInstant.hooks,
24+
async deploy() {
25+
// Emit sample records on the first run
26+
const docs = await this.getDocuments(5);
27+
await this.emitFiles(docs);
28+
},
29+
},
30+
methods: {
31+
...newFilesInstant.methods,
32+
getDriveId() {
33+
return googleDrive.methods.getDriveId(MY_DRIVE_VALUE);
34+
},
35+
shouldProcess(file) {
36+
return (
37+
file.mimeType.includes("document") &&
38+
newFilesInstant.methods.shouldProcess.bind(this)(file)
39+
);
40+
},
41+
getDocumentsFromFolderOpts(folderId) {
42+
const mimeQuery = "mimeType = 'application/vnd.google-apps.document'";
43+
let opts = {
44+
q: `${mimeQuery} and parents in '${folderId}' and trashed = false`,
45+
};
46+
return opts;
47+
},
48+
async getDocumentsFromFiles(files, limit) {
49+
return files.reduce(async (acc, file) => {
50+
const docs = await acc;
51+
const fileInfo = await this.googleDrive.getFile(file.id);
52+
return docs.length >= limit
53+
? docs
54+
: docs.concat(fileInfo);
55+
}, []);
56+
},
57+
async getDocuments(limit) {
58+
const foldersIds = this.folders;
59+
60+
if (!foldersIds?.length) {
61+
const opts = this.getDocumentsFromFolderOpts("root");
62+
const { files } = await this.googleDrive.listFilesInPage(null, opts);
63+
return this.getDocumentsFromFiles(files, limit);
64+
}
65+
66+
return foldersIds.reduce(async (docs, folderId) => {
67+
const opts = this.getDocumentsFromFolderOpts(folderId);
68+
const { files } = await this.googleDrive.listFilesInPage(null, opts);
69+
const nextDocuments = await this.getDocumentsFromFiles(files, limit);
70+
return (await docs).concat(nextDocuments);
71+
}, []);
72+
},
73+
async emitFiles(files) {
74+
for (const file of files) {
75+
if (!this.shouldProcess(file)) {
76+
continue;
77+
}
78+
const doc = await this.googleDrive.getDocument(file.id);
79+
this.$emit(doc, this.generateMeta(doc));
80+
}
81+
},
82+
},
83+
};

0 commit comments

Comments
 (0)