Skip to content

Commit d7da6c3

Browse files
committed
[Components] columns_ai - Added new action components
1 parent 0b30eb9 commit d7da6c3

File tree

6 files changed

+481
-7
lines changed

6 files changed

+481
-7
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import { ChartType } from "columns-graph-model";
2+
import app from "../../columns_ai.app.mjs";
3+
import utils from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "columns_ai-build-graph-from-scratch",
7+
name: "Build Graph From Scratch",
8+
description: "Builds a graph object from scratch and publishes it. [See the documentation](https://github.com/varchar-io/vaas?tab=readme-ov-file#basic-usage)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
name: {
14+
propDefinition: [
15+
app,
16+
"name",
17+
],
18+
},
19+
chartType: {
20+
type: "string",
21+
label: "Chart Type",
22+
description: "The type of chart to construct",
23+
async options() {
24+
return [
25+
{
26+
label: "Bar",
27+
value: ChartType.BAR,
28+
},
29+
{
30+
label: "Pie",
31+
value: ChartType.PIE,
32+
},
33+
{
34+
label: "Doughnut",
35+
value: ChartType.DOUGHNUT,
36+
},
37+
{
38+
label: "Line",
39+
value: ChartType.LINE,
40+
},
41+
{
42+
label: "Area",
43+
value: ChartType.AREA,
44+
},
45+
{
46+
label: "Scatter",
47+
value: ChartType.SCATTER,
48+
},
49+
{
50+
label: "Bar Race",
51+
value: ChartType.BAR_RACE,
52+
},
53+
{
54+
label: "Boxplot",
55+
value: ChartType.BOXPLOT,
56+
},
57+
{
58+
label: "Column",
59+
value: ChartType.COLUMN,
60+
},
61+
{
62+
label: "Dot",
63+
value: ChartType.DOT,
64+
},
65+
{
66+
label: "Gauge",
67+
value: ChartType.GAUGE,
68+
},
69+
{
70+
label: "Map",
71+
value: ChartType.MAP,
72+
},
73+
{
74+
label: "Radar",
75+
value: ChartType.RADAR,
76+
},
77+
{
78+
label: "Summary",
79+
value: ChartType.SUMMARY,
80+
},
81+
{
82+
label: "Table",
83+
value: ChartType.TABLE,
84+
},
85+
{
86+
label: "Timeline",
87+
value: ChartType.TIMELINE,
88+
},
89+
{
90+
label: "Timeline Area",
91+
value: ChartType.TIMELINE_AREA,
92+
},
93+
{
94+
label: "Timeline Bar",
95+
value: ChartType.TIMELINE_BAR,
96+
},
97+
{
98+
label: "Tree",
99+
value: ChartType.TREE,
100+
},
101+
{
102+
label: "Wordcloud",
103+
value: ChartType.WORDCLOUD,
104+
},
105+
];
106+
},
107+
},
108+
keys: {
109+
propDefinition: [
110+
app,
111+
"keys",
112+
],
113+
},
114+
metrics: {
115+
propDefinition: [
116+
app,
117+
"metrics",
118+
],
119+
},
120+
rows: {
121+
propDefinition: [
122+
app,
123+
"rows",
124+
],
125+
},
126+
},
127+
async run({ $ }) {
128+
const {
129+
app,
130+
name,
131+
chartType,
132+
keys,
133+
metrics,
134+
rows,
135+
} = this;
136+
137+
const graph = await app.createGraphFromScratch({
138+
chartType,
139+
keys,
140+
metrics,
141+
rows: utils.parseArray(rows),
142+
});
143+
144+
const response = await app.publishGraph({
145+
name,
146+
graph,
147+
});
148+
149+
$.export("$summary", "Successfully built and published the grap from scratch.");
150+
return response;
151+
},
152+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import app from "../../columns_ai.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "columns_ai-build-graph-from-template",
6+
name: "Build Graph From Template",
7+
description: "Builds a graph object from a template and publishes it. [See the documentation](https://github.com/varchar-io/vaas?tab=readme-ov-file#basic-usage).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
name: {
13+
propDefinition: [
14+
app,
15+
"name",
16+
],
17+
},
18+
visualId: {
19+
type: "string",
20+
label: "Visual ID",
21+
description: "The ID of an existing graph template on Columns. Eg. `U6tALuJ3cTdPFw` wher it can be taken from the URL `https://columns.ai/visual/view/U6tALuJ3cTdPFw`.",
22+
},
23+
keys: {
24+
propDefinition: [
25+
app,
26+
"keys",
27+
],
28+
},
29+
metrics: {
30+
propDefinition: [
31+
app,
32+
"metrics",
33+
],
34+
},
35+
rows: {
36+
propDefinition: [
37+
app,
38+
"rows",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const {
44+
app,
45+
name,
46+
visualId,
47+
keys,
48+
metrics,
49+
rows,
50+
} = this;
51+
52+
const graph = await app.createGraphFromTemplate({
53+
visualId,
54+
keys,
55+
metrics,
56+
rows: utils.parseArray(rows),
57+
});
58+
59+
const response = await app.publishGraph({
60+
name,
61+
graph,
62+
});
63+
64+
$.export("$summary", "Successfully built and published the grap from template.");
65+
return response;
66+
},
67+
};
Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,65 @@
1+
import { ChartType } from "columns-graph-model";
2+
import { Columns } from "columns-sdk";
3+
14
export default {
25
type: "app",
36
app: "columns_ai",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
name: {
9+
type: "string",
10+
label: "Graph Name",
11+
description: "The name of the graph",
12+
},
13+
keys: {
14+
type: "string[]",
15+
label: "Keys",
16+
description: "An array of keys for the data rows.",
17+
},
18+
metrics: {
19+
type: "string[]",
20+
label: "Metrics",
21+
description: "An array of metrics for the data rows.",
22+
},
23+
rows: {
24+
type: "string[]",
25+
label: "Rows",
26+
description: "An array of data objects, each object as a JSON string. Eg. `[{ \"value\": 4000, \"state\": \"US\", \"parent\": null }, { \"value\": 121, \"state\": \"AL\", \"parent\": \"US\" }, { \"value\": 34, \"state\": \"AK\", \"parent\": \"US\"}]`.",
27+
},
28+
},
529
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
30+
getColumns() {
31+
return new Columns(this.$auth.api_key);
32+
},
33+
async createGraphFromScratch({
34+
keys = [], metrics = [], rows = [], chartType = ChartType.COLUMN,
35+
} = {}) {
36+
const columns = this.getColumns();
37+
const data = columns.data(keys, metrics, rows);
38+
const graph = columns.graph(data);
39+
40+
graph.type = chartType;
41+
42+
return graph;
43+
},
44+
async createGraphFromTemplate({
45+
visualId, keys = [], metrics = [], rows = [],
46+
} = {}) {
47+
const columns = this.getColumns();
48+
const graph = await columns.template(visualId);
49+
50+
if (!graph) {
51+
throw new Error(`Failed to load template from Columns: ${visualId}`);
52+
}
53+
54+
graph.data = columns.data(keys, metrics, rows);
55+
56+
return graph;
57+
},
58+
publishGraph({
59+
name, graph,
60+
} = {}) {
61+
const columns = this.getColumns();
62+
return columns.publish(name, graph);
963
},
1064
},
1165
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
3+
const parseJson = (input) => {
4+
const parse = (value) => {
5+
if (typeof(value) === "string") {
6+
try {
7+
return parseJson(JSON.parse(value));
8+
} catch (e) {
9+
return value;
10+
}
11+
} else if (typeof(value) === "object" && value !== null) {
12+
return Object.entries(value)
13+
.reduce((acc, [
14+
key,
15+
val,
16+
]) => Object.assign(acc, {
17+
[key]: parse(val),
18+
}), {});
19+
}
20+
return value;
21+
};
22+
23+
return parse(input);
24+
};
25+
26+
function parseArray(value) {
27+
try {
28+
if (!value) {
29+
return [];
30+
}
31+
32+
if (Array.isArray(value)) {
33+
return value;
34+
}
35+
36+
const parsedValue = JSON.parse(value);
37+
38+
if (!Array.isArray(parsedValue)) {
39+
throw new Error("Not an array");
40+
}
41+
42+
return parsedValue;
43+
44+
} catch (e) {
45+
throw new ConfigurationError("Make sure the custom expression contains a valid array object");
46+
}
47+
}
48+
49+
export default {
50+
parseArray: (value) => parseArray(value).map(parseJson),
51+
};

components/columns_ai/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/columns_ai",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Columns Ai Components",
55
"main": "columns_ai.app.mjs",
66
"keywords": [
@@ -11,5 +11,9 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"columns-graph-model": "^1.1.4",
17+
"columns-sdk": "^0.0.6"
1418
}
15-
}
19+
}

0 commit comments

Comments
 (0)