constructor()

in src/templates/query.ts [46:93]


    constructor(query: string, opts: Partial<GrafanaQueryTemplate> = {}) {
        this.state = {
            query: query,
            // todo: added default
            name: opts.name || '',
            label: opts.name || '',
            datasource: opts.datasource,
            type: 'query',
            includeAll: true,
            allFormat: 'wildcard',
            allValue: null,
            refresh: false,
            multi: false,
            options: [],
            current: {},
        };

        this._required = ['name', 'datasource'];

        this._overridable = [
            'includeAll',
            'allFormat',
            'allValue',
            'multi',
            'multiFormat',
            'refresh',
            'regex',
            'tag',
            'label',
        ];

        // Override overridable values
        Object.keys(opts).forEach((opt) => {
            if (this._overridable.indexOf(opt) !== -1) {
                this.state[opt] = opts[opt];
            }
        });

        // assert required state has been populated
        this._required.forEach((reqOpt) => {
            if (!this.state[reqOpt]) {
                throw new Error('Missing Requirement: ' + reqOpt);
            }
        });

        // make state immutable after this point
        Object.freeze(this.state);
    }