JSFiddle - React, Tailwind, and code Playground
by IPWright83
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script>
JavaScript
var types = [{
name: "STRING",
groupable: true,
splittable: true,
nongroupable: true
}, {
name: "ENUM",
groupable: true,
splittable: true,
nongroupable: false
}, {
name: "BOOL",
groupable: true,
splittable: true,
nongroupable: false
}, {
name: "NUMBER",
groupable: true,
splittable: false,
nongroupable: true
}, {
name: "DATE",
groupable: true,
splittable: false,
nongroupable: true
}, ];
const groupCount = 10;
const nonGroupCount = 99;
const splitCount = 4;
class FieldTypeSet {
constructor(fieldTypes) {
this.fieldTypes = fieldTypes;
}
toString() {
return [].concat(this.fieldTypes.filter(t => t.type === "STRING"))
.concat(this.fieldTypes.filter(t => t.type === "NUMBER"))
.concat(this.fieldTypes.filter(t => t.type === "DATE"))
.concat(this.fieldTypes.filter(t => t.type === "ENUM"))
.concat(this.fieldTypes.filter(t => t.type === "BOOL"))
.map(t => t.toString());
}
}
class FieldType {
constructor(type, groupable, splittable) {
this.type = type;
}
toString() {
if (splittable) return `splittable ${this.type}`;
if (groupable) return `groupable ${this.type}`;
return `non-groupable ${this.type}`;
}
toField() {
if (splittable) return getFieldInfo(this.type, 4);
if (groupable) return getFieldInfo(this.type, 10);
return getFieldInfo(this.type, 99);
}
}
const Fields_1 = []
.concat(types.filter(t => t.groupable).map(t => `it("groupable ${t.name}", () => verify([getFieldInfo("${t.name}", ${groupCount})]));`))
.concat(["", "// Fields that can be split into multiple series"])
.concat(types.filter(t => t.nongroupable).map(t => `it("non-groupable ${t.name}", () => verify([getFieldInfo("${t.name}", ${nonGroupCount})]));`));
const Fields_2 = []
.concat(_.flattenDeep(
types.filter(t => t.groupable) // Get all the groupable types
...