Skip to content

Commit 5d818c3

Browse files
committed
updates
1 parent 7be67fe commit 5d818c3

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

components/hubspot/actions/common/common-create.mjs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default {
7070
? options
7171
: undefined;
7272
},
73-
makePropDefinition(property, requiredProperties) {
73+
async makePropDefinition(property, requiredProperties) {
7474
let type = "string";
7575
let options = this.makeLabelValueOptions(property);
7676

@@ -83,13 +83,32 @@ export default {
8383
property.description += ". Enter date in ISO-8601 format. Example: `2024-06-25T15:43:49.214Z`";
8484
}
8585

86+
const objectType = this.hubspot.getObjectTypeName(this.getObjectType());
87+
let reloadProps;
88+
if (property.name === "hs_pipeline") {
89+
options = await this.hubspot.getPipelinesOptions(objectType);
90+
reloadProps = true;
91+
}
92+
if (property.name === "hs_pipeline_stage") {
93+
options = await this.hubspot.getPipelineStagesOptions(objectType, this.hs_pipeline);
94+
}
95+
if (property.name === "hs_all_assigned_business_unit_ids") {
96+
try {
97+
options = await this.hubspot.getBusinessUnitOptions();
98+
} catch {
99+
console.log("Could not load business units");
100+
}
101+
property.description += " For use with the Business Units Add-On.";
102+
}
103+
86104
return {
87105
type,
88106
name: property.name,
89107
label: property.label,
90108
description: property.description,
91109
optional: !requiredProperties.includes(property.name),
92110
options,
111+
reloadProps,
93112
};
94113
},
95114
},
@@ -101,9 +120,12 @@ export default {
101120
const { results: properties } = await this.hubspot.getProperties({
102121
objectType,
103122
});
104-
return properties
105-
.filter(this.isRelevantProperty)
106-
.map((property) => this.makePropDefinition(property, schema.requiredProperties))
123+
const relevantProperties = properties.filter(this.isRelevantProperty);
124+
const propDefinitions = [];
125+
for (const property of relevantProperties) {
126+
propDefinitions.push(await this.makePropDefinition(property, schema.requiredProperties));
127+
}
128+
return propDefinitions
107129
.reduce((props, {
108130
name, ...definition
109131
}) => {

components/hubspot/common/constants.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const API_PATH = {
2121
CMS: "/cms/v3",
2222
AUTOMATION: "/automation/v2",
2323
DEAL: "/deals/v1",
24+
BUSINESS_UNITS: "/business-units/v3",
2425
};
2526

2627
/** Association categories for association types, as defined by the [Hubspot API

components/hubspot/hubspot.app.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,35 @@ export default {
580580
value: object.id,
581581
}));
582582
},
583+
async getPipelinesOptions(objectType) {
584+
const { results } = await this.getPipelines({
585+
objectType,
586+
});
587+
return results?.map((pipeline) => ({
588+
label: pipeline.label,
589+
value: pipeline.id,
590+
})) || [];
591+
},
592+
async getPipelineStagesOptions(objectType, pipelineId) {
593+
if (!pipelineId) {
594+
return [];
595+
}
596+
const { stages } = await this.getPipeline({
597+
objectType,
598+
pipelineId,
599+
});
600+
return stages?.map((stage) => ({
601+
label: stage.label,
602+
value: stage.id,
603+
})) || [];
604+
},
605+
async getBusinessUnitOptions() {
606+
const { results } = await this.getBusinessUnits();
607+
return results?.map((unit) => ({
608+
label: unit.name,
609+
value: unit.id,
610+
})) || [];
611+
},
583612
searchCRM({
584613
object, ...opts
585614
}) {
@@ -754,6 +783,22 @@ export default {
754783
...opts,
755784
});
756785
},
786+
getBusinessUnits(opts = {}) {
787+
return this.makeRequest({
788+
api: API_PATH.BUSINESS_UNITS,
789+
endpoint: `/business-units/user/${this.$auth.oauth_uid}`,
790+
...opts,
791+
});
792+
},
793+
getPipeline({
794+
objectType, pipelineId, ...opts
795+
}) {
796+
return this.makeRequest({
797+
api: API_PATH.CRMV3,
798+
endpoint: `/pipelines/${objectType}/${pipelineId}`,
799+
...opts,
800+
});
801+
},
757802
getPipelines({
758803
objectType, ...opts
759804
}) {

0 commit comments

Comments
 (0)