Skip to content

Commit

Permalink
Added new addChoices util function
Browse files Browse the repository at this point in the history
  • Loading branch information
oojacoboo committed Oct 9, 2023
1 parent dd01cfe commit 08ac50d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,38 @@ const addDynamicDropdowns = (inputFields, triggerMapping) => {
}


/**
* Adds a choices dropdown for an input field. This can be useful to use in substitution for a
* trigger. It's also often used with enums.
*
* @param {Array<Object>} inputFields The inputFields array from the operation
* @param {Object} choices An object of key/value pairs where the key is to be passed in
* the bundle with the request and the value is the human friendly
*
* @return {Array<Object>} The inputFields array with the choices added
*/
const addChoices = (inputFields, choices) => {
for (const [key, value] of Object.entries(choices)) {
inputFields.map((inputField) => {
if (inputField.key === key) {
inputField.choices = `${value}`;
}

// Zapier only supports one level of depth (should be refactored to recursive for more depth)
if (inputField.children && inputField.children.length) {
inputField.children.map((child) => {
if (child.key === key) {
child.choices = `${value}`;
}
});
}
});
}

return inputFields;
}


/**
* Will quote a string, but leave other types alone
*
Expand All @@ -54,5 +86,6 @@ const quote = (value) => {

module.exports = {
addDynamicDropdowns,
addChoices,
quote,
};

0 comments on commit 08ac50d

Please sign in to comment.