terra-table
Version:
The Terra Table component provides user a way to display data in an accessible table format.
62 lines (61 loc) • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
/**
* Returns an object with the section ids and the row ids of the first row and last row in non-collapsed and non-empty sections.
* @param {Object} Object conforming to the state.columnHighlightRowData shape.
*/
var getFirstAndLastVisibleRowData = function getFirstAndLastVisibleRowData(sections) {
var rowData = {
firstRowId: null,
lastRowId: null
};
if (sections.length < 1) {
/**
* If the sections prop is empty, there is no work to do here.
*/
return rowData;
}
var findNotEmptyOrCollapsed = function findNotEmptyOrCollapsed(section) {
if (section.subsections) {
return section.subsections.length > 0 && !section.isCollapsed;
}
return section.rows.length > 0 && !section.isCollapsed;
};
var visibleSections = sections.filter(findNotEmptyOrCollapsed);
if (visibleSections.length < 1) {
/**
* If the filtered list is empty after removing sections that contain no rows,
* plus removing sections that are collapsed, there is no more work to do here.
*/
return rowData;
}
for (var i = 0; i < visibleSections.length; i += 1) {
var rows = visibleSections[i].rows;
if (rows && rows.length) {
rowData.firstRowId = rows[0].id;
break;
}
}
if (!rowData.firstRowId) {
/**
* If no first row is found after filtering out rows marked as decorative,
* no last row will be found either. There is no more work to do here.
*/
return rowData;
}
for (var _i = visibleSections.length - 1; _i >= 0; _i -= 1) {
var _rows = visibleSections[_i].rows;
if (_rows && _rows.length) {
rowData.lastRowId = _rows[_rows.length - 1].id;
break;
}
}
return rowData;
};
var tableUtils = {
getFirstAndLastVisibleRowData: getFirstAndLastVisibleRowData
};
var _default = exports.default = tableUtils;