-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Components] columns_ai - Added new action components #14469
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
152 changes: 152 additions & 0 deletions
152
components/columns_ai/actions/build-graph-from-scratch/build-graph-from-scratch.mjs
This file contains hidden or 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,152 @@ | ||
| import { ChartType } from "columns-graph-model"; | ||
| import app from "../../columns_ai.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "columns_ai-build-graph-from-scratch", | ||
| name: "Build Graph From Scratch", | ||
| 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)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| name: { | ||
| propDefinition: [ | ||
| app, | ||
| "name", | ||
| ], | ||
| }, | ||
| chartType: { | ||
| type: "string", | ||
| label: "Chart Type", | ||
| description: "The type of chart to construct", | ||
| async options() { | ||
| return [ | ||
| { | ||
| label: "Bar", | ||
| value: ChartType.BAR, | ||
| }, | ||
| { | ||
| label: "Pie", | ||
| value: ChartType.PIE, | ||
| }, | ||
| { | ||
| label: "Doughnut", | ||
| value: ChartType.DOUGHNUT, | ||
| }, | ||
| { | ||
| label: "Line", | ||
| value: ChartType.LINE, | ||
| }, | ||
| { | ||
| label: "Area", | ||
| value: ChartType.AREA, | ||
| }, | ||
| { | ||
| label: "Scatter", | ||
| value: ChartType.SCATTER, | ||
| }, | ||
| { | ||
| label: "Bar Race", | ||
| value: ChartType.BAR_RACE, | ||
| }, | ||
| { | ||
| label: "Boxplot", | ||
| value: ChartType.BOXPLOT, | ||
| }, | ||
| { | ||
| label: "Column", | ||
| value: ChartType.COLUMN, | ||
| }, | ||
| { | ||
| label: "Dot", | ||
| value: ChartType.DOT, | ||
| }, | ||
| { | ||
| label: "Gauge", | ||
| value: ChartType.GAUGE, | ||
| }, | ||
| { | ||
| label: "Map", | ||
| value: ChartType.MAP, | ||
| }, | ||
| { | ||
| label: "Radar", | ||
| value: ChartType.RADAR, | ||
| }, | ||
| { | ||
| label: "Summary", | ||
| value: ChartType.SUMMARY, | ||
| }, | ||
| { | ||
| label: "Table", | ||
| value: ChartType.TABLE, | ||
| }, | ||
| { | ||
| label: "Timeline", | ||
| value: ChartType.TIMELINE, | ||
| }, | ||
| { | ||
| label: "Timeline Area", | ||
| value: ChartType.TIMELINE_AREA, | ||
| }, | ||
| { | ||
| label: "Timeline Bar", | ||
| value: ChartType.TIMELINE_BAR, | ||
| }, | ||
| { | ||
| label: "Tree", | ||
| value: ChartType.TREE, | ||
| }, | ||
| { | ||
| label: "Wordcloud", | ||
| value: ChartType.WORDCLOUD, | ||
| }, | ||
| ]; | ||
| }, | ||
| }, | ||
| keys: { | ||
| propDefinition: [ | ||
| app, | ||
| "keys", | ||
| ], | ||
| }, | ||
| metrics: { | ||
| propDefinition: [ | ||
| app, | ||
| "metrics", | ||
| ], | ||
| }, | ||
| rows: { | ||
| propDefinition: [ | ||
| app, | ||
| "rows", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| app, | ||
| name, | ||
| chartType, | ||
| keys, | ||
| metrics, | ||
| rows, | ||
| } = this; | ||
|
|
||
| const graph = await app.createGraphFromScratch({ | ||
| chartType, | ||
| keys, | ||
| metrics, | ||
| rows: utils.parseArray(rows), | ||
| }); | ||
|
|
||
| const response = await app.publishGraph({ | ||
| name, | ||
| graph, | ||
| }); | ||
|
|
||
| $.export("$summary", "Successfully built and published the graph from scratch."); | ||
| return response; | ||
| }, | ||
| }; | ||
67 changes: 67 additions & 0 deletions
67
components/columns_ai/actions/build-graph-from-template/build-graph-from-template.mjs
This file contains hidden or 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,67 @@ | ||
| import app from "../../columns_ai.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "columns_ai-build-graph-from-template", | ||
| name: "Build Graph From Template", | ||
| 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).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| name: { | ||
| propDefinition: [ | ||
| app, | ||
| "name", | ||
| ], | ||
| }, | ||
| visualId: { | ||
| type: "string", | ||
| label: "Visual ID", | ||
| 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`.", | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| keys: { | ||
| propDefinition: [ | ||
| app, | ||
| "keys", | ||
| ], | ||
| }, | ||
| metrics: { | ||
| propDefinition: [ | ||
| app, | ||
| "metrics", | ||
| ], | ||
| }, | ||
| rows: { | ||
| propDefinition: [ | ||
| app, | ||
| "rows", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| app, | ||
| name, | ||
| visualId, | ||
| keys, | ||
| metrics, | ||
| rows, | ||
| } = this; | ||
|
|
||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const graph = await app.createGraphFromTemplate({ | ||
| visualId, | ||
| keys, | ||
| metrics, | ||
| rows: utils.parseArray(rows), | ||
| }); | ||
|
|
||
| const response = await app.publishGraph({ | ||
| name, | ||
| graph, | ||
| }); | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $.export("$summary", "Successfully built and published the graph from template."); | ||
| return response; | ||
| }, | ||
| }; | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,11 +1,65 @@ | ||
| import { ChartType } from "columns-graph-model"; | ||
| import { Columns } from "columns-sdk"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "columns_ai", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| name: { | ||
| type: "string", | ||
| label: "Graph Name", | ||
| description: "The name of the graph", | ||
| }, | ||
| keys: { | ||
| type: "string[]", | ||
| label: "Keys", | ||
| description: "An array of keys for the data rows.", | ||
| }, | ||
| metrics: { | ||
| type: "string[]", | ||
| label: "Metrics", | ||
| description: "An array of metrics for the data rows.", | ||
| }, | ||
| rows: { | ||
| type: "string[]", | ||
| label: "Rows", | ||
| description: "An array of data objects, where each object should be a JSON string. Eg. `{ \"metric\": 4000, \"key\": \"US\", \"parent\": null }`.", | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| getColumns() { | ||
| return new Columns(this.$auth.api_key); | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async createGraphFromScratch({ | ||
| keys = [], metrics = [], rows = [], chartType = ChartType.COLUMN, | ||
| } = {}) { | ||
| const columns = this.getColumns(); | ||
| const data = columns.data(keys, metrics, rows); | ||
| const graph = columns.graph(data); | ||
|
|
||
| graph.type = chartType; | ||
|
|
||
| return graph; | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async createGraphFromTemplate({ | ||
| visualId, keys = [], metrics = [], rows = [], | ||
| } = {}) { | ||
| const columns = this.getColumns(); | ||
| const graph = await columns.template(visualId); | ||
|
|
||
| if (!graph) { | ||
| throw new Error(`Failed to load template from Columns: ${visualId}`); | ||
| } | ||
|
|
||
| graph.data = columns.data(keys, metrics, rows); | ||
|
|
||
| return graph; | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| publishGraph({ | ||
| name, graph, | ||
| } = {}) { | ||
| const columns = this.getColumns(); | ||
| return columns.publish(name, graph); | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or 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,51 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
|
|
||
| const parseJson = (input) => { | ||
| const parse = (value) => { | ||
| if (typeof(value) === "string") { | ||
| try { | ||
| return parseJson(JSON.parse(value)); | ||
| } catch (e) { | ||
| return value; | ||
| } | ||
| } else if (typeof(value) === "object" && value !== null) { | ||
| return Object.entries(value) | ||
| .reduce((acc, [ | ||
| key, | ||
| val, | ||
| ]) => Object.assign(acc, { | ||
| [key]: parse(val), | ||
| }), {}); | ||
| } | ||
| return value; | ||
| }; | ||
|
|
||
| return parse(input); | ||
| }; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function parseArray(value) { | ||
| try { | ||
| if (!value) { | ||
| return []; | ||
| } | ||
|
|
||
| if (Array.isArray(value)) { | ||
| return value; | ||
| } | ||
|
|
||
| const parsedValue = JSON.parse(value); | ||
|
|
||
| if (!Array.isArray(parsedValue)) { | ||
| throw new Error("Not an array"); | ||
| } | ||
|
|
||
| return parsedValue; | ||
|
|
||
| } catch (e) { | ||
| throw new ConfigurationError("Make sure the custom expression contains a valid array object"); | ||
| } | ||
| } | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default { | ||
| parseArray: (value) => parseArray(value).map(parseJson), | ||
| }; | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/columns_ai", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Columns Ai Components", | ||
| "main": "columns_ai.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,9 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "columns-graph-model": "^1.1.4", | ||
| "columns-sdk": "^0.0.6" | ||
| } | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.