synapse-react-client
Version:
[](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client) [](https://badge.fury.io/js/synaps
53 lines • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNextPageOfData = exports.getFieldIndex = void 0;
var tslib_1 = require("tslib");
var __1 = require("..");
var lodash_es_1 = require("lodash-es");
/**
* Retrieve the index of a column using the column name
* @param name the column name
* @param result the QueryResultBundle containing the columns
* @returns The index of the column, or -1 if the column doesn't exist in the result
*/
var getFieldIndex = function (name, result) {
var _a, _b;
return ((_b = (_a = result === null || result === void 0 ? void 0 : result.selectColumns) === null || _a === void 0 ? void 0 : _a.findIndex(function (el) {
return el.name === name;
})) !== null && _b !== void 0 ? _b : -1);
};
exports.getFieldIndex = getFieldIndex;
/**
* Grab the next page of data, pulling in 25 more rows.
*
* @param {*} queryRequest Query request as specified by
* https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/table/Query.html
*/
var getNextPageOfData = function (queryRequest, data, token) { return (0, tslib_1.__awaiter)(void 0, void 0, void 0, function () {
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, __1.SynapseClient.getQueryTableResults(queryRequest, token)
.then(function (newData) {
var _a;
var _b;
var oldData = (0, lodash_es_1.cloneDeep)(data);
// push on the new data retrieved from the API call
var hasMoreData = (_b = newData.queryResult.queryResults.rows.length ===
queryRequest.query.limit) !== null && _b !== void 0 ? _b : __1.SynapseConstants.DEFAULT_PAGE_SIZE;
(_a = oldData.queryResult.queryResults.rows).push.apply(_a, newData.queryResult.queryResults.rows);
var newState = {
hasMoreData: hasMoreData,
data: oldData,
};
return newState;
})
.catch(function (err) {
console.log('Failed to get data ', err);
return {};
})];
case 1: return [2 /*return*/, _a.sent()];
}
});
}); };
exports.getNextPageOfData = getNextPageOfData;
//# sourceMappingURL=queryUtils.js.map