- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
[Components] geckoboard #13394 #15908
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
Changes from 3 commits
961e5bb
              3670c85
              82b15a6
              52882b8
              4f6c319
              decd6f6
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import app from "../../geckoboard.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "geckoboard-append-to-dataset", | ||
| name: "Append to Dataset", | ||
| description: "Append data to the specified dataset. [See the documentation](https://developer.geckoboard.com/?#append-data-to-a-dataset)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| datasetId: { | ||
| propDefinition: [ | ||
| app, | ||
| "datasetId", | ||
| ], | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
|  | ||
| async additionalProps(existingProps) { | ||
| const datasetId = this.datasetId?.value || this.datasetId; | ||
| const datasets = await this.app.getDatasets(); | ||
|  | ||
| const dataset = datasets.data.find((d) => d.id === datasetId); | ||
| if (!dataset) return existingProps; | ||
|  | ||
| const props = {}; | ||
| for (const [ | ||
| key, | ||
| field, | ||
| ] of Object.entries(dataset.fields)) { | ||
| props[key] = { | ||
| type: "string", | ||
| label: field.name, | ||
| optional: field.optional, | ||
| }; | ||
| } | ||
|  | ||
| return props; | ||
| }, | ||
|  | ||
| async run({ $ }) { | ||
| const data = {}; | ||
|  | ||
| for (const key of Object.keys(this)) { | ||
| if (![ | ||
| "app", | ||
| "datasetId", | ||
| ].includes(key)) { | ||
| let value = this[key]; | ||
|  | ||
| if (!isNaN(value)) { | ||
| value = parseFloat(value); | ||
| } | ||
|  | ||
| data[key] = value; | ||
| } | ||
| } | ||
|  | ||
| const response = await this.app.appendToDataset({ | ||
| $, | ||
| datasetId: this.datasetId, | ||
| data: { | ||
| data: [ | ||
| data, | ||
| ], | ||
| }, | ||
| }); | ||
|  | ||
| $.export("$summary", "Successfully appended data to dataset"); | ||
| return response; | ||
| }, | ||
|  | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import app from "../../geckoboard.app.mjs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|  | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key: "geckoboard-create-dataset", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: "Create Dataset", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: "Create a new dataset. [See the documentation](https://developer.geckoboard.com/?#find-or-create-a-new-dataset)", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| version: "0.0.1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: "action", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| props: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| app, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fields: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| propDefinition: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| app, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fields", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| propDefinition: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| app, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "id", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async run({ $ }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const response = await this.app.createDataset({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: this.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fields: JSON.parse(this.fields), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $.export("$summary", "Successfully created dataset"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
      Comment on lines
    
      +24
     to 
      +34
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for JSON parsing The current implementation uses  Consider adding a try/catch block to handle potential JSON parsing errors:   async run({ $ }) {
+   let parsedFields;
+   try {
+     parsedFields = JSON.parse(this.fields);
+   } catch (error) {
+     throw new Error(`Invalid JSON format for fields: ${error.message}`);
+   }
+   
    const response = await this.app.createDataset({
      $,
      id: this.id,
      data: {
-       fields: JSON.parse(this.fields),
+       fields: parsedFields,
      },
    });
    $.export("$summary", "Successfully created dataset");
    return response;
  },📝 Committable suggestion
 
        Suggested change
       
 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import app from "../../geckoboard.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "geckoboard-delete-dataset", | ||
| name: "Delete Dataset", | ||
| description: "Delete the specified dataset. [See the documentation](https://developer.geckoboard.com/?#delete-a-dataset)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| datasetId: { | ||
| propDefinition: [ | ||
| app, | ||
| "datasetId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.deleteDataset({ | ||
| $, | ||
| datasetId: this.datasetId, | ||
| }); | ||
| $.export("$summary", "Successfully deleted dataset"); | ||
| return response; | ||
| }, | ||
| }; | 
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,85 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import { axios } from "@pipedream/platform"; | ||||||||||||||||||||||||||||||||||||||||||
|  | ||||||||||||||||||||||||||||||||||||||||||
| export default { | ||||||||||||||||||||||||||||||||||||||||||
| type: "app", | ||||||||||||||||||||||||||||||||||||||||||
| app: "geckoboard", | ||||||||||||||||||||||||||||||||||||||||||
| propDefinitions: { | ||||||||||||||||||||||||||||||||||||||||||
| fields: { | ||||||||||||||||||||||||||||||||||||||||||
| type: "string", | ||||||||||||||||||||||||||||||||||||||||||
| label: "Fields", | ||||||||||||||||||||||||||||||||||||||||||
| description: "JSON containing the fields of the dataset, i.e.: `{ \"amount\": { \"type\": \"number\", \"name\": \"Amount\", \"optional\": false }, \"timestamp\": { \"type\": \"datetime\", \"name\": \"Date\" } }. See [documentation](https://developer.geckoboard.com/#plan-your-schema)`", | ||||||||||||||||||||||||||||||||||||||||||
|         
                  vunguyenhung marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| id: { | ||||||||||||||||||||||||||||||||||||||||||
| type: "string", | ||||||||||||||||||||||||||||||||||||||||||
| label: "ID", | ||||||||||||||||||||||||||||||||||||||||||
| description: "The ID of the dataset that will be created", | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| datasetId: { | ||||||||||||||||||||||||||||||||||||||||||
| type: "string", | ||||||||||||||||||||||||||||||||||||||||||
| label: "Dataset Id", | ||||||||||||||||||||||||||||||||||||||||||
| description: "The ID of the dataset", | ||||||||||||||||||||||||||||||||||||||||||
| async options() { | ||||||||||||||||||||||||||||||||||||||||||
| const response = await this.getDatasets(); | ||||||||||||||||||||||||||||||||||||||||||
| const datasets = response.data; | ||||||||||||||||||||||||||||||||||||||||||
| return datasets.map(({ id }) => ({ | ||||||||||||||||||||||||||||||||||||||||||
| value: id, | ||||||||||||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| 
      Comment on lines
    
      +21
     to 
      +27
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling to the datasetId options function. The async options() function for datasetId does not include error handling. If the API call fails, it could lead to an uncaught exception.  async options() {
-  const response = await this.getDatasets();
-  const datasets = response.data;
-  return datasets.map(({ id }) => ({
-    value: id,
-  }));
+  try {
+    const response = await this.getDatasets();
+    const datasets = response.data;
+    return datasets.map(({ id }) => ({
+      value: id,
+      label: id,
+    }));
+  } catch (error) {
+    console.error("Error fetching datasets:", error);
+    return [];
+  }
 },📝 Committable suggestion
 
        Suggested change
       
 | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| methods: { | ||||||||||||||||||||||||||||||||||||||||||
| _baseUrl() { | ||||||||||||||||||||||||||||||||||||||||||
| return "https://api.geckoboard.com"; | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| async _makeRequest(opts = {}) { | ||||||||||||||||||||||||||||||||||||||||||
| const { | ||||||||||||||||||||||||||||||||||||||||||
| $ = this, | ||||||||||||||||||||||||||||||||||||||||||
| path, | ||||||||||||||||||||||||||||||||||||||||||
| auth, | ||||||||||||||||||||||||||||||||||||||||||
| ...otherOpts | ||||||||||||||||||||||||||||||||||||||||||
| } = opts; | ||||||||||||||||||||||||||||||||||||||||||
| return axios($, { | ||||||||||||||||||||||||||||||||||||||||||
| ...otherOpts, | ||||||||||||||||||||||||||||||||||||||||||
| url: this._baseUrl() + path, | ||||||||||||||||||||||||||||||||||||||||||
| auth: { | ||||||||||||||||||||||||||||||||||||||||||
| username: `${this.$auth.api_key}`, | ||||||||||||||||||||||||||||||||||||||||||
| password: "", | ||||||||||||||||||||||||||||||||||||||||||
| ...auth, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| async appendToDataset({ | ||||||||||||||||||||||||||||||||||||||||||
| datasetId, ...args | ||||||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||||||
| return this._makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||
| path: `/datasets/${datasetId}/data`, | ||||||||||||||||||||||||||||||||||||||||||
| method: "post", | ||||||||||||||||||||||||||||||||||||||||||
| ...args, | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| async createDataset({ | ||||||||||||||||||||||||||||||||||||||||||
| id, ...args | ||||||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||||||
| return this._makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||
| path: `/datasets/${id}`, | ||||||||||||||||||||||||||||||||||||||||||
| method: "put", | ||||||||||||||||||||||||||||||||||||||||||
| ...args, | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| async deleteDataset({ | ||||||||||||||||||||||||||||||||||||||||||
| datasetId, ...args | ||||||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||||||
| return this._makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||
| path: `/datasets/${datasetId}`, | ||||||||||||||||||||||||||||||||||||||||||
| method: "delete", | ||||||||||||||||||||||||||||||||||||||||||
| ...args, | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| async getDatasets(args = {}) { | ||||||||||||||||||||||||||||||||||||||||||
| return this._makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||
| path: "/datasets", | ||||||||||||||||||||||||||||||||||||||||||
| ...args, | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| { | ||
| "name": "@pipedream/geckoboard", | ||
| "version": "0.0.2", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Geckoboard Components", | ||
| "main": "dist/app/geckoboard.app.mjs", | ||
| "main": "geckoboard.app.mjs", | ||
| "keywords": [ | ||
| "pipedream", | ||
| "geckoboard" | ||
| ], | ||
| "files": ["dist"], | ||
| "homepage": "https://pipedream.com/apps/geckoboard", | ||
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } | 
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve property iteration and value conversion
The current approach of iterating over all properties of
thiscould include methods or internal properties that shouldn't be part of the data payload. Additionally, the automatic conversion of any numeric string to float might not be appropriate for all cases.Consider a more targeted approach:
async run({ $ }) { const data = {}; + + // Get dynamic field definitions + const props = await this.additionalProps({}); + const fieldKeys = Object.keys(props); - for (const key of Object.keys(this)) { - if (!["app", "datasetId"].includes(key)) { - let value = this[key]; - - if (!isNaN(value)) { - value = parseFloat(value); - } - - data[key] = value; - } - } + // Only process fields from the dataset schema + for (const key of fieldKeys) { + if (this[key] === undefined) continue; + + let value = this[key]; + + // Convert numeric strings to numbers when appropriate + if (typeof value === 'string' && !isNaN(value) && value.trim() !== '') { + value = parseFloat(value); + } + + data[key] = value; + }This approach only processes fields that were explicitly defined by the dataset schema and provides more robust number conversion.
📝 Committable suggestion