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

fix: improve types for row grouping #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

spike-rabbit
Copy link
Collaborator

What kind of change does this PR introduce? (check one with "x")

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior? (You can also link to an open issue here)

What is the new behavior?

Does this PR introduce a breaking change? (check one with "x")

  • Yes, but the note is already merged
  • No

If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...

Other information:

@spike-rabbit spike-rabbit force-pushed the fix/improve-types-remaining branch 2 times, most recently from 1d218f2 to 090d833 Compare September 26, 2024 07:17
Copy link
Member

@timowolf timowolf left a comment

Choose a reason for hiding this comment

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

Thanks, this makes sense. I added some comments. Maybe we can merge 2 types. Rebase and place to the new types to public or internal and if possible, write some documentation to the event types.

@@ -86,8 +86,7 @@ export class DataTableRowWrapperComponent<TRow = any> implements DoCheck, OnInit

@Input() set rowIndex(val: number) {
this._rowIndex = val;
this.rowContext.rowIndex = val;
this.groupContext.rowIndex = val;
(this.rowContext ?? this.groupContext).rowIndex = val;
Copy link
Member

Choose a reason for hiding this comment

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

I think we should merge group and row context types and also merge the two properties.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am against merging. Those types just share two properties. The others are different.

export interface GroupContext<TRow> {
  group: Group<TRow>;
  expanded: boolean;
  rowIndex: number;
}

export interface RowDetailContext<TRow> {
  row: TRow;
  expanded: boolean;
  rowIndex: number;
  disableRow$?: Observable<boolean>;
}

They are emitted by different directives (DatatableGroupHeaderTemplateDirective and DatatableRowDetailTemplateDirective) so merging them would make them bad as we have properties in there which are never used in certain context.

Sure, the code looks bad this way, but we need to find a better solution in another MR. Merging the interface is far more worse in my opinion as this has a negative impact on consumer.

@@ -99,7 +98,7 @@ export class DataTableRowWrapperComponent<TRow = any> implements DoCheck, OnInit

@Input() set expanded(val: boolean) {
this._expanded = val;
this.groupContext.expanded = val;
(this.groupContext ?? this.rowContext)!.expanded = val;
Copy link
Member

Choose a reason for hiding this comment

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

Merge into one property if possible and make it protected.

Comment on lines +110 to +119
groupContext?: GroupContext<TRow>;
rowContext?: RowDetailContext<TRow>;
Copy link
Member

Choose a reason for hiding this comment

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

merge to one property

@@ -14,7 +14,7 @@ export interface HeaderCellContext {
}

export interface GroupContext<TRow> {
Copy link
Member

Choose a reason for hiding this comment

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

merge with type RowDetailContext

value: Group<TRow>;
}

export interface AllGroupsToggleEvent {
Copy link
Member

Choose a reason for hiding this comment

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

I find not usage of this interface. Why do we need it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is part of the GroupToggleEvents . The AllGroupsToggleEvent type is indirectly used in DatatableGroupHeaderDirective#expandAllGroups

projects/ngx-datatable/src/lib/types/group.events.ts Outdated Show resolved Hide resolved
@timowolf
Copy link
Member

@spike-rabbit Back to you :-)

@timowolf timowolf self-requested a review September 26, 2024 11:14
Copy link
Member

@timowolf timowolf left a comment

Choose a reason for hiding this comment

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

No other review, find my comments. I pressed the re-request review button by accident.

@spike-rabbit spike-rabbit force-pushed the fix/improve-types-remaining branch 2 times, most recently from 1619e28 to 0446116 Compare September 27, 2024 07:00
@timowolf
Copy link
Member

@spike-rabbit I think the body component should also make use of the new toggle types.

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.

2 participants