-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add collapse & expand all groups #20891
Conversation
WalkthroughWalkthroughThe updates introduce new functionality to the Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant User
participant UI as User Interface
participant DT as HaDataTable
participant Tabs as HassTabsSubpageDataTable
User->>UI: Click "Expand all"
UI->>Tabs: Trigger expand all event
Tabs->>DT: Call expandAllGroups()
DT->>DT: Expand all groups
DT-->>Tabs: Groups expanded
User->>UI: Click "Collapse all"
UI->>Tabs: Trigger collapse all event
Tabs->>DT: Call collapseAllGroups()
DT->>DT: Collapse all groups
DT-->>Tabs: Groups collapsed
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Additional Context UsedBiome (19)
Additional comments not posted (2)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 2
public expandAllGroups() { | ||
this._collapsedGroups = []; | ||
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups }); | ||
} | ||
|
||
public collapseAllGroups() { | ||
if (!this.groupColumn) { | ||
return; | ||
} | ||
const grouped = groupBy(this.data, (item) => item[this.groupColumn!]); | ||
if (grouped.undefined) { | ||
// undefined is a reserved group name | ||
grouped[UNDEFINED_GROUP_KEY] = grouped.undefined; | ||
delete grouped.undefined; | ||
} | ||
this._collapsedGroups = Object.keys(grouped); | ||
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups }); | ||
} |
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.
The methods expandAllGroups
and collapseAllGroups
are well-implemented to manage the visibility of grouped items. However, consider handling the scenario where groupColumn
is not set in collapseAllGroups
to prevent unnecessary processing.
- if (!this.groupColumn) {
- return;
- }
+ if (!this.groupColumn || !this.data.some(item => item[this.groupColumn])) {
+ console.warn('No group column set or no data to group.');
+ return;
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
public expandAllGroups() { | |
this._collapsedGroups = []; | |
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups }); | |
} | |
public collapseAllGroups() { | |
if (!this.groupColumn) { | |
return; | |
} | |
const grouped = groupBy(this.data, (item) => item[this.groupColumn!]); | |
if (grouped.undefined) { | |
// undefined is a reserved group name | |
grouped[UNDEFINED_GROUP_KEY] = grouped.undefined; | |
delete grouped.undefined; | |
} | |
this._collapsedGroups = Object.keys(grouped); | |
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups }); | |
} | |
public expandAllGroups() { | |
this._collapsedGroups = []; | |
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups }); | |
} | |
public collapseAllGroups() { | |
if (!this.groupColumn || !this.data.some(item => item[this.groupColumn])) { | |
console.warn('No group column set or no data to group.'); | |
return; | |
} | |
const grouped = groupBy(this.data, (item) => item[this.groupColumn!]); | |
if (grouped.undefined) { | |
// undefined is a reserved group name | |
grouped[UNDEFINED_GROUP_KEY] = grouped.undefined; | |
delete grouped.undefined; | |
} | |
this._collapsedGroups = Object.keys(grouped); | |
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups }); | |
} |
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.
Actionable comments posted: 1
Outside diff range comments (4)
src/components/data-table/ha-data-table.ts (4)
Line range hint
57-57
: Specify explicit types instead ofany
.Using
any
type reduces the benefits of TypeScript's static type checking. Where possible, replaceany
with more specific types to improve code safety and clarity.Also applies to: 70-70, 94-94, 619-619, 651-651, 680-680, 722-722
Line range hint
220-220
: Avoid non-null assertions.Non-null assertions can lead to runtime errors if the assumptions about data presence are incorrect. Consider adding null checks or using optional chaining to make the code more robust.
Also applies to: 535-535, 741-742, 745-745
Line range hint
234-239
: Preferfor...of
loops overforEach
.Using
for...of
loops can make the code cleaner and easier to understand, especially when dealing with asynchronous operations or when needing to break out of the loop early.Also applies to: 567-592
Line range hint
2-11
: Optimize imports.Some imports are only used as types. Consider importing them using
import type
to clarify that they are only used for type checking and not included in the JavaScript output.Also applies to: 30-31
public collapseAllGroups() { | ||
if ( | ||
!this.groupColumn || | ||
!this.data.some((item) => item[this.groupColumn!]) | ||
) { | ||
return; | ||
} | ||
const grouped = groupBy(this.data, (item) => item[this.groupColumn!]); | ||
if (grouped.undefined) { | ||
// undefined is a reserved group name | ||
grouped[UNDEFINED_GROUP_KEY] = grouped.undefined; | ||
delete grouped.undefined; | ||
} | ||
this._collapsedGroups = Object.keys(grouped); | ||
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups }); | ||
} |
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.
Add method to collapse all groups.
- if (
- !this.groupColumn ||
- !this.data.some((item) => item[this.groupColumn!])
- ) {
- return;
- }
+ if (!this.groupColumn) {
+ console.warn('No group column set.');
+ return;
+ }
+ if (!this.data.some((item) => item[this.groupColumn])) {
+ console.warn('No data to group.');
+ return;
+ }
Consider separating the checks for groupColumn
and data existence into separate conditions for clearer error messaging. Also, avoid using non-null assertions as they can lead to runtime errors if assumptions about data presence are incorrect.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
public collapseAllGroups() { | |
if ( | |
!this.groupColumn || | |
!this.data.some((item) => item[this.groupColumn!]) | |
) { | |
return; | |
} | |
const grouped = groupBy(this.data, (item) => item[this.groupColumn!]); | |
if (grouped.undefined) { | |
// undefined is a reserved group name | |
grouped[UNDEFINED_GROUP_KEY] = grouped.undefined; | |
delete grouped.undefined; | |
} | |
this._collapsedGroups = Object.keys(grouped); | |
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups }); | |
} | |
public collapseAllGroups() { | |
if (!this.groupColumn) { | |
console.warn('No group column set.'); | |
return; | |
} | |
if (!this.data.some((item) => item[this.groupColumn])) { | |
console.warn('No data to group.'); | |
return; | |
} | |
const grouped = groupBy(this.data, (item) => item[this.groupColumn!]); | |
if (grouped.undefined) { | |
// undefined is a reserved group name | |
grouped[UNDEFINED_GROUP_KEY] = grouped.undefined; | |
delete grouped.undefined; | |
} | |
this._collapsedGroups = Object.keys(grouped); | |
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups }); | |
} |
Proposed change
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed:
Summary by CodeRabbit