@talend/react-components
Version:
Set of react components.
130 lines (119 loc) • 3.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.extractSpecialFields = extractSpecialFields;
exports.getCellData = getCellData;
exports.getCellRenderer = getCellRenderer;
exports.getCellType = getCellType;
exports.getColumnData = getColumnData;
exports.getDataKey = getDataKey;
exports.getId = getId;
exports.getLabel = getLabel;
exports.getRowData = getRowData;
exports.renderCell = renderCell;
var _react = require("react");
var _CellTitle = require("../CellTitle");
var _constants = require("./constants");
/**
* This utility file contains any common functions that are used in row renderers
* - get infos from parent props, content field, ...
* - render a cell
* - ...
*/
/**
* Get the cell renderer from VirtualizedList.Content configuration
* @param field The VirtualizedList.Content instance
*/
function getCellRenderer(field) {
return field.props.cellRenderer;
}
/**
* Get the cellType from VirtualizedList.Content configuration
* @param field The VirtualizedList.Content instance
*/
function getCellType(field) {
return field.props.cellType;
}
/**
* Get the id from row parent instance
* @param parent The row parent instance
*/
function getId(parent) {
return parent.props.id;
}
/**
* Enhance VirtualizedList.Content columnData with the row parent id
* @param field The VirtualizedList.Content instance
*/
function getColumnData(field) {
return field.props.columnData;
}
/**
* Get the data property key from VirtualizedList.Content instance
* @param field The VirtualizedList.Content instance
*/
function getDataKey(field) {
return field.props.dataKey;
}
/**
* Get the content label from VirtualizedList.Content instance
* @param field The VirtualizedList.Content instance
*/
function getLabel(field) {
return field.props.label;
}
/**
* Get the collection item
* @param parent The row parent instance
* @param index The item index in the collection
*/
function getRowData(parent, index) {
return parent.props.rowGetter(index);
}
/**
* Get cell data
* @param field The VirtualizedList.Content instance
* @param parent The row instance
* @param index The item index in collection
*/
function getCellData(field, parent, index) {
return field.props.cellDataGetter({
columnData: getColumnData(field),
dataKey: getDataKey(field),
rowData: getRowData(parent, index)
});
}
/**
* Extract the title VirtualizedList.Content from the other ones
* @param parent The row parent
*/
function extractSpecialFields(parent) {
const children = _react.Children.toArray(parent.props.children);
const titleField = children.find(field => getCellType(field) === _CellTitle.cellType);
const selectionField = children.find(field => field.props.id === _constants.internalIds.rowSelector);
const otherFields = children.filter(field => field !== titleField && field !== selectionField);
return {
titleField,
selectionField,
otherFields
};
}
/**
* Render a cell
* @param index The item index in collection
* @param parent The row parent instance
* @param field The VirtualizedList.Content instance
*/
function renderCell(index, parent, field, type) {
const cellRenderer = getCellRenderer(field);
return cellRenderer({
cellData: getCellData(field, parent, index),
columnData: getColumnData(field),
dataKey: getDataKey(field),
rowData: getRowData(parent, index),
rowIndex: index,
type
});
}
//# sourceMappingURL=gridrow.js.map