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

[EuiDataGrid] Add new beta rowHeightsOptions.autoBelowLineCount feature flag #8096

Merged
merged 9 commits into from
Oct 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const useUnconstrainedHeight = ({
rowHeightOption,
defaultRowHeight,
correctRowIndex,
rowHeightUtils.isRowHeightOverride(correctRowIndex, rowHeightsOptions)
rowHeightsOptions
);
}
}
Expand Down
19 changes: 18 additions & 1 deletion packages/eui/src/components/datagrid/utils/row_heights.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ describe('RowHeightUtils', () => {
});
});

describe('autoBelowLineCount', () => {
it('uses the auto height cache', () => {
const rowIndex = 3;
const autoRowHeight = 100;
rowHeightUtils.setRowHeight(rowIndex, 'a', autoRowHeight, 0);

expect(
rowHeightUtils.getCalculatedHeight(
{ lineCount: 10 },
34,
rowIndex,
{ rowHeights: { [rowIndex]: autoRowHeight } }
)
).toEqual(autoRowHeight);
});
});

describe('row-specific overrides', () => {
it('returns the height set in the cache', () => {
const rowIndex = 5;
Expand All @@ -119,7 +136,7 @@ describe('RowHeightUtils', () => {
{ lineCount: 10 },
34,
rowIndex,
true
{ rowHeights: { [rowIndex]: rowHeightOverride } }
)
).toEqual(rowHeightOverride);
});
Expand Down
13 changes: 9 additions & 4 deletions packages/eui/src/components/datagrid/utils/row_heights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class RowHeightUtils {
heightOption: EuiDataGridRowHeightOption,
defaultHeight: number,
rowIndex?: number,
isRowHeightOverride?: boolean
rowHeightsOptions?: EuiDataGridRowHeightsOptions
) {
if (isObject(heightOption) && heightOption.height) {
return Math.max(heightOption.height, defaultHeight);
Expand All @@ -65,8 +65,13 @@ export class RowHeightUtils {
}

if (isObject(heightOption) && heightOption.lineCount) {
if (isRowHeightOverride) {
return this.getRowHeight(rowIndex!) || defaultHeight; // lineCount overrides are stored in the heights cache
const { autoBelowLineCount } = rowHeightsOptions || {}; // uses auto height cache
const isRowHeightOverride = // lineCount overrides are stored in the heights cache
rowIndex != null &&
this.isRowHeightOverride(rowIndex, rowHeightsOptions);
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved

if (autoBelowLineCount || isRowHeightOverride) {
return this.getRowHeight(rowIndex!) || defaultHeight;
} else {
return defaultHeight; // default lineCount height is set in minRowHeight state in grid_row_body
}
Expand Down Expand Up @@ -405,7 +410,7 @@ export const useDefaultRowHeight = ({
rowHeightOption,
minRowHeight,
correctRowIndex,
rowHeightUtils.isRowHeightOverride(correctRowIndex, rowHeightsOptions)
rowHeightsOptions
);
}

Expand Down