All files / datamodel/src field-store.js

100% Statements 18/18
100% Branches 6/6
100% Functions 3/3
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43      1x       387x 387x       318x 318x 1306x   318x     36x 36x 148x 72x     36x     18x 18x 74x 38x     18x     387x          
import { FieldType } from './enums';
import { getUniqueId } from './utils';
 
const fieldStore = {
    data: {},
 
    createNamespace (fieldArr, name) {
        const dataId = name || getUniqueId();
        this.data[dataId] = {
            name: dataId,
            fields: fieldArr,
            fieldsObj () {
                const retObj = {};
                this.fields.forEach((field) => {
                    retObj[field.name] = field;
                });
                return retObj;
            },
            getMeasure () {
                const retObj = {};
                this.fields.forEach((field) => {
                    if (field.schema.type === FieldType.MEASURE) {
                        retObj[field.name] = field;
                    }
                });
                return retObj;
            },
            getDimension () {
                const retObj = {};
                this.fields.forEach((field) => {
                    if (field.schema.type === FieldType.DIMENSION) {
                        retObj[field.name] = field;
                    }
                });
                return retObj;
            },
        };
        return this.data[dataId];
    },
};
 
export default fieldStore;