frontend icon indicating copy to clipboard operation
frontend copied to clipboard

Allow customizing the number of column within a section

Open piitaya opened this issue 1 year ago • 1 comments

Proposed change

This PR introduces a new grid_base parameter to each grid section to allow customizing the number of column within a section. 2 presets are available in the UI (default and dense). Any number can be set using YAML.

The implementation is not perfect but will be enough for now. I will open another PR to refactor section editor and layout editor using the same logic as card. Each section will be able to provide its own editor.

Section editor

CleanShot 2024-08-19 at 09 51 36

Section YAML config

grid_base: 6

4 columns grid

Dashboard CleanShot 2024-08-16 at 11 56 39

Editor CleanShot 2024-08-16 at 11 56 53

6 columns grid

Dashboard CleanShot 2024-08-16 at 11 56 25

Editor CleanShot 2024-08-16 at 11 57 13

Type of change

  • [ ] Dependency upgrade
  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [x] New feature (thank you!)
  • [ ] Breaking change (fix/feature causing existing functionality to break)
  • [ ] Code quality improvements to existing code or addition of tests

Example configuration


Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • [x] The code change is tested and works locally.
  • [x] There is no commented out code in this PR.
  • [ ] Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration option for grid-based layouts, enabling more precise control over section designs.
    • Added a grid_density setting to enhance UI layout flexibility with options for "default," "dense," and "custom."
  • Bug Fixes

    • Updated visibility logic for layout tabs, simplifying the user interface experience.
  • Documentation

    • Expanded translation entries to include new settings related to grid density, improving user guidance.
  • Refactor

    • Enhanced configuration handling across various components to improve flexibility and maintainability.

piitaya avatar Aug 16 '24 10:08 piitaya

Walkthrough

Walkthrough

This update introduces the LovelaceGridSectionConfig interface, enhancing layout control for Lovelace sections with an optional grid_base property. Various components have been modified to streamline configuration management, replacing previous methods and properties with this new structure. The editor and section settings have become more flexible, and language support has been expanded with new translation entries related to grid configuration options.

Changes

Files Change Summary
src/data/lovelace/config/section.ts Added LovelaceGridSectionConfig interface extending LovelaceSectionConfig with optional grid_base.
src/panels/lovelace/editor/card-editor/hui-card-element-editor.ts, Modified HuiCardElementEditor to use sectionConfig instead of showLayoutTab, updating tab rendering logic accordingly.
src/panels/lovelace/editor/card-editor/hui-card-layout-editor.ts, Introduced sectionConfig in HuiCardLayoutEditor, affecting column management based on grid_base.
src/panels/lovelace/editor/card-editor/hui-dialog-edit-card.ts Removed _shouldShowLayoutTab, simplifying layout tab visibility control using sectionConfig.
src/panels/lovelace/editor/section-editor/hui-section-settings-editor.ts Added grid_density to SettingsData, updated _schema to include it dynamically based on section type, introduced _isGridSectionConfig method.
src/panels/lovelace/sections/hui-grid-section.ts Updated configuration type to LovelaceGridSectionConfig, added DEFAULT_GRID_BASE, and modified CSS properties for grid layout.
src/translations/en.json Added new entries for grid_density settings and options within the translations file.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Aug 16 '24 10:08 coderabbitai[bot]

Are there any plans to continue work on this? This seems to be the last piece needed to achieve what I'm looking for which, is to make possible to create half width sections. Other pieces needed for that landed recently with the row/column span and option to increase the number of columns in sections view but the number of columns inside a section only increases as stated in https://github.com/home-assistant/frontend/pull/21524#issuecomment-2317770401 whereas I'm looking to actually decrease it instead, so the overall data density stays the same as the default but it's possible to fit 2 smaller sections on the lowest breakpoint with one column inside each.

dsypniewski avatar Sep 30 '24 11:09 dsypniewski

Replaced with #22366

piitaya avatar Oct 16 '24 08:10 piitaya

What are you trying to achieve with half sections? @dsypniewski.

It can already be done with a single section, right? Or maybe I misunderstood.

CleanShot 2024-10-16 at 10 31 03

piitaya avatar Oct 16 '24 08:10 piitaya

Yes, this is what I'm doing now as well - before the new headers introduced in the latest release I had vertical stacks as titles if I remember correctly, but I'm looking for half sections purely for proper segregation of groups and ease of organising them. In the above example if you want to switch Lights and Shutters "columns" in places you need to drag and drop all of those individual cards instead of just doing that to the whole section which could be half of that. The problem only gets worse when on higher breakpoints you have multiple of such "columns" sections in one row and want to switch their placing. I know I could put those in vertical stacks which kind of solve that issue but that creates another one where you lose drag and drop inside the "column", so as far as I can see it the only real solution would be a half width section.

dsypniewski avatar Oct 16 '24 11:10 dsypniewski