Add min/max row/columns to resize card editor
Proposed change
Allows card to provide a min and max rows and columns for resize card editor in a grid. I implemented it on 4 cards (future PRs will be open for others cards):
- tile card
- entity card
- thermostat card
- humidifier card
Tile card : Not possible to resize the height because it's calculated according to features
Entity card : Free resize if there is a footer (to enlarge a graph for example).
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
- [ ] The code change is tested and works locally.
- [ ] 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:
- [ ] Documentation added/updated for www.home-assistant.io
Summary by CodeRabbit
-
New Features
- Enhanced grid size editor to dynamically disable sliders based on column and row constraints.
- Added layout options calculation for various Lovelace cards, enabling dynamic grid configurations.
-
Refactor
- Improved grid size computation with a new
computeSizeOnGridfunction for more accurate layout calculations.
- Improved grid size computation with a new
-
Style
- Updated the slider styling to better differentiate between active and disabled states.
[!NOTE]
Reviews paused
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Walkthrough
The updates enhance Lovelace panels and components by incorporating dynamic grid layout calculations. Key additions include the introduction of getLayoutOptions methods across multiple card classes, implementation of the computeSizeOnGrid function for grid calculations, and modifications to the look and behavior of the HaGridLayoutSlider. These changes collectively improve the flexibility and responsiveness of the Lovelace interface, offering customizable grid configurations based on card features and conditions.
Changes
| File(s) | Summary |
|---|---|
src/components/ha-grid-size-picker.ts |
Introduced disabledColumns and disabledRows to conditionally disable sliders in HaGridSizeEditor component based on min/max values. |
src/panels/lovelace/cards/hui-entity-card.ts, hui-humidifier-card.ts, hui-thermostat-card.ts, hui-tile-card.ts |
Added/updated getLayoutOptions() methods in card classes to calculate layout options based on configuration. |
src/panels/lovelace/editor/card-editor/sections/.../hui-grid-section.ts |
Replaced DEFAULT_GRID_OPTIONS with computeSizeOnGrid function for precise grid size calculations and added GridSizeValue type for rows/columns representation. |
src/panels/lovelace/editor/card-editor/.../hui-card-layout-editor.ts |
Updated functionality to merge default and provided layout options, directly compute grid sizes, and modify render method for layout configuration based on merged options. |
src/panels/lovelace/editor/card-editor/ha-grid-layout-slider.ts |
Altered HaGridLayoutSlider class by adjusting the structure and styles of slider elements, including background and active element opacities, and disabled state styling. |
src/panels/lovelace/types.ts |
Expanded LovelaceLayoutOptions interface to include grid_max_columns, grid_min_columns, grid_min_rows, and grid_max_rows properties for enhanced layout configuration across Lovelace panels. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant UI as Lovelace UI
participant Card as LovelaceCard
participant Editor as HaGridSizeEditor
User->>UI: Load Lovelace Panel
UI->>Card: Instantiates Card
Card->>Card: Call getLayoutOptions()
Card->>UI: Return layout options
UI->>Editor: Open Layout Editor
Editor->>Editor: Calculate disabledColumns and disabledRows
Editor->>UI: Render with updated grid layout and sliders
sequenceDiagram
participant User
participant UI as Lovelace UI
participant Slider as HaGridLayoutSlider
User->>UI: Load Grid Layout Editor
UI->>Slider: Instantiate Slider
Slider->>Slider: Adjust track structure, background and active elements
Slider->>UI: Render with new styles and behaviors
These diagrams illustrate the interaction flow for loading Lovelace cards with dynamic layout options and updating the grid layout editor with redesigned sliders.
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?
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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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 pause