@integec/grid-tools
Version:
Integ Grid Tools
91 lines (70 loc) • 4.98 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createData = exports.headers = exports.randomRow = undefined;
var _range = require('ramda/src/range');
var _range2 = _interopRequireDefault(_range);
var _map = require('ramda/src/map');
var _map2 = _interopRequireDefault(_map);
var _fromPairs = require('ramda/src/fromPairs');
var _fromPairs2 = _interopRequireDefault(_fromPairs);
var _compose = require('ramda/src/compose');
var _compose2 = _interopRequireDefault(_compose);
var _chance = require('chance');
var _chance2 = _interopRequireDefault(_chance);
var _moment = require('moment');
var _moment2 = _interopRequireDefault(_moment);
var _cols = require('../cols');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var chance = new _chance2.default();
//* test helpers
var randomRow = exports.randomRow = (0, _compose2.default)(_fromPairs2.default, (0, _map2.default)(function (_ref) {
var ident = _ref.ident,
type = _ref.type,
dataFormat = _ref.dataFormat,
numFormat = _ref.numFormat;
if (ident === 'commitStatusOvr') return [ident, chance.pickone(['UNA', 'ECO', 'EMER', 'MUST'])];
if (ident === 'unitId') return [ident, chance.pickone(['u1', 'u2', 'u3', 'u4'])];
if (ident === 'he') return [ident, chance.integer({ min: 1, max: 24 })];
switch (type) {
case 'str':
case 'sel':
return [ident, chance.word()];
case 'num':
return [ident, chance.floating({ fixed: 2, min: 0, max: 50000 })];
case 'bool':
return [ident, chance.bool()];
case 'date-time':
return [ident, (0, _moment2.default)(chance.date()).format(dataFormat)];
}
}));
/**
* The following are example of what choices and dataFormatter should be
* They are not normally created this way
* the toSelectionColProps function in utils.js
* should be used to create these 2 objects.
* They are coded this way here to demostrate what their strcutrues should be
*/
// TODO add documentation
/** choices */
var unitChoices = [{ value: 'u1', text: 'Unit 4' }, { value: 'u2', text: 'Unit 1' }, { value: 'u3', text: 'Unit 2' }, { value: 'u4', text: 'Unit 3' }];
var unitMap = {
u1: 'Unit4',
u2: 'Unit1',
u3: 'Unit2',
u4: 'Unit3'
// TODO add documentation
/** data-formatter */
};var unitDataFormatter = function unitDataFormatter(_ref2) {
var value = _ref2.value,
header = _ref2.header;
return unitMap[value] || value;
};
/* prettier-ignore */
var headers = exports.headers = [(0, _cols.dateCol)({ ident: 'transDate', display: 'Trans-Date', width: 120, isKey: true }), (0, _cols.strCol)({ ident: 'unitId', display: 'Unit', width: 180, isKey: true, dataFormatter: unitDataFormatter, choices: unitChoices }), (0, _cols.intCol)({ ident: 'he', display: 'HE', width: 40, isKey: true, numFormat: "0" }), (0, _cols.strCol)({ ident: 'fixedGen', display: 'Fixed Gen' }), (0, _cols.numCol)({ ident: 'emerMinOvr', display: 'Emer Min', width: 120, alignment: 'right', displayFormat: null }), (0, _cols.numCol)({ ident: 'ecoMinOvr', display: 'Eco Min' }), (0, _cols.numCol)({ ident: 'ecoMaxOvr', display: 'Eco Max' }), (0, _cols.numCol)({ ident: 'emerMaxOvr', display: 'Emer Max' }), (0, _cols.strCol)({ ident: 'commitStatusOvr', display: 'Commit Status' }), (0, _cols.numCol)({ ident: 'regMwOvr', display: 'Reg Mw' }), (0, _cols.numCol)({ ident: 'regMinOvr', display: 'Reg Min' }), (0, _cols.numCol)({ ident: 'regMaxOvr', display: 'Reg Max' }), (0, _cols.strCol)({ ident: 'regAStatusOvr', display: 'Reg A Status' }), (0, _cols.strCol)({ ident: 'spilling', display: 'Spilling' }), (0, _cols.pctCol)({ ident: 'reducedRampRatePct', display: 'Reduce Ramp Percent', width: 220 }), (0, _cols.dollarCol)({ ident: 'regAPrice', display: 'Reg A Price', width: 120 }), (0, _cols.dollarCol)({ ident: 'regACost', display: 'Reg A Cost', width: 120 }), (0, _cols.dollarCol)({ ident: 'regAPerfPrice', display: 'Reg A Perf Price', width: 120 }), (0, _cols.dollarCol)({ ident: 'regAPerfCost', display: 'Reg A Perf Cost', width: 120 }), (0, _cols.strCol)({ ident: 'regDStatus', display: 'Reg D status' }), (0, _cols.dollarCol)({ ident: 'regDPrice', display: 'Reg D Price', width: 120 }), (0, _cols.dollarCol)({ ident: 'regDCost', display: 'Reg D Cost', width: 120 }), (0, _cols.dollarCol)({ ident: 'regDPerfPrice', display: 'Reg D Perf Price', width: 120 }), (0, _cols.dollarCol)({ ident: 'regDPerfCost', display: 'Reg D Perf Cost', width: 120 }), (0, _cols.numCol)({ ident: 'spinMwOvr', display: 'Spin Mw' }), (0, _cols.numCol)({ ident: 'spinMaxOvr', display: 'Spin Max' }), (0, _cols.strCol)({ ident: 'spinStatusOvr', display: 'Spin Status' }), (0, _cols.dollarCol)({ ident: 'spinPrice', display: 'Spin Price', width: 120 })];
var createRow = function createRow(_) {
return randomRow(headers);
};
var createData = exports.createData = (0, _compose2.default)((0, _map2.default)(createRow), (0, _range2.default)(0));
//# sourceMappingURL=data.js.map