Skip to content

Conversation

ImmortalRabbit
Copy link
Contributor

Introduced rowGroupingMapper with type overload to make sure when itemOrRow is type of number it should return RowGroupingMapperResult<number> and when type if Item it should return RowGroupingMapperResult<Item>

@lukasmasuch lukasmasuch requested a review from Copilot August 19, 2025 17:36
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the typing for the useRowGrouping hook by introducing a new rowGroupingMapper function with proper type overloads to ensure type safety when working with row grouping operations.

Key changes:

  • Introduced rowGroupingMapper function with type overloads for number and Item parameters
  • Removed the deprecated MapResult interface in favor of RowGroupingMapperResult<T>
  • Simplified the RowGroupingMapper type definition

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/core/src/data-editor/row-grouping.ts Removed MapResult interface and updated mapRowIndexToPath return type
packages/core/src/data-editor/row-grouping-api.ts Added rowGroupingMapper function with type overloads and refactored the mapper implementation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


// grid relative index to path and other details
export function mapRowIndexToPath(row: number, flattenedRowGroups?: readonly FlattenedRowGroup[]): MapResult {
export function mapRowIndexToPath(row: number, flattenedRowGroups?: readonly FlattenedRowGroup[]): RowGroupingMapperResult<number> {
if (flattenedRowGroups === undefined || flattenRowGroups.length === 0)
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

There's a typo in the variable name. It should be flattenedRowGroups.length instead of flattenRowGroups.length. The function parameter is flattenedRowGroups but the condition checks flattenRowGroups (missing 'd').

Suggested change
if (flattenedRowGroups === undefined || flattenRowGroups.length === 0)
if (flattenedRowGroups === undefined || flattenedRowGroups.length === 0)

Copilot uses AI. Check for mistakes.

(itemOrRow: number): RowGroupingMapperResult<number>;
(itemOrRow: Item): RowGroupingMapperResult<Item>;
};
export type RowGroupingMapper = (itemOrRow: number | Item) => RowGroupingMapperResult<Item | number>;
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The RowGroupingMapper type loses type safety by returning a union type RowGroupingMapperResult<Item | number>. This contradicts the purpose of the type overloads in rowGroupingMapper. Consider using function overloads for this type as well to maintain type safety.

Suggested change
export type RowGroupingMapper = (itemOrRow: number | Item) => RowGroupingMapperResult<Item | number>;
export type RowGroupingMapper = {
(itemOrRow: number, flattenedRowGroups?: readonly FlattenedRowGroup[] | undefined): RowGroupingMapperResult<number>;
(itemOrRow: Item, flattenedRowGroups?: readonly FlattenedRowGroup[] | undefined): RowGroupingMapperResult<Item>;
};

Copilot uses AI. Check for mistakes.

export function rowGroupingMapper(itemOrRow: number, flattenedRowGroups?: readonly FlattenedRowGroup[] | undefined): RowGroupingMapperResult<number>;
export function rowGroupingMapper(itemOrRow: Item, flattenedRowGroups?: readonly FlattenedRowGroup[] | undefined): RowGroupingMapperResult<Item>;
export function rowGroupingMapper(itemOrRow: number | Item, flattenedRowGroups?: readonly FlattenedRowGroup[] | undefined): RowGroupingMapperResult<number> | RowGroupingMapperResult<Item>;
export function rowGroupingMapper(itemOrRow: number | Item, flattenedRowGroups?: readonly FlattenedRowGroup[] | undefined): RowGroupingMapperResult<number> | RowGroupingMapperResult<Item> {
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The implementation signature includes redundant | undefined since the parameter is already marked as optional with ?. Remove | undefined from the parameter type.

Suggested change
export function rowGroupingMapper(itemOrRow: number | Item, flattenedRowGroups?: readonly FlattenedRowGroup[] | undefined): RowGroupingMapperResult<number> | RowGroupingMapperResult<Item> {
export function rowGroupingMapper(itemOrRow: number, flattenedRowGroups?: readonly FlattenedRowGroup[]): RowGroupingMapperResult<number>;
export function rowGroupingMapper(itemOrRow: Item, flattenedRowGroups?: readonly FlattenedRowGroup[]): RowGroupingMapperResult<Item>;
export function rowGroupingMapper(itemOrRow: number | Item, flattenedRowGroups?: readonly FlattenedRowGroup[]): RowGroupingMapperResult<number> | RowGroupingMapperResult<Item>;
export function rowGroupingMapper(itemOrRow: number | Item, flattenedRowGroups?: readonly FlattenedRowGroup[]): RowGroupingMapperResult<number> | RowGroupingMapperResult<Item> {

Copilot uses AI. Check for mistakes.

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.

1 participant