-
-
Notifications
You must be signed in to change notification settings - Fork 257
Thing and Item Details: Use core's file-format service to display code in YAML and DSL #3180
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: main
Are you sure you want to change the base?
Conversation
#3120 Bundle Size — 11.2MiB (+0.05%).3f787a1(current) vs 5579ef8 main#3110(baseline) Warning Bundle contains 2 duplicate packages – View duplicate packages Bundle metrics
Bundle size by type
Bundle analysis report Branch jimtng:thing-details-code Project dashboard Generated by RelativeCI Documentation Report issue |
I like it. You finally decided to strip YAML first lines Would it be possible to have a horizontal scrollbar to be able to see the full DSL? |
There are vertical and horizontal scrollbars, just that they're not visible by default until you tried to scroll. That's the default behaviour (from the OS maybe?) |
The YAML headers are stripped (version, things: and thinguid) and the rest are unindented. As a result of this, if someone were to copy paste from here, they'd have to re-add the indentation. There's also the "Copy File Definition" button on the main "Thing" tab that was added before, which will give them the full yaml. Maybe we can move that button into the bottom toolbar |
Yes, exact. So that's fine for me. |
Did you already handle errors and warnings when editing? |
Come to think of it, if we moved the "copy file" button into the "Code" section, that would be a bit confusing, especially since the yaml code is not exactly the same as the yaml file. So let's leave the copy file button where it is now. |
Edited code gets parsed whenever you switch away from Code tab or when switching yaml <=> dsl. If the editor isn't dirty (modified), parsing is skipped. One thing I'm thinking about: It would be easier for the ui code to get the errors in json too so the actual error message can be displayed, not just the generic http error name (eg. "Bad Request") |
I can do it but look at this answer when I proposed it: |
I don't know if you saw my comment (elsewhere) to rename the tab to make it clear it is generated code and not original code. what is your opinion about that? |
Maybe hold off on the json error code. I just had a bit of experiment. Whilst I could display the errors in the body, it's a lot to display. Too long for a small dialog box. The editor's built in yaml support can point out obvious syntax errors so hopefully that helps. When I tried dsl, I got this:
and tbh I'm not sure it's very helpful. Let's go ahead without this enhancement for now.
I saw your post about that. I think let's just stay with "CODE". "GEN CODE" will raise more questions, and "GENERATED CODE" is too long and will also make people wonder. |
For YAML, I implemented some checks (errors and warnings) that would be helpful if displayed. |
I saw the yaml one. Whilst it seems helpful, I'm not sure where to display it. It's too big / too much text for the dialog. There may be a way to make codemirror editor to handle it / show it. See https://github.com/openhab/openhab-webui/blob/efe3fefd4f82402b055c86a33cc379075d0efdf2/bundles/org.openhab.ui/web/src/components/config/controls/script-editor.vue#L294C21-L306 We'll need the line numbers in a similar manner instead of/in addition to just a message. Yaml isn't the main issue, because as you see we already have a built in (generic) yaml syntax checker on the editor. The DSL one is the problem. An easy solution is to make DSL read-only. Right now you could edit the DSL just like you could edit the YAML. |
Refactored the code editor into a component so it can be used in both Thing Details page and Item Details page |
What is interesting is the additionnel checks I implemented like valid item type value, valid item dimension value, ... |
I've decided to display the full YAML, including I managed to make it so the first 3 lines are un-editable when it's YAML |
Updated the screenshots. YAML syntax is shown exactly as provided, including I hope we can finalise this before the 17th. I won't have a lot of time to work on this after that time until end of June. @lolodomo are the Items (DSL and YAML) ready? I'm trying to combine all the available core PRs to create a complete version, but I can't see a YAML Item converter. Also I mustn't have combined them properly because the combined version returned Bad requests for Things too. |
I am sorry but we are waiting for @openhab/core-maintainers to merge stuff. |
Are they currently separated so that they can be merged independently? If so, perhaps leave them as is. I just need to figure out how to merge them all on my local git so I can build a single complete version. I think I only attempted to merge 3 PRs last time. I'll try all the 4 you mentioned here. |
I tried to combine those 4 PRs but I failed :( |
I created PR openhab/openhab-core#4793 that contains everything, you can play with it. Ir replaces two PRs and is based on the PR that adds YAML for items. |
Thank you! I will test this now. |
48d8e09
to
a52881d
Compare
…e in YAML and DSL Signed-off-by: Jimmy Tanagra <[email protected]>
b8d993c
to
3e2fba6
Compare
Signed-off-by: Jimmy Tanagra <[email protected]>
Marking certain sections of the editor (the UID bit) as read-only poses a problem when the user selects all text and pastes new text, amongst other operations. The read-only part doesn't get overwritten by the paste operation. Making it "work" involves adding too much extra code and I think it outweighs the benefit. I'm removing this feature. There is already a check to ensure that the uid isn't modified, and the parser will complain on syntax errors. |
Signed-off-by: Jimmy Tanagra <[email protected]>
@lolodomo wdyt about the "Copy" button I added in the Code tab (See the original post for screenshot)? I noticed that the code produced in the code tab has all the channels defined by the Thing, vs the "Generate DSL/YAML File" function will only return the channels that have been customised, so it's usually a lot more compact. The "Copy" button in the code tab can probably be used by users to paste into forums, but they can of course just select all + Ctrl+C too. |
Depends on:
Partially resolve openhab/openhab-core#4585
Parse error details shown in a movable popup

YAML Hints adjusted to the new YAML syntax

I added this one hint for the channel type:
