Skip to content
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

Pass parameters to the hidden trigger #22

Closed
simonachmueller opened this issue May 20, 2019 · 3 comments
Closed

Pass parameters to the hidden trigger #22

simonachmueller opened this issue May 20, 2019 · 3 comments

Comments

@simonachmueller
Copy link

In my Platform CLI integration I have 2 public triggers which use same dynamic dropdown element and same hidden trigger behind it.
Now I want to be able to customize the request my hidden trigger produces.

So let say the hidden trigger (behind the dynamic dropdown) produces object list, but for 1st public trigger I want to show only object with type=1, and in 2nd public trigger with type=3.

So I want to see my perform function in the hidden trigger like this:

const getFrogList = (z, bundle) => {
  const requestOptions = {
    url: `${process.env.BASE_URL}/api/frogs/getall`,
    params: {type: bundle._MY_CUSTOM_TYPE_FIELD}
  };

  return z.request(requestOptions)
  .then((response) => z.JSON.parse(response.content));
};

And in my public trigger:

inputFields: [
{
  key: "frog",
  type: "string",
  helpText: "Please define which kind of frog you want to use",
  label: "Frog",
  dynamic: "getFrogList.id.name",
  altersDynamicFields: true,
  required: true,
  _MY_CUSTOM_TYPE_FIELD: 1
 } 
]
@thespielplatz
Copy link

I am having the same problem!

  • I am fine with the suggested solution
  • What I would prefer would be an "Hidden Field"

Currently I am dynamically creating all possible hidden trigger types ... it works, but it is way too dirty & too much code

@xavdid
Copy link
Contributor

xavdid commented Feb 18, 2021

I think the best option here is to create the function manually. The dynamic property is just syntactic sugar around running a function and returning a valid field type. So instead, give something like this a shot (untested, but it's the right idea):

const fetchFrogs = async (customType, z, bundle) => {
  const requestOptions = {
    url: `${process.env.BASE_URL}/api/frogs/getall`,
    params: { type: customType },
  };

  const response = await z.request(requestOptions);
  const data = z.JSON.parse(response.content);

  return {
    key: "frog",
    type: "string",
    helpText: "Please define which kind of frog you want to use",
    label: "Frog",
    choices: data.frogs, // array of objects, see https://github.com/zapier/zapier-platform/blob/master/packages/schema/docs/build/schema.md#fieldchoicesschema
    // ...
  };
};

inputFields: [
  //...
  fetchFrogs.bind(null, "blue frogs"),
];

That fetchFrogs can be used in any number of triggers and you can pass all the arguments you want to it. I think the big key here is to not get too attached to powering loading options via the dynamic key.

@phorwath @semenmiroshnichenko Do you think that'll work for your use case?

@thespielplatz
Copy link

I like the idea, it's simple! Hadn't thought of bind :D

Implemented it, work's! Thanks 🙌

🙋‍♂️ I would prefer the solution with powering of dynamic.
Because now with bind I am "wrapping" the whole field definition, with powering dynamic I am just wrapping there where I need it.

@rnegron rnegron closed this as completed Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants