All files / wdclib Table.js

100% Statements 15/15
100% Branches 8/8
100% Functions 2/2
100% Lines 15/15
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74                                              4x   4x   4x   4x   4x   4x     4x                             5x 1x   1x     4x     1x 1x       3x   3x            
/**
 *
 */
class Table {
 
    /**
     * Represents a single table which Tableau has requeste
     *
     * @param {Object} tableInfo Information about the table which has been requested.
     * This is guaranteed to be one of the tables the connector returned in the call to getSchema.
     *
     * @param {string=} incrementValue Defines the incremental update value for this table.
     * Empty string if there is not an incremental update requested.
     *
     * @param {Boolean=} isJoinFiltered Whether or not this table is meant to be filtered using filterValues.
     * @param {String=} filterColumnId If this table is filtered, this is the column where the filter values should be found.
     * @param {Array} filterValues An array of strings which specifies the values we want to retrieve.
     * For example, if an ID column was the filter column, this would be a collection of IDs to retrieve.
     *
     * @param {Function} dataCallbackFn
     */
    constructor (tableInfo, incrementValue = '', isJoinFiltered = false, filterColumnId = '', filterValues = [], dataCallbackFn) {
 
        this.tableInfo = tableInfo;
 
        this.incrementValue = incrementValue;
 
        this.isJoinFiltered = isJoinFiltered;
 
        this.filterColumnId = filterColumnId;
 
        this.filterValues = filterValues;
 
        this._dataCallbackFn = dataCallbackFn; // privacy by dangling underscore
 
        // bind the public facing version of this function so it can be passed around
        this.appendRows = this._appendRows.bind(this);
    }
 
    /**
     * Appends the given rows to the set of data contained in this table
     *
     * @param {Array} data - Either an array of arrays or an array of objects which represent the individual rows of data to append to this table
     *
     * @returns {Boolean}
     */
    _appendRows (data) {
        // note: add boolean return for testing purpose
 
        // Do some quick validation that this data is the format we expect
        // is this validation enough? shouldn't we throw an error? (Jax)
        if (!data) {
            console.warn('rows data is null or undefined');
 
            return false;
        }
 
        if (!Array.isArray(data)) {
            // Log a warning because the data is not an array like we expected
            // is this validation enough? shouldn't we throw an error? (Jax)
            console.warn('Table.appendRows must take an array of arrays or array of objects');
            return false;
        }
 
        // Call back with the rows for this table
        this._dataCallbackFn(this.tableInfo.id, data);
 
        return true;
    }
 
}
 
export default Table;