Improved Task Options
under review
Steve Honey
Appreciating that schema markup would give lots of flexibiity here I think a V1, simpler version of this might be to just support select and radio. I imagined the markup could look like:
options.some_option__required_select["value1":"Select Label 1"," value2":"Select Label 2"]
options.some_other_option__required_radio["value1":"Radio Label 1","value2":"Radio Label 2"]
Aubrey Taylor
Related ask for option secrets encryption: https://mechanic.canny.io/futures/p/secret-store
Aubrey Taylor
Just lurking here, but I'd love to expand on this convo by adding two suggestions:
- Option sections to organize options in the admin better
- Encrypted flag for sensitive variables like api tokens. This would encrypt the value until it's used and wouldn't render in plaintext as they're inevitably logged in Mechanic.
Matt Sodomsky
Aubrey Taylor: Can you expand on this: "Option sections to organize options in the admin better". I'm curious :)
Aubrey Taylor
Matt Sodomsky:
For sure. I guess I'm, basically, referring to fieldsets.
For a contrived example, let's assume a task has config needed for two APIs. "Option sections" (i.e. fieldsets) might look something like this:
P
Patou Tech
I was thinking more about this today, namely because I want to support options like select fields, enums, and passwords.
The existing method of
options.{{ option_name}}_{{ option_format }}_{{ is_required }}
should still be supported, but I thought that maybe supporting a {% schema %}
tag using JSON schema as the value could allow us to further configure options on top of the base definitions.For example, if I had in my task:
{% assign accepted_types = options.accepted_types__array %}
{% assign webhook_auth_token = options.webhook_auth_token__required %}
I could then add this to the bottom of the task (or maybe as an additional "Options" tab on the task) extra JSON schema configuration to ensure that :
{% schema %}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "options",
"type": "object",
"properties": {
"accepted_types": {
"items": {
"type": "string",
"enum": ["option1", "option2", "option3"]
},
"minItems": 1,
"maxItems": 1
},
"webhook_auth_token": {
"minLength": 2,
"maxLength": 16
}
}
}
{% endschema %}
There could be support for configuring what kind of input is displayed by defining an "_input_type" (underscore to denote that it is a non-standard JSON schema property) on the definition:
{% schema %}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "options",
"type": "object",
"properties": {
"accepted_types": {
"_input_type": "select",
"items": {
"type": "string",
"enum": ["option1", "option2", "option3"]
},
"minItems": 1,
"maxItems": 1
},
"webhook_auth_token": {
"_input_type": "password",
"minLength": 2,
"maxLength": 16
}
}
}
{% endschema %}
Mechanic would then extract the options and schema within the task and then combine them all to create the options JSON schema like so:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "options",
"type": "object",
"properties": {
"accepted_types": {
"type": "array",
"items": {
"type": "string",
"enum": ["option1", "option2", "option3"],
},
"minItems": 1,
"maxItems": 1
},
"webhook_auth_token": {
"type": "string",
"maxLength": 16
}
},
"required": ["webhook_auth_token"]
}
This options JSON schema would then be used by Mechanic to render the options in the task itself, and provide additional input validation and configuration of form inputs (and acceptable input options).
M
Matt Scheurich
What could be cool is if we could optionally define options via a JSON schema rather than within the task code, and that way maybe we could also support additional features like option grouping/sections, extra information, headers, etc. It could also let us build in specific validation as well.
Tim Mackey
Matt Scheurich: Lol, I must have forgotten that you suggested this, because I just came here to post the same thing! I've been thinking that copying Shopify's JSON schema method might be a good solution—it works well, and it's already familiar to Shopify developers.
M
Matt Scheurich
Tim Mackey: Shopify schema does work well to a certain extent, however there's a lot more flexibility and range with using JSON schema, plus a lot more tooling that supports it IMO
Tim Mackey
I thought of another use case for this today. Shopify's default customer export doesn't give me some fields I need, so I'm creating a Mechanic task to do it for me.
It would be useful if I could expose a list of customer properties to the task options, so the user could choose which columns to include in their CSV. Basically a sortable checkbox list. I'd implement the data as key-value pairs, so that the user sees friendly column names, and the task code receives graphQL property names.
Isaac Bowen
A note about character limits: _currently_ these can be enforced by rendering an {% error %} if the value isn't compliant. It's not as pretty as an input-level constraint, but it does work! :)
Matt Sodomsky
under review