Skip to content

Commit 0274618

Browse files
fix(itemlist): Remove header section when list is empty (#3224)
* fix(itemlist): Remove header section when list is empty * fix(itemlist): Update as per PR comment Co-authored-by: Trevor <7311041+tjuanitas@users.noreply.github.com> * fix(itemlist): Remove headerProps const * fix(itemlist): Add condition for checking noItemsRenderer --------- Co-authored-by: Trevor <7311041+tjuanitas@users.noreply.github.com>
1 parent 4ecdd81 commit 0274618

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎src/features/content-explorer/item-list/ItemList.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ const ItemList = ({
210210
};
211211
}
212212

213+
if (!noItemsRenderer || items.length > 0) {
214+
tableProps.headerHeight = headerHeight;
215+
tableProps.headerRowRenderer = headerRenderer;
216+
}
217+
213218
return (
214219
<div
215220
className={classNames('content-explorer-item-list table', className, {
@@ -221,8 +226,6 @@ const ItemList = ({
221226
headerClassName="table-header-item"
222227
width={width}
223228
height={height}
224-
headerHeight={headerHeight}
225-
headerRowRenderer={headerRenderer}
226229
rowHeight={rowHeight}
227230
rowCount={items.length}
228231
onRowClick={onItemClick}

‎src/features/content-explorer/item-list/__tests__/ItemList.test.js‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,24 +293,50 @@ describe('features/content-explorer/item-list/ItemList', () => {
293293
});
294294

295295
describe('headerHeight', () => {
296-
test('should display header row with specified height', () => {
296+
const items = [{ id: '1', name: 'item1' }];
297+
test('should display header row with specified height when item list is not empty', () => {
297298
const headerHeight = 30;
298299
const wrapper = renderComponent({
299300
headerHeight,
301+
items,
300302
});
301303

302304
const header = wrapper.find('.ReactVirtualized__Table__headerRow');
303305
expect(header.props().style.height).toBe(headerHeight);
304306
});
307+
308+
test('should not display header row with specified height when item list is empty and noItemsRenderer is present', () => {
309+
const headerHeight = 30;
310+
const noItemsRenderer = () => <></>;
311+
const wrapper = renderComponent({
312+
headerHeight,
313+
noItemsRenderer,
314+
});
315+
316+
const header = wrapper.find('.ReactVirtualized__Table__headerRow');
317+
expect(header.props().style.height).not.toBe(headerHeight);
318+
});
305319
});
306320

307321
describe('headerRenderer', () => {
308-
test('should use headerRenderer when specified', () => {
322+
const items = [{ id: '1', name: 'item1' }];
323+
test('should use headerRenderer when specified if item list is not empty', () => {
309324
const wrapper = renderComponent({
310325
headerRenderer: () => <div data-testid="customHeader">Custom Header</div>,
326+
items,
311327
});
312328
const headerRow = wrapper.find("[data-testid='customHeader']");
313329
expect(headerRow.length).toBe(1);
314330
});
331+
332+
test('should not use headerRenderer when specified if item list is empty and noItemsRenderer is present', () => {
333+
const noItemsRenderer = () => <></>;
334+
const wrapper = renderComponent({
335+
headerRenderer: () => <div data-testid="customHeader">Custom Header</div>,
336+
noItemsRenderer,
337+
});
338+
const headerRow = wrapper.find("[data-testid='customHeader']");
339+
expect(headerRow.length).not.toBe(1);
340+
});
315341
});
316342
});

0 commit comments

Comments
 (0)