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

feat: sections support #1139

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

Conversation

selvalt7
Copy link

@selvalt7 selvalt7 commented Sep 12, 2024

This adds support for sections dashboard and addresses #1111.
Which means it fixes card size and also add card size restrictions based on the card configuration.
This "shouldn't" affect other types of dashboards.
sections

@Nickduino
Copy link

Please merge this into the base branch, guys, we need it :-)

@akloeckner
Copy link
Collaborator

Please feel free to give a first peer review. This one will take some time on my side, as I don't have too much spare time and #1128 is first in line. @selvalt7 is very productive. 😄 Thanks!

@ildar170975
Copy link
Collaborator

Honestly I made a quick look at this PR.
What I noticed that all changes affect only on a "sections" view (hope I am not wrong) - i.e. will not break traditional views.
Cannot test it in full scale myself - not using sections.

IMHO we can give this PR a go & test with participation of users who is using sections.
Hopefully will find more bugs)))

Copy link
Collaborator

@akloeckner akloeckner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the discussion came here before I could look at the UI PR again, I used some travel time to review. I must admit, I don't use sections, so this is from a pure code review perspective now.

Forgive me if I didn't get some parts of the code completely. All suggestions are open to discussion.

src/main.js Outdated
@@ -127,6 +135,68 @@ class MiniGraphCard extends LitElement {
}
}

checkSections() {
let root = document.querySelector('home-assistant');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the best way to check for the view layout? The main frontend suggests, there might be this.layout?

See here: https://github.com/home-assistant/frontend/blob/67217b9dd0f5ad43aafb3bba2fe2821407b25243/src/panels/lovelace/cards/hui-entity-card.ts#L139

Also, maybe this.options.layout_options will only defined in sections view?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.layout does not seem to be defined when the graphs are created in getConfig. I could try to modify graphs height in render as it seems that this.layout is defined there.

As for the this.options.layout_options there could be a situation where user copies card to a different dashboard that is not necessarily a sections but maybe I am overthinking.

src/main.js Show resolved Hide resolved
src/main.js Show resolved Hide resolved
src/main.js Outdated
}

getLayoutSize(layout) {
if (!this.sections) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce?

return this.sections && layout.grid_rows === 2 ? 'small' : '';

And if that is enough, maybe remove the function and do the logic in the render directly... (Because it seems used only once.)

src/style.js Show resolved Hide resolved
src/style.js Outdated
@@ -49,6 +53,9 @@ const style = css`
order: -1;
padding: 0 16px 8px 16px;
}
ha-card[fill].sections .graph__legend {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do the margins and paddings need tweaking? If it's kind of a refactor but yields the same layout, let's consider to change this also in non-section view to keep consistency.

@@ -238,6 +254,10 @@ const style = css`
margin-top: auto;
width: 100%;
}
.sections .graph {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, too: if this is useful also in non-section views, let's consider to just add it to the regular styles.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is only useful for section view. It makes graph position itself so that it's not clipping out of bounds.

return false;
}

getCurrentLayout() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder: isn't this taken care of by home assistant? If we report a minimum row count via getLayoutOptions, shouldn't this be reflected in this.config.layout_options?

See also here, maybe: https://github.com/home-assistant/frontend/blob/67217b9dd0f5ad43aafb3bba2fe2821407b25243/src/panels/lovelace/editor/card-editor/hui-card-layout-editor.ts#L68

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it only clamps the values for setting the card size and for the visual editor, values set by user in this.config.layout_options stays untouched even when they're lower than minimum set in getLayoutOptions.

src/main.js Show resolved Hide resolved
Card is considered small when its row size is 3 or less
Simpler sections checking
Simpler card height style
@jnnck
Copy link

jnnck commented Oct 8, 2024

Hi Guys! Thanks for your work, just wanted to let you guys know that as a sections user, i tried out this PR and it did fix my dashboards

Before:
Screenshot 2024-10-08 at 15 11 47

After:
Screenshot 2024-10-08 at 15 10 48

Personally i did like the thinner lines, but thats just preference and i can just add line_width to my yaml ofcourse

@Nickduino
Copy link

Nickduino commented Oct 8, 2024

@jnnck Awesome. Could you show us how the labels look like on your humidity graph with the PR?

image

@selvalt7
Copy link
Author

selvalt7 commented Oct 8, 2024

I haven't touched the labels, but I think it could be solved by changing flex-direction in the labels container to column-reverse and changing their arrangement in HTML so they appear correctly.

This would introduce some overlaps, of course.

Before:
brave_SqDfzx3I9s
After:
brave_H3SzSNnlQB

@ildar170975
Copy link
Collaborator

ildar170975 commented Oct 8, 2024

Hope this PR will only touch sections and will not affect other layouts.
I would suggest to reduce it to as minimal as possible to simplify testing and probably to review necessary changes.

As for labels and similar: consider more playing with fonts than with placement.

@Nickduino
Copy link

After: brave_H3SzSNnlQB

If you want to go that route, I think you shouldn't leave such an important gap at the bottom and the state should remain on top of the labels

@jnnck
Copy link

jnnck commented Oct 8, 2024

@jnnck Awesome. Could you show us how the labels look like on your humidity graph with the PR?

Labels before:
Screenshot 2024-10-08 at 18 54 41Screenshot 2024-10-08 at 18 54 47

Labels after:
Screenshot 2024-10-08 at 18 53 29Screenshot 2024-10-08 at 18 53 38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants