Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Google Docs Usability Audit / Improvements #13960

Merged
merged 7 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 7 additions & 9 deletions components/google_docs/actions/append-image/append-image.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import googleDocs from "../../google_docs.app.mjs";
export default {
key: "google_docs-append-image",
name: "Append Image to Document",
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)",
version: "0.0.3",
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)",
version: "0.0.4",
type: "action",
props: {
googleDocs,
Expand All @@ -28,13 +28,11 @@ export default {
},
},
async run({ $ }) {
const image = {
await this.googleDocs.appendImage(this.docId, {
uri: this.imageUri,
};
const { data } = await this.googleDocs.appendImage(this.docId, image, this.appendAtBeginning);
$.export("$summary", "Successfully appended image to doc");
return {
documentId: data.documentId,
};
}, this.appendAtBeginning);
const doc = this.googleDocs.getDocument(this.docId);
$.export("$summary", `Successfully appended image to document with ID: ${this.docId}`);
return doc;
},
};
16 changes: 7 additions & 9 deletions components/google_docs/actions/append-text/append-text.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import googleDocs from "../../google_docs.app.mjs";
export default {
key: "google_docs-append-text",
name: "Append Text",
description: "Append text to an existing document. [See the docs](https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertTextRequest)",
version: "0.1.2",
description: "Append text to an existing document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/request#InsertTextRequest)",
version: "0.1.3",
type: "action",
props: {
googleDocs,
Expand All @@ -28,13 +28,11 @@ export default {
},
},
async run({ $ }) {
const text = {
await this.googleDocs.insertText(this.docId, {
text: this.text,
};
await this.googleDocs.insertText(this.docId, text, this.appendAtBeginning);
$.export("$summary", "Successfully appended text to doc");
return {
documentId: this.docId,
};
}, this.appendAtBeginning);
const doc = this.googleDocs.getDocument(this.docId);
$.export("$summary", `Successfully appended text to document with ID: ${this.docId}`);
return doc;
},
};

This file was deleted.

55 changes: 49 additions & 6 deletions components/google_docs/actions/create-document/create-document.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,59 @@ import googleDocs from "../../google_docs.app.mjs";
export default {
key: "google_docs-create-document",
name: "Create a New Document",
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)",
version: "0.1.2",
description: "Create a new document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/create)",
version: "0.1.3",
type: "action",
props: {
googleDocs,
title: "string",
title: {
type: "string",
label: "Title",
description: "Title of the new document",
},
text: {
propDefinition: [
googleDocs,
"text",
],
optional: true,
},
folderId: {
propDefinition: [
googleDocs,
"folderId",
],
optional: true,
},
},
async run({ $ }) {
const createdDoc = await this.googleDocs.createEmptyDoc(this.title);
$.export("$summary", "Successfully created doc");
return createdDoc;
// Create Doc
const { documentId } = await this.googleDocs.createEmptyDoc(this.title);

// Insert text
if (this.text) {
await this.googleDocs.insertText(documentId, {
text: this.text,
});
}

// Move file
if (this.folderId) {
// Get file to get parents to remove
const file = await this.googleDocs.getFile(documentId);

// Move file, removing old parents, adding new parent folder
await this.googleDocs.updateFile(documentId, {
fields: "*",
removeParents: file.parents.join(","),
addParents: this.folderId,
});
}

// Get updated doc resource to return
const doc = await this.googleDocs.getDocument(documentId);

$.export("$summary", `Successfully created document with ID: ${documentId}`);
return doc;
},
};
10 changes: 6 additions & 4 deletions components/google_docs/actions/get-document/get-document.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import googleDocs from "../../google_docs.app.mjs";
export default {
key: "google_docs-get-document",
name: "Get Document",
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)",
version: "0.1.1",
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)",
version: "0.1.2",
type: "action",
props: {
googleDocs,
Expand All @@ -15,7 +15,9 @@ export default {
],
},
},
async run() {
return this.googleDocs.getDocument(this.docId);
async run({ $ }) {
const response = await this.googleDocs.getDocument(this.docId);
$.export("$summary", `Successfully retrieved document with ID: ${this.docId}`);
return response;
},
};
11 changes: 5 additions & 6 deletions components/google_docs/actions/replace-image/replace-image.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import googleDocs from "../../google_docs.app.mjs";
export default {
key: "google_docs-replace-image",
name: "Replace Image",
description: "Replace image in a existing document. [See the docs](https://developers.google.com/docs/api/reference/rest/v1/documents/request#ReplaceImageRequest)",
version: "0.0.3",
description: "Replace image in a existing document. [See the documentation](https://developers.google.com/docs/api/reference/rest/v1/documents/request#ReplaceImageRequest)",
version: "0.0.4",
type: "action",
props: {
googleDocs,
Expand Down Expand Up @@ -37,9 +37,8 @@ export default {
uri: this.imageUri,
};
await this.googleDocs.replaceImage(this.docId, image);
$.export("$summary", "Successfully replaced image in doc");
return {
documentId: this.docId,
};
const doc = this.googleDocs.getDocument(this.docId);
$.export("$summary", `Successfully replaced image in doc with ID: ${this.docId}`);
return doc;
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
},
};
11 changes: 5 additions & 6 deletions components/google_docs/actions/replace-text/replace-text.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import googleDocs from "../../google_docs.app.mjs";
export default {
key: "google_docs-replace-text",
name: "Replace Text",
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)",
version: "0.0.3",
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)",
version: "0.0.4",
type: "action",
props: {
googleDocs,
Expand Down Expand Up @@ -45,9 +45,8 @@ export default {
},
};
await this.googleDocs.replaceText(this.docId, text);
$.export("$summary", "Successfully replaced text in doc");
return {
documentId: this.docId,
};
const doc = this.googleDocs.getDocument(this.docId);
$.export("$summary", `Successfully replaced text in doc with ID: ${this.docId}`);
return doc;
},
};
14 changes: 9 additions & 5 deletions components/google_docs/google_docs.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export default {
docId: {
type: "string",
label: "Document",
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`).",
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`).",
useQuery: true,
async options({
prevContext, driveId,
prevContext, driveId, query,
}) {
const { nextPageToken } = prevContext;
return this.listDocsOptions(driveId, nextPageToken);
return this.listDocsOptions(driveId, query, nextPageToken);
},
},
imageId: {
Expand Down Expand Up @@ -128,8 +129,11 @@ export default {
async replaceImage(documentId, image) {
return this._batchUpdate(documentId, "replaceImage", image);
},
async listDocsOptions(driveId, pageToken = null) {
const q = "mimeType='application/vnd.google-apps.document'";
async listDocsOptions(driveId, query, pageToken = null) {
let q = "mimeType='application/vnd.google-apps.document'";
if (query) {
q = `${q} and name contains '${query}'`;
}
let request = {
q,
};
Expand Down
4 changes: 2 additions & 2 deletions components/google_docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/google_docs",
"version": "0.3.6",
"version": "0.4.0",
"description": "Pipedream Google_docs Components",
"main": "google_docs.app.mjs",
"keywords": [
Expand All @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"@googleapis/docs": "^0.2.0"
"@googleapis/docs": "^3.3.0"
}
}
83 changes: 83 additions & 0 deletions components/google_docs/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import newFilesInstant from "../../../google_drive/sources/new-files-instant/new-files-instant.mjs";
import googleDrive from "../../google_docs.app.mjs";
import { MY_DRIVE_VALUE } from "../../../google_drive/common/constants.mjs";

export default {
...newFilesInstant,
props: {
googleDrive,
db: "$.service.db",
http: "$.interface.http",
timer: newFilesInstant.props.timer,
folders: {
propDefinition: [
googleDrive,
"folderId",
],
type: "string[]",
description: "(Optional) The folders you want to watch. Leave blank to watch for any new document.",
optional: true,
},
},
hooks: {
...newFilesInstant.hooks,
async deploy() {
// Emit sample records on the first run
const docs = await this.getDocuments(5);
await this.emitFiles(docs);
},
},
methods: {
...newFilesInstant.methods,
getDriveId() {
return googleDrive.methods.getDriveId(MY_DRIVE_VALUE);
},
shouldProcess(file) {
return (
file.mimeType.includes("document") &&
newFilesInstant.methods.shouldProcess.bind(this)(file)
);
},
getDocumentsFromFolderOpts(folderId) {
const mimeQuery = "mimeType = 'application/vnd.google-apps.document'";
let opts = {
q: `${mimeQuery} and parents in '${folderId}' and trashed = false`,
};
return opts;
},
async getDocumentsFromFiles(files, limit) {
return files.reduce(async (acc, file) => {
const docs = await acc;
const fileInfo = await this.googleDrive.getFile(file.id);
return docs.length >= limit
? docs
: docs.concat(fileInfo);
}, []);
},
async getDocuments(limit) {
const foldersIds = this.folders;

if (!foldersIds.length) {
const opts = this.getDocumentsFromFolderOpts("root");
const { files } = await this.googleDrive.listFilesInPage(null, opts);
return this.getDocumentsFromFiles(files, limit);
}

return foldersIds.reduce(async (docs, folderId) => {
const opts = this.getDocumentsFromFolderOpts(folderId);
const { files } = await this.googleDrive.listFilesInPage(null, opts);
const nextDocuments = await this.getDocumentsFromFiles(files, limit);
return (await docs).concat(nextDocuments);
}, []);
},
async emitFiles(files) {
for (const file of files) {
if (!this.shouldProcess(file)) {
continue;
}
const doc = await this.googleDrive.getDocument(file.id);
this.$emit(doc, this.generateMeta(doc));
}
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import common from "../common/base.mjs";

export default {
...common,
key: "google_docs-new-document-created",
name: "New Document Created (Instant)",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these sources be labeled as instant? Aren't they timer-based?

Also, can we include docs links in the descriptions?

Copy link
Collaborator Author

@michelle0927 michelle0927 Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • These sources are subscription based. They inherit from Google Drive, like I mentioned in the gsheet. new-files-instant. There is a timer though to renew the subscription.
  • Added doc links!

description: "Emit new event when a new document is created in Google Docs",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
generateMeta(doc) {
return {
id: doc.documentId,
summary: `New Document: ${doc.documentId}`,
ts: Date.now(),
};
},
async processChanges() {
const lastFileCreatedTime = this._getLastFileCreatedTime();
const timeString = new Date(lastFileCreatedTime).toISOString();

const args = this.getListFilesOpts({
q: `mimeType != "application/vnd.google-apps.folder" and createdTime > "${timeString}" and trashed = false`,
orderBy: "createdTime desc",
fields: "*",
});

const { files } = await this.googleDrive.listFilesInPage(null, args);
if (!files?.length) {
return;
}
await this.emitFiles(files);
this._setLastFileCreatedTime(Date.parse(files[0].createdTime));
},
},
};
Loading
Loading