ze-react-component-library
Version:
ZeroETP React Component Library
79 lines (64 loc) • 2.25 kB
JavaScript
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
import { getNameProperty } from "zeroetp-api-sdk";
var getIDKey = function getIDKey(prop, item) {
if (!prop.schema) {
return item[prop.name];
}
var nameProp = getNameProperty(prop.schema);
return item[prop.name][nameProp.name];
};
export var transposeResult = function transposeResult(ret, firstColumnName, horizontalColumns) {
var _a;
var result = ret.result,
columnProperties = ret.columnProperties;
var newData = [];
var newColumnProperties = []; // 1. 搞newColumnProperties
// 后面几列的数据变为第一列。要求后面几列的type一样
newColumnProperties.push({
name: firstColumnName,
type: "string",
primal_type: "string",
constraints: {}
}); // 第一列的数据变为columnProperties。
if (horizontalColumns) {
for (var _i = 0, horizontalColumns_1 = horizontalColumns; _i < horizontalColumns_1.length; _i++) {
var item = horizontalColumns_1[_i];
newColumnProperties.push(__assign(__assign({}, columnProperties[1]), {
name: item
}));
}
} else {
for (var _b = 0, result_1 = result; _b < result_1.length; _b++) {
var item = result_1[_b];
newColumnProperties.push(__assign(__assign({}, columnProperties[1]), {
name: getIDKey(columnProperties[0], item)
}));
}
} // 除去第一列,后面有几列,就是数据有几行
for (var i = 1; i < columnProperties.length; i++) {
var property = columnProperties[i];
var item = (_a = {
_id: property.name
}, _a[firstColumnName] = property.name, _a); // 横过来
for (var _c = 0, result_2 = result; _c < result_2.length; _c++) {
var i_1 = result_2[_c];
item[getIDKey(columnProperties[0], i_1)] = i_1[property.name];
}
newData.push(item);
}
return __assign(__assign({}, ret), {
columnProperties: newColumnProperties,
result: newData
});
};