Skip to content

Commit db76106

Browse files
committed
add new actions
1 parent 68ee470 commit db76106

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import app from "../../google_docs.app.mjs";
2+
import common from "@pipedream/google_drive/actions/create-file-from-template/create-file-from-template.mjs";
3+
4+
import utils from "../../common/utils.mjs";
5+
6+
const {
7+
// eslint-disable-next-line no-unused-vars
8+
name, description, type, ...others
9+
} = common;
10+
const props = utils.adjustPropDefinitions(others.props, app);
11+
12+
export default {
13+
...others,
14+
key: "google_docs-create-document-from-template",
15+
name: "Create New Document From Template",
16+
version: "0.0.1",
17+
description,
18+
type,
19+
props: {
20+
googleDrive: app,
21+
...props,
22+
templateId: {
23+
propDefinition: [
24+
app,
25+
"docId",
26+
],
27+
description:
28+
"Select the template document you'd like to use as the template, or use a custom expression to reference a document ID from a previous step. Template documents should contain placeholders in the format `{{xyz}}`.",
29+
},
30+
},
31+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import app from "../../google_docs.app.mjs";
2+
import common from "@pipedream/google_drive/actions/find-file/find-file.mjs";
3+
import { getListFilesOpts } from "@pipedream/google_drive/common/utils.mjs";
4+
5+
import utils from "../../common/utils.mjs";
6+
7+
const {
8+
// eslint-disable-next-line no-unused-vars
9+
name, description, type, ...others
10+
} = common;
11+
const props = utils.adjustPropDefinitions(others.props, app);
12+
13+
export default {
14+
...others,
15+
key: "google_docs-find-document",
16+
name: "Find Document",
17+
version: "0.0.1",
18+
description,
19+
type,
20+
props: {
21+
googleDrive: app,
22+
...props,
23+
},
24+
async run({ $ }) {
25+
const q = this.getQuery();
26+
const opts = getListFilesOpts(this.drive, {
27+
q,
28+
});
29+
const files = (await this.googleDrive.listFilesInPage(null, opts)).files?.filter(({ mimeType }) => mimeType === "application/vnd.google-apps.document") || [];
30+
31+
$.export("$summary", `Successfully found ${files.length} file${files.length === 1
32+
? ""
33+
: "s"} with the query "${q}"`);
34+
return files;
35+
},
36+
};

components/google_docs/common/utils.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,49 @@ function addTextContentToDocument(response) {
2020
};
2121
}
2222

23+
function adjustPropDefinitions(props, app) {
24+
return Object.fromEntries(
25+
Object.entries(props).map(([
26+
key,
27+
prop,
28+
]) => {
29+
if (typeof prop === "string") return [
30+
key,
31+
prop,
32+
];
33+
const {
34+
propDefinition, ...otherValues
35+
} = prop;
36+
if (propDefinition) {
37+
const [
38+
, ...otherDefs
39+
] = propDefinition;
40+
return [
41+
key,
42+
{
43+
propDefinition: [
44+
app,
45+
...otherDefs,
46+
],
47+
...otherValues,
48+
},
49+
];
50+
}
51+
return [
52+
key,
53+
otherValues.type === "app"
54+
? null
55+
: otherValues,
56+
];
57+
})
58+
.filter(([
59+
, value,
60+
]) => value),
61+
);
62+
}
63+
2364
export default {
2465
getTextContentFromDocument,
2566
addTextContentToDocument,
67+
adjustPropDefinitions,
2668
};

0 commit comments

Comments
 (0)