Skip to content

Commit c4cc96b

Browse files
Copilotvnbaaij
andcommitted
Refactor DataGridCell to expose Column property instead of Columns property
Co-authored-by: vnbaaij <1761079+vnbaaij@users.noreply.github.com>
1 parent f734f33 commit c4cc96b

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

src/Core/Components/DataGrid/FluentDataGridCell.razor.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,13 @@ public partial class FluentDataGridCell<TGridItem> : FluentComponentBase
5353
/// <summary>
5454
/// Gets a reference to the column that this cell belongs to.
5555
/// </summary>
56-
private ColumnBase<TGridItem>? Column => Grid._columns.ElementAtOrDefault(GridColumn - 1);
56+
public ColumnBase<TGridItem>? Column => Grid._columns.ElementAtOrDefault(GridColumn - 1);
5757

5858
/// <summary>
5959
/// Gets a reference to the enclosing <see cref="FluentDataGrid{TGridItem}" />.
6060
/// </summary>
6161
protected FluentDataGrid<TGridItem> Grid => InternalGridContext.Grid;
6262

63-
/// <summary>
64-
/// Gets the columns associated with this data grid cell.
65-
/// </summary>
66-
public IReadOnlyList<ColumnBase<TGridItem>> Columns => Grid._columns;
67-
6863
protected string? ClassValue => new CssBuilder(Class)
6964
.AddClass("column-header", when: CellType == DataGridCellType.ColumnHeader)
7065
.AddClass("select-all", when: CellType == DataGridCellType.ColumnHeader && Column is SelectColumn<TGridItem>)

tests/Core/DataGrid/DataGridColumnsPropertyTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public void DataGridRow_Columns_Property_IsAccessible()
6666
}
6767

6868
[Fact]
69-
public void DataGridCell_Columns_Property_IsAccessible()
69+
public void DataGridCell_Column_Property_IsAccessible()
7070
{
71-
// This test validates that the Columns property was added successfully
71+
// This test validates that the Column property was made public successfully
7272
// and compiles correctly. Runtime testing would require complex setup
7373
// involving grid context and cell instantiation within a rendered grid.
7474

tests/Core/DataGrid/DataGridColumnsPropertyTestsRazor.razor

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
}
5555

5656
[Fact]
57-
public void DataGridCell_Columns_Property_AccessibleAndContainsExpectedColumns()
57+
public void DataGridCell_Column_Property_AccessibleAndContainsExpectedColumn()
5858
{
5959
// Arrange & Act
6060
var cut = Render(
@@ -72,21 +72,22 @@
7272

7373
Assert.True(dataCells.Count >= 9, "Should have at least 9 data cells (3 items × 3 columns)");
7474

75-
// Test the Columns property on the first data cell
76-
var firstCell = dataCells.First();
77-
var columns = firstCell.Instance.Columns;
75+
// Test the Column property on cells in the first row
76+
var firstRowCells = dataCells.Take(3).ToList(); // First 3 cells belong to first row
7877
79-
Assert.NotNull(columns);
80-
Assert.Equal(3, columns.Count);
78+
// Verify each cell has access to its specific column
79+
Assert.NotNull(firstRowCells[0].Instance.Column);
80+
Assert.Equal("ID", firstRowCells[0].Instance.Column?.Title);
8181

82-
// Verify column titles are accessible
83-
Assert.Equal("ID", columns[0].Title);
84-
Assert.Equal("Name", columns[1].Title);
85-
Assert.Equal("Category", columns[2].Title);
82+
Assert.NotNull(firstRowCells[1].Instance.Column);
83+
Assert.Equal("Name", firstRowCells[1].Instance.Column?.Title);
84+
85+
Assert.NotNull(firstRowCells[2].Instance.Column);
86+
Assert.Equal("Category", firstRowCells[2].Instance.Column?.Title);
8687
}
8788

8889
[Fact]
89-
public void DataGridRow_And_DataGridCell_Columns_PropertyReturnsConsistentData()
90+
public void DataGridRow_Columns_And_DataGridCell_Column_PropertyReturnsConsistentData()
9091
{
9192
// Arrange & Act
9293
var cut = Render(
@@ -103,15 +104,16 @@
103104
var firstCell = cut.FindComponents<FluentDataGridCell<TestItem>>()
104105
.First(cell => cell.Instance.CellType == DataGridCellType.Default);
105106

106-
// Assert both return the same columns data
107+
// Assert row has all columns and cell has access to its specific column
107108
var rowColumns = firstRow.Instance.Columns;
108-
var cellColumns = firstCell.Instance.Columns;
109+
var cellColumn = firstCell.Instance.Column;
110+
111+
Assert.NotNull(rowColumns);
112+
Assert.Equal(2, rowColumns.Count);
109113

110-
Assert.Equal(rowColumns.Count, cellColumns.Count);
114+
Assert.NotNull(cellColumn);
111115

112-
for (int i = 0; i < rowColumns.Count; i++)
113-
{
114-
Assert.Equal(rowColumns[i].Title, cellColumns[i].Title);
115-
}
116+
// The first cell should correspond to the first column in the row
117+
Assert.Equal(rowColumns[0].Title, cellColumn.Title);
116118
}
117119
}

0 commit comments

Comments
 (0)