-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Google Docs Usability Audit / Improvements (#13960)
* versions, descriptions, summaries * update actions * new sources * pnpm-lock.yaml * update filename * add doc links * fix
- Loading branch information
1 parent
13522fb
commit 1b11b0b
Showing
13 changed files
with
322 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
components/google_docs/actions/create-document-from-text/create-document-from-text.mjs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
}, | ||
}, | ||
}; |
38 changes: 38 additions & 0 deletions
38
components/google_docs/sources/new-document-created/new-document-created.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)", | ||
description: "Emit new event when a new document is created in Google Docs. [See the documentation](https://developers.google.com/drive/api/reference/rest/v3/changes/watch)", | ||
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)); | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.