-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Separate action field YAML examples #27218
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
base: dev
Are you sure you want to change the base?
Separate action field YAML examples #27218
Conversation
|
I think comma separation should be avoided; should we make a list instead? |
|
As in one above the other in a veritical list? |
|
My feeling is that an example should be exactly one example that can be copied and pasted in it's entirety and will work. For that reason, I don't think even the ability to have a list of examples in the services.yaml makes sense. Sometimes as @karwosts says, the example could be a json dict object that is intended to be pasted in its entirety. Other times it could be an array, and then we want the user to not paste the whole array, but just pick one of them? What about a array of dicts? Or a dict containing arrays? Could be confusing. If we want to list several possible options, I think that should be in the description. So perhaps the solution is to remove all instances where there is more than one example in services.yaml and update the validator to enforce it. I don't have a strong view on this, so happy to go with what others think, but we shouldn't display multiple examples without any delimiter. |
|
See comment here: #27217 (comment) Now I see that the examples are not discrete examples, but rather a list that the user could enter in it's entirety, where they are requesting all items in that list. |
|
I have seen some service authors confused from time to time and write things like "foo OR bar" in their example, which should probably be discouraged when discovered, though I don't know how you can check for that 😅 |
Could one of the pytests be to put the |
| ${this.hass.localize( | ||
| `component.${domain}.services.${serviceName}.fields.${field.key}.example` | ||
| ) || field.example} | ||
| ) || JSON.stringify(field.example)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixing JSON with YAML seems confusing. I propose just YAML formatting complex objects like this, where dump is imported from "js-yaml"
| ${this.hass.localize( | |
| `component.${domain}.services.${serviceName}.fields.${field.key}.example` | |
| ) || field.example} | |
| ) || JSON.stringify(field.example)} | |
| ${this.hass.localize( | |
| `component.${domain}.services.${serviceName}.fields.${field.key}.example` | |
| ) || | |
| (typeof field.example === "object" | |
| ? html`<pre>${dump(field.example)}</pre>` | |
| : field.example)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MindFreeze agreed, although in some instances json is way more helpful (e.g. if feeding the data into the REST API - which is what I was doing when I stumbled across this issue).
Would having two example columns (one for JSON, one for yaml) be out of the question?
I noticed the Microsoft started doing similar a while ago where they have a help page with API examples in multiple languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this page is meant for using/documenting the REST API, we generally use YAML for everything, and that is what we should display here. I would not add yet another column.
MindFreeze
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the formatting to YAML as suggested
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |



Proposed change
When the user selects the Actions page in Developer tools, the YAML examples should be separated, rather than displayed as all one word. For more information see #27217.
Before:
After:
Type of change
Additional information
One thing I'm not so sure about is the added whitespace before and after the text in the
<td>. The automatic (prettier) formatting added whitespace which then showed up in the output. I fixed this by adding a<!-- prettier-ignore -->statement but I'm not sure this was fully necessary, as my build showed this problem whitespace on the output both before and after the change.Checklist
If user exposed functionality or configuration variables are added/changed: