PromucFlow_constructor/app/client/src/widgets/TableWidget/derived.js

74 lines
2.0 KiB
JavaScript
Raw Normal View History

export default {
getSelectedRow: (props) => {
const selectedRowIndex =
props.selectedRowIndex === undefined ||
Number.isNaN(parseInt(props.selectedRowIndex))
? -1
: parseInt(props.selectedRowIndex);
const filteredTableData = props.filteredTableData || props.tableData || [];
if (selectedRowIndex === -1) {
const emptyRow = { ...filteredTableData[0] };
Object.keys(emptyRow).forEach((key) => {
emptyRow[key] = "";
});
return emptyRow;
}
const selectedRow = { ...filteredTableData[selectedRowIndex] };
return selectedRow;
},
//
getSelectedRows: (props) => {
const selectedRowIndices = props.selectedRowIndices || [];
const filteredTableData = props.filteredTableData || props.tableData || [];
const selectedRows = selectedRowIndices.map(
(ind) => filteredTableData[ind],
);
return selectedRows;
},
//
getPageSize: (props) => {
const TABLE_SIZES = {
DEFAULT: {
COLUMN_HEADER_HEIGHT: 38,
TABLE_HEADER_HEIGHT: 42,
ROW_HEIGHT: 40,
ROW_FONT_SIZE: 14,
},
SHORT: {
COLUMN_HEADER_HEIGHT: 38,
TABLE_HEADER_HEIGHT: 42,
ROW_HEIGHT: 20,
ROW_FONT_SIZE: 12,
},
TALL: {
COLUMN_HEADER_HEIGHT: 38,
TABLE_HEADER_HEIGHT: 42,
ROW_HEIGHT: 60,
ROW_FONT_SIZE: 18,
},
};
const compactMode = props.compactMode || "DEFAULT";
const componentHeight =
(props.bottomRow - props.topRow) * props.parentRowSpace;
const tableSizes = TABLE_SIZES[compactMode];
let pageSize = Math.floor(
(componentHeight -
tableSizes.TABLE_HEADER_HEIGHT -
tableSizes.COLUMN_HEADER_HEIGHT) /
tableSizes.ROW_HEIGHT,
);
if (
componentHeight -
(tableSizes.TABLE_HEADER_HEIGHT +
tableSizes.COLUMN_HEADER_HEIGHT +
tableSizes.ROW_HEIGHT * pageSize) >
0
) {
pageSize += 1;
}
return pageSize;
},
//
};