- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
New Components - charthop #15391
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
                    New Components - charthop #15391
Changes from 7 commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      55fbfd7
              
                charthop init
              
              
                michelle0927 44485d1
              
                wip
              
              
                michelle0927 0891f82
              
                pnpm-lock.yaml
              
              
                michelle0927 385452b
              
                wip
              
              
                michelle0927 f010ed1
              
                new components
              
              
                michelle0927 52f29e7
              
                pnpm-lock.yaml
              
              
                michelle0927 91c529e
              
                fixes
              
              
                michelle0927 528a1c6
              
                fix method names
              
              
                michelle0927 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
        
          
          
            47 changes: 47 additions & 0 deletions
          
          47 
        
  components/charthop/actions/create-employee/create-employee.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,47 @@ | ||
| import charthop from "../../charthop.app.mjs"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
|  | ||
| export default { | ||
| key: "charthop-create-employee", | ||
| name: "Create Employee", | ||
| description: "Adds a new employee to the system. [See the documentation](https://api.charthop.com/swagger#/person/createPerson)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| charthop, | ||
| orgId: { | ||
| propDefinition: [ | ||
| charthop, | ||
| "orgId", | ||
| ], | ||
| }, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "Name of the employee", | ||
| }, | ||
| additionalProperties: { | ||
| type: "object", | ||
| label: "Additional Properties", | ||
| description: "Additional properties to add to the employee", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const additionalProperties = this.additionalProperties | ||
| ? parseObject(this.additionalProperties) | ||
| : {}; | ||
|  | ||
| const response = await this.charthop.createPerson({ | ||
| $, | ||
| orgId: this.orgId, | ||
| data: { | ||
| name: this.name, | ||
| ...additionalProperties, | ||
| }, | ||
| }); | ||
|  | ||
| $.export("$summary", `Successfully created employee with ID: ${response.id}`); | ||
| return response; | ||
| }, | ||
| }; | 
        
          
          
            36 changes: 36 additions & 0 deletions
          
          36 
        
  components/charthop/actions/search-organization/search-organization.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,36 @@ | ||
| import charthop from "../../charthop.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "charthop-search-organization", | ||
| name: "Search Organization", | ||
| description: "Return people, job, group, and field data for a particular org that match a provided search string. [See the documentation](https://api.charthop.com/swagger#/search/searchOrgData)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| charthop, | ||
| orgId: { | ||
| propDefinition: [ | ||
| charthop, | ||
| "orgId", | ||
| ], | ||
| }, | ||
| q: { | ||
| type: "string", | ||
| label: "Query", | ||
| description: "The search query", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.charthop.searchOrganization({ | ||
| $, | ||
| orgId: this.orgId, | ||
| params: { | ||
| q: this.q, | ||
| includeFormer: true, | ||
| }, | ||
| }); | ||
|  | ||
| $.export("$summary", "Successfully completed search query"); | ||
| return response; | ||
| }, | ||
| }; | 
        
          
          
            83 changes: 83 additions & 0 deletions
          
          83 
        
  components/charthop/actions/update-employee-details/update-employee-details.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,83 @@ | ||
| import charthop from "../../charthop.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "charthop-update-employee-details", | ||
| name: "Update Employee Details", | ||
| description: "Updates an existing employee's details. [See the documentation](https://api.charthop.com/swagger#/user/updateUser)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| charthop, | ||
| orgId: { | ||
| propDefinition: [ | ||
| charthop, | ||
| "orgId", | ||
| ], | ||
| }, | ||
| employeeId: { | ||
| propDefinition: [ | ||
| charthop, | ||
| "employeeId", | ||
| (c) => ({ | ||
| orgId: c.orgId, | ||
| }), | ||
| ], | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const props = {}; | ||
| if (!this.employeeId || !this.orgId) { | ||
| return props; | ||
| } | ||
|  | ||
| const employee = await this.charthop.getPerson({ | ||
| orgId: this.orgId, | ||
| personId: this.employeeId, | ||
| }); | ||
|  | ||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(employee)) { | ||
| if (key === "id") { | ||
| continue; | ||
| } | ||
| props[key] = { | ||
| type: "string", | ||
| label: `${key}`, | ||
| default: key === "name" | ||
| ? (`${value?.first} ${value?.last}`).trim() | ||
| : `${value}`, | ||
| }; | ||
| } | ||
|  | ||
| return props; | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| charthop, | ||
| orgId, | ||
| employeeId, | ||
| ...fields | ||
| } = this; | ||
|  | ||
| await charthop.updatePerson({ | ||
| $, | ||
| orgId, | ||
| personId: employeeId, | ||
| data: { | ||
| ...fields, | ||
| }, | ||
| }); | ||
|  | ||
| const response = await charthop.getPerson({ | ||
| $, | ||
| orgId, | ||
| personId: employeeId, | ||
| }); | ||
|  | ||
| $.export("$summary", `Successfully updated employee with ID ${employeeId}`); | ||
| 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,214 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|  | ||
| export default { | ||
| type: "app", | ||
| app: "charthop", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| orgId: { | ||
| type: "string", | ||
| label: "Organization ID", | ||
| description: "The identifier of an organization", | ||
| async options({ prevContext }) { | ||
| const params = prevContext?.from | ||
| ? { | ||
| from: prevContext.from, | ||
| } | ||
| : {}; | ||
| const { data } = await this.listOrgs({ | ||
| params, | ||
| }); | ||
| const options = data?.map(({ | ||
| id: value, name: label, | ||
| }) => ({ | ||
| value, | ||
| label, | ||
| })) || []; | ||
| return { | ||
| options, | ||
| context: { | ||
| from: options[options.length - 1].id, | ||
| }, | ||
| }; | ||
| }, | ||
| }, | ||
| employeeId: { | ||
| type: "string", | ||
| label: "Employee ID", | ||
| description: "The identifier of an employee", | ||
| async options({ | ||
| orgId, prevContext, | ||
| }) { | ||
| const params = { | ||
| includeAll: true, | ||
| }; | ||
| if (prevContext?.from) { | ||
| params.from = prevContext.from; | ||
| } | ||
| const { data } = await this.listPersons({ | ||
| orgId, | ||
| params: { | ||
| ...params, | ||
| }, | ||
| }); | ||
| const options = data?.map(({ | ||
| id: value, name, | ||
| }) => ({ | ||
| value, | ||
| label: (`${name?.first} ${name?.last}`).trim(), | ||
| })) || []; | ||
| return { | ||
| options, | ||
| context: { | ||
| from: data[data.length - 1].id, | ||
| }, | ||
| }; | ||
| }, | ||
| }, | ||
| groupTypeId: { | ||
| type: "string", | ||
| label: "Group Type ID", | ||
| description: "The identifier of a group type", | ||
| async options({ | ||
| orgId, prevContext, | ||
| }) { | ||
| const params = { | ||
| includeAll: true, | ||
| }; | ||
| if (prevContext?.from) { | ||
| params.from = prevContext.from; | ||
| } | ||
| const { data } = await this.listGroupTypes({ | ||
| orgId, | ||
| params: { | ||
| ...params, | ||
| }, | ||
| }); | ||
| const options = data?.map(({ | ||
| id: value, name: label, | ||
| }) => ({ | ||
| value, | ||
| label, | ||
| })) || []; | ||
| return { | ||
| options, | ||
| context: { | ||
| from: data[data.length - 1].id, | ||
| }, | ||
| }; | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.charthop.com"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, | ||
| path, | ||
| ...otherOpts | ||
| }) { | ||
| return axios($, { | ||
| ...otherOpts, | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| "Authorization": `Bearer ${this.$auth.api_token}`, | ||
| "Content-Type": "application/json", | ||
| }, | ||
| }); | ||
| }, | ||
| listOrgs(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/v1/org", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listPersons({ | ||
| orgId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/v2/org/${orgId}/person`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listJobs({ | ||
| orgId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/v2/org/${orgId}/job`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listGroupTypes({ | ||
| orgId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/v1/org/${orgId}/group-type`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listGroups({ | ||
| orgId, type, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/v2/org/${orgId}/group/${type}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getPerson({ | ||
| orgId, personId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/v2/org/${orgId}/person/${personId}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| createPerson({ | ||
| orgId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: `/v2/org/${orgId}/person`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| updatePerson({ | ||
| orgId, personId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| method: "PATCH", | ||
| path: `/v2/org/${orgId}/person/${personId}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| searchOrganization({ | ||
| orgId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/v1/org/${orgId}/search`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| resourceFn, | ||
| args, | ||
| max, | ||
| }) { | ||
| let count = 0; | ||
| do { | ||
| const { | ||
| data, next, | ||
| } = await resourceFn(args); | ||
| for (const item of data) { | ||
| yield item; | ||
| if (max && ++count >= max) { | ||
| return; | ||
| } | ||
| args.params = { | ||
| ...args.params, | ||
| from: next, | ||
| }; | ||
| } | ||
| } while (args.params?.from); | ||
| }, | ||
| }, | ||
| }; | ||
      
      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.