@quintype/components 3.5.0 → 3.5.1-csv-table.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +20 -17
- package/dist/es/components/story-elements/table.js +21 -17
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -3118,9 +3118,10 @@ function _createSuper$8(Derived) { var hasNativeReflectConstruct = _isNativeRefl
|
|
|
3118
3118
|
|
|
3119
3119
|
function _isNativeReflectConstruct$8() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
3120
3120
|
|
|
3121
|
-
function TableHeader(
|
|
3121
|
+
function TableHeader() {
|
|
3122
|
+
var columns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
3122
3123
|
return /*#__PURE__*/React__default["default"].createElement("thead", null, /*#__PURE__*/React__default["default"].createElement("tr", null, columns.map(function (col) {
|
|
3123
|
-
return /*#__PURE__*/React__default["default"].createElement("th", null, col
|
|
3124
|
+
return /*#__PURE__*/React__default["default"].createElement("th", null, col);
|
|
3124
3125
|
})));
|
|
3125
3126
|
}
|
|
3126
3127
|
|
|
@@ -3132,8 +3133,8 @@ function TableView(_ref) {
|
|
|
3132
3133
|
return /*#__PURE__*/React__default["default"].createElement("table", {
|
|
3133
3134
|
className: className
|
|
3134
3135
|
}, hasHeader && TableHeader(columns), /*#__PURE__*/React__default["default"].createElement("tbody", null, data.map(function (row) {
|
|
3135
|
-
return /*#__PURE__*/React__default["default"].createElement("tr", null,
|
|
3136
|
-
return /*#__PURE__*/React__default["default"].createElement("td", null,
|
|
3136
|
+
return /*#__PURE__*/React__default["default"].createElement("tr", null, row.map(function (item) {
|
|
3137
|
+
return /*#__PURE__*/React__default["default"].createElement("td", null, item);
|
|
3137
3138
|
}));
|
|
3138
3139
|
})));
|
|
3139
3140
|
}
|
|
@@ -3147,6 +3148,7 @@ var Table = /*#__PURE__*/function (_React$Component) {
|
|
|
3147
3148
|
|
|
3148
3149
|
_classCallCheck__default["default"](this, Table);
|
|
3149
3150
|
|
|
3151
|
+
// props.data = {content: '', content-type: 'csv'}
|
|
3150
3152
|
_this = _super.call(this, props);
|
|
3151
3153
|
_this.state = {
|
|
3152
3154
|
tableData: []
|
|
@@ -3164,7 +3166,8 @@ var Table = /*#__PURE__*/function (_React$Component) {
|
|
|
3164
3166
|
'papaparse')); }).then(function (_ref2) {
|
|
3165
3167
|
var parse = _ref2.parse;
|
|
3166
3168
|
parse(content, {
|
|
3167
|
-
header:
|
|
3169
|
+
header: false,
|
|
3170
|
+
// with header true, the order of columns in table is not guaranteed, so we will handle the case
|
|
3168
3171
|
complete: function complete(results) {
|
|
3169
3172
|
return _this2._isMounted && _this2.setState({
|
|
3170
3173
|
tableData: results.data
|
|
@@ -3177,7 +3180,9 @@ var Table = /*#__PURE__*/function (_React$Component) {
|
|
|
3177
3180
|
key: "componentDidMount",
|
|
3178
3181
|
value: function componentDidMount() {
|
|
3179
3182
|
this._isMounted = true;
|
|
3180
|
-
this.parseCSVToJson(this.props.data.content);
|
|
3183
|
+
this.parseCSVToJson(this.props.data.content); // csv string
|
|
3184
|
+
|
|
3185
|
+
console.log("aa--qc-tableData", this.state.tableData);
|
|
3181
3186
|
}
|
|
3182
3187
|
}, {
|
|
3183
3188
|
key: "componentWillUnmount",
|
|
@@ -3187,6 +3192,8 @@ var Table = /*#__PURE__*/function (_React$Component) {
|
|
|
3187
3192
|
}, {
|
|
3188
3193
|
key: "componentWillReceiveProps",
|
|
3189
3194
|
value: function componentWillReceiveProps(nextProps) {
|
|
3195
|
+
console.log("aa--qc-nextProps", nextProps);
|
|
3196
|
+
|
|
3190
3197
|
if (this.props.data.content !== nextProps.data.content) {
|
|
3191
3198
|
this.parseCSVToJson(nextProps.data.content);
|
|
3192
3199
|
}
|
|
@@ -3194,25 +3201,21 @@ var Table = /*#__PURE__*/function (_React$Component) {
|
|
|
3194
3201
|
}, {
|
|
3195
3202
|
key: "render",
|
|
3196
3203
|
value: function render() {
|
|
3197
|
-
|
|
3204
|
+
console.log("aa--qc-tableLength", this.state.tableData.length);
|
|
3198
3205
|
|
|
3199
3206
|
if (!this.state.tableData.length > 0) {
|
|
3200
3207
|
return null;
|
|
3201
3208
|
}
|
|
3202
3209
|
|
|
3203
|
-
var
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
display: "none"
|
|
3209
|
-
} : {}
|
|
3210
|
-
};
|
|
3211
|
-
});
|
|
3210
|
+
var _ref3 = this.props.hasHeader ? [this.state.tableData[0], this.state.tableData.slice(1)] : [[], this.state.tableData],
|
|
3211
|
+
_ref4 = _slicedToArray__default["default"](_ref3, 2),
|
|
3212
|
+
columns = _ref4[0],
|
|
3213
|
+
tableData = _ref4[1];
|
|
3214
|
+
|
|
3212
3215
|
var className = "story-element-table-".concat(this.props.id);
|
|
3213
3216
|
return /*#__PURE__*/React__default["default"].createElement(this.props.tableComponent || TableView, {
|
|
3214
3217
|
hasHeader: this.props.hasHeader,
|
|
3215
|
-
data:
|
|
3218
|
+
data: tableData,
|
|
3216
3219
|
columns: columns,
|
|
3217
3220
|
showPageSizeOptions: false,
|
|
3218
3221
|
showPageJump: false,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
4
|
import _inherits from "@babel/runtime/helpers/inherits";
|
|
@@ -10,9 +11,10 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
10
11
|
|
|
11
12
|
import React from "react";
|
|
12
13
|
|
|
13
|
-
function TableHeader(
|
|
14
|
+
function TableHeader() {
|
|
15
|
+
var columns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
14
16
|
return /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, columns.map(function (col) {
|
|
15
|
-
return /*#__PURE__*/React.createElement("th", null, col
|
|
17
|
+
return /*#__PURE__*/React.createElement("th", null, col);
|
|
16
18
|
})));
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -24,8 +26,8 @@ export function TableView(_ref) {
|
|
|
24
26
|
return /*#__PURE__*/React.createElement("table", {
|
|
25
27
|
className: className
|
|
26
28
|
}, hasHeader && TableHeader(columns), /*#__PURE__*/React.createElement("tbody", null, data.map(function (row) {
|
|
27
|
-
return /*#__PURE__*/React.createElement("tr", null,
|
|
28
|
-
return /*#__PURE__*/React.createElement("td", null,
|
|
29
|
+
return /*#__PURE__*/React.createElement("tr", null, row.map(function (item) {
|
|
30
|
+
return /*#__PURE__*/React.createElement("td", null, item);
|
|
29
31
|
}));
|
|
30
32
|
})));
|
|
31
33
|
}
|
|
@@ -39,6 +41,7 @@ export var Table = /*#__PURE__*/function (_React$Component) {
|
|
|
39
41
|
|
|
40
42
|
_classCallCheck(this, Table);
|
|
41
43
|
|
|
44
|
+
// props.data = {content: '', content-type: 'csv'}
|
|
42
45
|
_this = _super.call(this, props);
|
|
43
46
|
_this.state = {
|
|
44
47
|
tableData: []
|
|
@@ -56,7 +59,8 @@ export var Table = /*#__PURE__*/function (_React$Component) {
|
|
|
56
59
|
"papaparse").then(function (_ref2) {
|
|
57
60
|
var parse = _ref2.parse;
|
|
58
61
|
parse(content, {
|
|
59
|
-
header:
|
|
62
|
+
header: false,
|
|
63
|
+
// with header true, the order of columns in table is not guaranteed, so we will handle the case
|
|
60
64
|
complete: function complete(results) {
|
|
61
65
|
return _this2._isMounted && _this2.setState({
|
|
62
66
|
tableData: results.data
|
|
@@ -69,7 +73,9 @@ export var Table = /*#__PURE__*/function (_React$Component) {
|
|
|
69
73
|
key: "componentDidMount",
|
|
70
74
|
value: function componentDidMount() {
|
|
71
75
|
this._isMounted = true;
|
|
72
|
-
this.parseCSVToJson(this.props.data.content);
|
|
76
|
+
this.parseCSVToJson(this.props.data.content); // csv string
|
|
77
|
+
|
|
78
|
+
console.log("aa--qc-tableData", this.state.tableData);
|
|
73
79
|
}
|
|
74
80
|
}, {
|
|
75
81
|
key: "componentWillUnmount",
|
|
@@ -79,6 +85,8 @@ export var Table = /*#__PURE__*/function (_React$Component) {
|
|
|
79
85
|
}, {
|
|
80
86
|
key: "componentWillReceiveProps",
|
|
81
87
|
value: function componentWillReceiveProps(nextProps) {
|
|
88
|
+
console.log("aa--qc-nextProps", nextProps);
|
|
89
|
+
|
|
82
90
|
if (this.props.data.content !== nextProps.data.content) {
|
|
83
91
|
this.parseCSVToJson(nextProps.data.content);
|
|
84
92
|
}
|
|
@@ -86,25 +94,21 @@ export var Table = /*#__PURE__*/function (_React$Component) {
|
|
|
86
94
|
}, {
|
|
87
95
|
key: "render",
|
|
88
96
|
value: function render() {
|
|
89
|
-
|
|
97
|
+
console.log("aa--qc-tableLength", this.state.tableData.length);
|
|
90
98
|
|
|
91
99
|
if (!this.state.tableData.length > 0) {
|
|
92
100
|
return null;
|
|
93
101
|
}
|
|
94
102
|
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
display: "none"
|
|
101
|
-
} : {}
|
|
102
|
-
};
|
|
103
|
-
});
|
|
103
|
+
var _ref3 = this.props.hasHeader ? [this.state.tableData[0], this.state.tableData.slice(1)] : [[], this.state.tableData],
|
|
104
|
+
_ref4 = _slicedToArray(_ref3, 2),
|
|
105
|
+
columns = _ref4[0],
|
|
106
|
+
tableData = _ref4[1];
|
|
107
|
+
|
|
104
108
|
var className = "story-element-table-".concat(this.props.id);
|
|
105
109
|
return /*#__PURE__*/React.createElement(this.props.tableComponent || TableView, {
|
|
106
110
|
hasHeader: this.props.hasHeader,
|
|
107
|
-
data:
|
|
111
|
+
data: tableData,
|
|
108
112
|
columns: columns,
|
|
109
113
|
showPageSizeOptions: false,
|
|
110
114
|
showPageJump: false,
|