Skip to content

Commit adee904

Browse files
authored
Merging pull request #17955
* Adding download PDF action * Improvements to download * Version bumps
1 parent 7c74563 commit adee904

File tree

7 files changed

+177
-5
lines changed

7 files changed

+177
-5
lines changed

components/tableau/actions/create-project/create-project.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "tableau-create-project",
55
name: "Create Project",
66
description: "Creates a project on the specified site. You can also create project hierarchies by creating a project under the specified parent project on the site. [See the documentation](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_projects.htm#create_project)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
app,
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import app from "../../tableau.app.mjs";
2+
import fs from "fs";
3+
import path from "path";
4+
5+
export default {
6+
key: "tableau-download-pdf",
7+
name: "Download PDF",
8+
description: "Downloads images of the sheets of a workbook as a PDF file. [See the documentation](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_workbooks_and_views.htm#download_workbook_pdf)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
siteId: {
14+
propDefinition: [
15+
app,
16+
"siteId",
17+
],
18+
},
19+
workbookId: {
20+
propDefinition: [
21+
app,
22+
"workbookId",
23+
({ siteId }) => ({
24+
siteId,
25+
}),
26+
],
27+
},
28+
maxAge: {
29+
type: "integer",
30+
label: "Max Age",
31+
description: "The maximum number of minutes a workbook PDF will be cached before being refreshed. Minimum interval is one minute",
32+
optional: true,
33+
min: 1,
34+
},
35+
orientation: {
36+
type: "string",
37+
label: "Page Orientation",
38+
description: "The orientation of the pages in the PDF file produced",
39+
options: [
40+
"Portrait",
41+
"Landscape",
42+
],
43+
default: "Portrait",
44+
optional: true,
45+
},
46+
pageType: {
47+
type: "string",
48+
label: "Page Type",
49+
description: "The type of page, which determines the page dimensions of the PDF file returned",
50+
options: [
51+
"A3",
52+
"A4",
53+
"A5",
54+
"B5",
55+
"Executive",
56+
"Folio",
57+
"Ledger",
58+
"Legal",
59+
"Letter",
60+
"Note",
61+
"Quarto",
62+
"Tabloid",
63+
],
64+
default: "Legal",
65+
optional: true,
66+
},
67+
vizHeight: {
68+
type: "integer",
69+
label: "Viz Height",
70+
description: "The height of the rendered PDF image in pixels that, along with `Viz Width`, determines its resolution and aspect ratio",
71+
optional: true,
72+
},
73+
vizWidth: {
74+
type: "integer",
75+
label: "Viz Width",
76+
description: "The width of the rendered PDF image in pixels that, along with `Viz Height`, determines its resolution and aspect ratio",
77+
optional: true,
78+
},
79+
outputFilename: {
80+
type: "string",
81+
label: "Output Filename",
82+
description: "The filename for the downloaded PDF file, which will be saved to the `/tmp` folder",
83+
default: "workbook.pdf",
84+
optional: true,
85+
},
86+
syncDir: {
87+
type: "dir",
88+
accessMode: "write",
89+
sync: true,
90+
},
91+
},
92+
async run({ $ }) {
93+
const {
94+
siteId,
95+
workbookId,
96+
maxAge,
97+
orientation,
98+
pageType,
99+
vizHeight,
100+
vizWidth,
101+
outputFilename,
102+
} = this;
103+
104+
const response = await this.app.downloadWorkbookPdf({
105+
$,
106+
siteId,
107+
workbookId,
108+
params: {
109+
"max-age-minutes": maxAge,
110+
orientation,
111+
"page-type": pageType,
112+
"viz-height": vizHeight,
113+
"viz-width": vizWidth,
114+
},
115+
responseType: "arraybuffer",
116+
});
117+
118+
// Write the PDF to the /tmp folder
119+
const filename = outputFilename || "workbook.pdf";
120+
const filePath = path.join("/tmp", filename);
121+
122+
await fs.promises.writeFile(filePath, Buffer.from(response));
123+
124+
$.export("$summary", `Successfully downloaded workbook PDF to \`${filePath}\``);
125+
return {
126+
filePath,
127+
fileContent: response,
128+
};
129+
},
130+
};

components/tableau/actions/query-projects/query-projects.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "tableau-query-projects",
66
name: "Query Projects",
77
description: "Returns a list of projects on the specified site. [See the documentation](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_projects.htm)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
app,

components/tableau/package.json

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

components/tableau/sources/label-created-instant/label-created-instant.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "tableau-label-created-instant",
77
name: "New Label Created (Instant)",
88
description: "Emit new event when a label is created in Tableau. [See the documentation](https://help.tableau.com/current/developer/webhooks/en-us/docs/webhooks-events-payload.html)",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "source",
1111
dedupe: "unique",
1212
methods: {

components/tableau/sources/workbook-created-instant/workbook-created-instant.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "tableau-workbook-created-instant",
77
name: "New Workbook Created (Instant)",
88
description: "Emit new event each time a new workbook is created in Tableau. [See the documentation](https://help.tableau.com/current/developer/webhooks/en-us/docs/webhooks-events-payload.html)",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "source",
1111
dedupe: "unique",
1212
methods: {

components/tableau/tableau.app.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@ export default {
4747
}));
4848
},
4949
},
50+
workbookId: {
51+
type: "string",
52+
label: "Workbook ID",
53+
description: "The ID of the workbook to download as PDF",
54+
async options({
55+
siteId, page,
56+
}) {
57+
if (!siteId) {
58+
return [];
59+
}
60+
const { workbooks: { workbook: data } } =
61+
await this.listWorkbooks({
62+
siteId,
63+
params: {
64+
pageSize: constants.DEFAULT_LIMIT,
65+
pageNumber: page + 1,
66+
},
67+
});
68+
return data?.map(({
69+
id: value, name: label,
70+
}) => ({
71+
label,
72+
value,
73+
})) || [];
74+
},
75+
},
5076
},
5177
methods: {
5278
getUrl(path) {
@@ -95,6 +121,22 @@ export default {
95121
...args,
96122
});
97123
},
124+
listWorkbooks({
125+
siteId, ...args
126+
}) {
127+
return this._makeRequest({
128+
path: `/sites/${siteId}/workbooks`,
129+
...args,
130+
});
131+
},
132+
downloadWorkbookPdf({
133+
siteId, workbookId, ...args
134+
}) {
135+
return this._makeRequest({
136+
path: `/sites/${siteId}/workbooks/${workbookId}/pdf`,
137+
...args,
138+
});
139+
},
98140
async *getIterations({
99141
resourcesFn, resourcesFnArgs, resourceName,
100142
max = constants.DEFAULT_MAX,

0 commit comments

Comments
 (0)