@bento-core/table 1.0.1-ccdiintegrated.2 → 1.0.1-ccdiintegrated.4
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/body/DisplayBodyCell.js +5 -2
- package/dist/body/components/CustomLinkView.js +2 -1
- package/dist/body/components/DataFormatView.js +1 -1
- package/dist/index.js +12 -0
- package/dist/util/Dataformat.js +37 -2
- package/dist/util/downloadTable.js +52 -62
- package/package.json +1 -1
- package/src/body/DisplayBodyCell.js +9 -2
- package/src/body/components/CustomLinkView.js +2 -1
- package/src/body/components/DataFormatView.js +2 -2
- package/src/index.js +1 -1
- package/src/util/Dataformat.js +39 -0
- package/src/util/downloadTable.js +62 -63
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _core = require("@material-ui/core");
|
|
9
9
|
var _Types = require("../util/Types");
|
|
10
|
+
var _Dataformat = require("../util/Dataformat");
|
|
10
11
|
var _CustomLinkView = _interopRequireDefault(require("./components/CustomLinkView"));
|
|
11
12
|
var _DataFormatView = _interopRequireDefault(require("./components/DataFormatView"));
|
|
12
13
|
var _CPIView = _interopRequireDefault(require("./components/CPIView"));
|
|
@@ -30,8 +31,10 @@ const CustomComponent = _ref => {
|
|
|
30
31
|
dataField,
|
|
31
32
|
customCellRender
|
|
32
33
|
} = column;
|
|
34
|
+
const stripped = (0, _Dataformat.stripSurroundingBrackets)(row[dataField]);
|
|
33
35
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, customCellRender(_objectSpread(_objectSpread(_objectSpread({}, row), column), {}, {
|
|
34
|
-
|
|
36
|
+
[dataField]: stripped,
|
|
37
|
+
label: (0, _Dataformat.formatValueForDisplay)(row[dataField])
|
|
35
38
|
})));
|
|
36
39
|
};
|
|
37
40
|
|
|
@@ -87,7 +90,7 @@ const ViewCell = _ref2 => {
|
|
|
87
90
|
column: column
|
|
88
91
|
});
|
|
89
92
|
default:
|
|
90
|
-
return /*#__PURE__*/_react.default.createElement(_core.Typography, null, row[column.dataField]);
|
|
93
|
+
return /*#__PURE__*/_react.default.createElement(_core.Typography, null, (0, _Dataformat.formatValueForDisplay)(row[column.dataField]));
|
|
91
94
|
}
|
|
92
95
|
};
|
|
93
96
|
const DisplayCell = _ref3 => {
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _core = require("@material-ui/core");
|
|
9
9
|
var _Types = require("../../util/Types");
|
|
10
|
+
var _Dataformat = require("../../util/Dataformat");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
/**
|
|
12
13
|
* Custom Link component
|
|
@@ -24,7 +25,7 @@ const CustomLinkView = _ref => {
|
|
|
24
25
|
return /*#__PURE__*/_react.default.createElement(_core.Link, {
|
|
25
26
|
href: url,
|
|
26
27
|
className: _Types.cellTypes.LINK
|
|
27
|
-
}, /*#__PURE__*/_react.default.createElement(_core.Typography, null, row[column === null || column === void 0 ? void 0 : column.dataField]));
|
|
28
|
+
}, /*#__PURE__*/_react.default.createElement(_core.Typography, null, (0, _Dataformat.formatValueForDisplay)(row[column === null || column === void 0 ? void 0 : column.dataField])));
|
|
28
29
|
};
|
|
29
30
|
var _default = CustomLinkView;
|
|
30
31
|
exports.default = _default;
|
|
@@ -26,7 +26,7 @@ const CellView = _ref => {
|
|
|
26
26
|
case _Types.dataFormatTypes.FORMAT_BYTES:
|
|
27
27
|
return /*#__PURE__*/_react.default.createElement(_core.Typography, null, (0, _Dataformat.formatBytes)(value));
|
|
28
28
|
default:
|
|
29
|
-
return /*#__PURE__*/_react.default.createElement(_core.Typography, null, value);
|
|
29
|
+
return /*#__PURE__*/_react.default.createElement(_core.Typography, null, (0, _Dataformat.formatValueForDisplay)(value));
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
const DataFormatView = _ref2 => {
|
package/dist/index.js
CHANGED
|
@@ -45,12 +45,24 @@ Object.defineProperty(exports, "formatBytes", {
|
|
|
45
45
|
return _Dataformat.formatBytes;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
+
Object.defineProperty(exports, "formatValueForDisplay", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function get() {
|
|
51
|
+
return _Dataformat.formatValueForDisplay;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
48
54
|
Object.defineProperty(exports, "headerTypes", {
|
|
49
55
|
enumerable: true,
|
|
50
56
|
get: function get() {
|
|
51
57
|
return _Types.headerTypes;
|
|
52
58
|
}
|
|
53
59
|
});
|
|
60
|
+
Object.defineProperty(exports, "stripSurroundingBrackets", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function get() {
|
|
63
|
+
return _Dataformat.stripSurroundingBrackets;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
54
66
|
var _TableView = _interopRequireDefault(require("./TableView"));
|
|
55
67
|
var _Types = require("./util/Types");
|
|
56
68
|
var _Dataformat = require("./util/Dataformat");
|
package/dist/util/Dataformat.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.formatBytes = formatBytes;
|
|
7
|
-
exports.formatColumnValues = void 0;
|
|
7
|
+
exports.stripSurroundingBrackets = exports.formatValueForDisplay = exports.formatColumnValues = void 0;
|
|
8
8
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
9
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
10
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -52,4 +52,39 @@ const formatColumnValues = (columns, data) => {
|
|
|
52
52
|
}
|
|
53
53
|
return data;
|
|
54
54
|
};
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Remove wrapping square brackets from OpenSearch array-as-string values.
|
|
58
|
+
* "[Complete Response]" => "Complete Response"; "[]" => "".
|
|
59
|
+
*/
|
|
60
|
+
exports.formatColumnValues = formatColumnValues;
|
|
61
|
+
const stripSurroundingBrackets = value => {
|
|
62
|
+
if (value == null) {
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
return value.map(item => stripSurroundingBrackets(item));
|
|
67
|
+
}
|
|
68
|
+
const text = String(value).trim();
|
|
69
|
+
if (text === '[]') {
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
if (text.startsWith('[') && text.endsWith(']')) {
|
|
73
|
+
return text.slice(1, -1).trim();
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** Display helper: strip wrapping brackets and join arrays. */
|
|
79
|
+
exports.stripSurroundingBrackets = stripSurroundingBrackets;
|
|
80
|
+
const formatValueForDisplay = value => {
|
|
81
|
+
const stripped = stripSurroundingBrackets(value);
|
|
82
|
+
if (Array.isArray(stripped)) {
|
|
83
|
+
return stripped.map(item => item == null ? '' : String(item)).filter(Boolean).join(', ');
|
|
84
|
+
}
|
|
85
|
+
if (stripped == null) {
|
|
86
|
+
return '';
|
|
87
|
+
}
|
|
88
|
+
return String(stripped);
|
|
89
|
+
};
|
|
90
|
+
exports.formatValueForDisplay = formatValueForDisplay;
|
|
@@ -7,6 +7,7 @@ exports.convertToCSV = convertToCSV;
|
|
|
7
7
|
exports.createFileName = createFileName;
|
|
8
8
|
exports.downloadCSV = downloadCSV;
|
|
9
9
|
exports.downloadJson = downloadJson;
|
|
10
|
+
exports.formatAgeForDownload = formatAgeForDownload;
|
|
10
11
|
var _Dataformat = require("./Dataformat");
|
|
11
12
|
var _Types = require("./Types");
|
|
12
13
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -14,6 +15,31 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
14
15
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
16
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
17
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
|
+
const AGE_FIELDS = new Set(['age_at_diagnosis', 'participant_age_at_collection', 'age_at_treatment_start', 'age_at_treatment_end', 'age_at_response', 'age_at_last_known_survival_status', 'age_at_event_free_survival_status']);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Sentinel OpenSearch age values (-999) become "Not Reported" for CSV/JSON download.
|
|
22
|
+
* Supports scalars, arrays (files table), and bracketed strings.
|
|
23
|
+
*/
|
|
24
|
+
function formatAgeForDownload(value) {
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
if (value.length === 0) {
|
|
27
|
+
return 'Not Reported';
|
|
28
|
+
}
|
|
29
|
+
return value.map(item => formatAgeForDownload(item)).join('; ');
|
|
30
|
+
}
|
|
31
|
+
if (value === -999 || value === '-999' || value == null || value === '') {
|
|
32
|
+
return 'Not Reported';
|
|
33
|
+
}
|
|
34
|
+
if (typeof value === 'string' && value.startsWith('[') && value.endsWith(']')) {
|
|
35
|
+
const inner = value.slice(1, -1).trim();
|
|
36
|
+
if (!inner) {
|
|
37
|
+
return 'Not Reported';
|
|
38
|
+
}
|
|
39
|
+
return inner.split(',').map(item => formatAgeForDownload(item.trim())).join('; ');
|
|
40
|
+
}
|
|
41
|
+
return String(value);
|
|
42
|
+
}
|
|
17
43
|
function createFileName(fileName, type) {
|
|
18
44
|
const date = new Date();
|
|
19
45
|
const yyyy = date.getFullYear();
|
|
@@ -54,22 +80,25 @@ function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
54
80
|
if (line !== '') line += ',';
|
|
55
81
|
if (keyName === 'file_size') {
|
|
56
82
|
line += entry[keyName] !== null ? "\"".concat((0, _Dataformat.formatBytes)(entry[keyName]), "\"") : ' ';
|
|
57
|
-
} else if (keyName
|
|
58
|
-
if (entry[keyName]
|
|
59
|
-
line += '
|
|
83
|
+
} else if (AGE_FIELDS.has(keyName)) {
|
|
84
|
+
if (entry[keyName] == null) {
|
|
85
|
+
line += ' ';
|
|
60
86
|
} else {
|
|
61
|
-
line +=
|
|
87
|
+
line += "\"".concat(formatAgeForDownload(entry[keyName]), "\"");
|
|
62
88
|
}
|
|
63
|
-
} else
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
line += "\"".concat(entry[keyName].toString().substring(1, entry[keyName].length - 1), "\"");
|
|
89
|
+
} else {
|
|
90
|
+
const raw = entry[keyName];
|
|
91
|
+
if (raw == null) {
|
|
92
|
+
line += ' ';
|
|
68
93
|
} else {
|
|
69
|
-
|
|
94
|
+
const stripped = (0, _Dataformat.stripSurroundingBrackets)(raw);
|
|
95
|
+
if (stripped === '' || stripped === '[]') {
|
|
96
|
+
line += '';
|
|
97
|
+
} else {
|
|
98
|
+
const display = Array.isArray(stripped) ? stripped.join(', ') : stripped;
|
|
99
|
+
line += "\"".concat(display, "\"");
|
|
100
|
+
}
|
|
70
101
|
}
|
|
71
|
-
} else {
|
|
72
|
-
line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
|
|
73
102
|
}
|
|
74
103
|
return line;
|
|
75
104
|
});
|
|
@@ -159,57 +188,18 @@ function downloadJson(tableData, table, downloadFileName) {
|
|
|
159
188
|
});
|
|
160
189
|
let formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
|
|
161
190
|
formatDataVal = formatDataVal.map(entry => {
|
|
162
|
-
let survivalStatus = entry.last_known_survival_status;
|
|
163
|
-
let sampleId = entry.sample_id;
|
|
164
|
-
let dataCategory = entry.data_category;
|
|
165
|
-
let participantId = entry.participant_id;
|
|
166
|
-
let anatomicSite = entry.anatomic_site;
|
|
167
|
-
let ageAtCollection = entry.participant_age_at_collection;
|
|
168
|
-
let sampleDescription = entry.sample_description;
|
|
169
|
-
let percentTumor = entry.percent_tumor;
|
|
170
|
-
let percentNecrosis = entry.percent_necrosis;
|
|
171
|
-
let consentCodes = entry.consent_codes;
|
|
172
191
|
const toReturn = _objectSpread({}, entry);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
if (participantId && participantId.toString().charAt(0) === '[' && participantId.toString().charAt(participantId.toString().length - 1) === ']') {
|
|
186
|
-
participantId = participantId.toString().substring(1, participantId.length - 1);
|
|
187
|
-
toReturn['Participant ID'] = participantId;
|
|
188
|
-
}
|
|
189
|
-
if (anatomicSite && anatomicSite.toString().charAt(0) === '[' && anatomicSite.toString().charAt(anatomicSite.toString().length - 1) === ']') {
|
|
190
|
-
anatomicSite = anatomicSite.toString().substring(1, anatomicSite.length - 1);
|
|
191
|
-
toReturn['Anatomic Site'] = anatomicSite;
|
|
192
|
-
}
|
|
193
|
-
if (ageAtCollection && ageAtCollection.toString().charAt(0) === '[' && ageAtCollection.toString().charAt(ageAtCollection.toString().length - 1) === ']') {
|
|
194
|
-
ageAtCollection = ageAtCollection.toString().substring(1, ageAtCollection.length - 1);
|
|
195
|
-
toReturn['Age at Collection'] = ageAtCollection;
|
|
196
|
-
}
|
|
197
|
-
if (sampleDescription && sampleDescription.toString().charAt(0) === '[' && sampleDescription.toString().charAt(sampleDescription.toString().length - 1) === ']') {
|
|
198
|
-
sampleDescription = sampleDescription.toString().substring(1, sampleDescription.length - 1);
|
|
199
|
-
toReturn['Sample Description'] = sampleDescription;
|
|
200
|
-
}
|
|
201
|
-
if (percentTumor && percentTumor.toString().charAt(0) === '[' && percentTumor.toString().charAt(percentTumor.toString().length - 1) === ']') {
|
|
202
|
-
percentTumor = percentTumor.toString().substring(1, percentTumor.length - 1);
|
|
203
|
-
toReturn['Percent Tumor'] = percentTumor;
|
|
204
|
-
}
|
|
205
|
-
if (percentNecrosis && percentNecrosis.toString().charAt(0) === '[' && percentNecrosis.toString().charAt(percentNecrosis.toString().length - 1) === ']') {
|
|
206
|
-
percentNecrosis = percentNecrosis.toString().substring(1, percentNecrosis.length - 1);
|
|
207
|
-
toReturn['Percent Necrosis'] = percentNecrosis;
|
|
208
|
-
}
|
|
209
|
-
if (consentCodes && consentCodes.toString().charAt(0) === '[' && consentCodes.toString().charAt(consentCodes.toString().length - 1) === ']') {
|
|
210
|
-
consentCodes = consentCodes.toString().substring(1, consentCodes.length - 1);
|
|
211
|
-
toReturn['Consent Codes'] = consentCodes;
|
|
212
|
-
}
|
|
192
|
+
AGE_FIELDS.forEach(field => {
|
|
193
|
+
if (Object.prototype.hasOwnProperty.call(entry, field) && entry[field] != null) {
|
|
194
|
+
toReturn[field] = formatAgeForDownload(entry[field]);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
Object.keys(toReturn).forEach(key => {
|
|
198
|
+
if (AGE_FIELDS.has(key)) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
toReturn[key] = (0, _Dataformat.stripSurroundingBrackets)(toReturn[key]);
|
|
202
|
+
});
|
|
213
203
|
toDelete.forEach(column => delete toReturn[column.dataField]);
|
|
214
204
|
return toReturn;
|
|
215
205
|
});
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
Typography,
|
|
5
5
|
} from '@material-ui/core';
|
|
6
6
|
import { cellTypes } from '../util/Types';
|
|
7
|
+
import { formatValueForDisplay, stripSurroundingBrackets } from '../util/Dataformat';
|
|
7
8
|
import CustomLinkView from './components/CustomLinkView';
|
|
8
9
|
import DataFormatView from './components/DataFormatView';
|
|
9
10
|
import CPIView from './components/CPIView';
|
|
@@ -18,9 +19,15 @@ const CustomComponent = ({
|
|
|
18
19
|
column,
|
|
19
20
|
}) => {
|
|
20
21
|
const { dataField, customCellRender } = column;
|
|
22
|
+
const stripped = stripSurroundingBrackets(row[dataField]);
|
|
21
23
|
return (
|
|
22
24
|
<>
|
|
23
|
-
{customCellRender({
|
|
25
|
+
{customCellRender({
|
|
26
|
+
...row,
|
|
27
|
+
...column,
|
|
28
|
+
[dataField]: stripped,
|
|
29
|
+
label: stripped,
|
|
30
|
+
})}
|
|
24
31
|
</>
|
|
25
32
|
);
|
|
26
33
|
};
|
|
@@ -88,7 +95,7 @@ const ViewCell = ({
|
|
|
88
95
|
default:
|
|
89
96
|
return (
|
|
90
97
|
<Typography>
|
|
91
|
-
{row[column.dataField]}
|
|
98
|
+
{formatValueForDisplay(row[column.dataField])}
|
|
92
99
|
</Typography>
|
|
93
100
|
);
|
|
94
101
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
Link, Typography,
|
|
4
4
|
} from '@material-ui/core';
|
|
5
5
|
import { cellTypes } from '../../util/Types';
|
|
6
|
+
import { formatValueForDisplay } from '../../util/Dataformat';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Custom Link component
|
|
@@ -16,7 +17,7 @@ const CustomLinkView = ({
|
|
|
16
17
|
return (
|
|
17
18
|
<Link href={url} className={cellTypes.LINK}>
|
|
18
19
|
<Typography>
|
|
19
|
-
{row[column?.dataField]}
|
|
20
|
+
{formatValueForDisplay(row[column?.dataField])}
|
|
20
21
|
</Typography>
|
|
21
22
|
</Link>
|
|
22
23
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Typography } from '@material-ui/core';
|
|
3
3
|
import { dataFormatTypes } from '../../util/Types';
|
|
4
|
-
import { formatBytes } from '../../util/Dataformat';
|
|
4
|
+
import { formatBytes, formatValueForDisplay } from '../../util/Dataformat';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* dataformat view for file size (byte, MB, GB)
|
|
@@ -23,7 +23,7 @@ const CellView = ({
|
|
|
23
23
|
default:
|
|
24
24
|
return (
|
|
25
25
|
<Typography>
|
|
26
|
-
{value}
|
|
26
|
+
{formatValueForDisplay(value)}
|
|
27
27
|
</Typography>
|
|
28
28
|
);
|
|
29
29
|
}
|
package/src/index.js
CHANGED
|
@@ -6,5 +6,5 @@ export {
|
|
|
6
6
|
ComponentTypes,
|
|
7
7
|
dataFormatTypes,
|
|
8
8
|
} from './util/Types';
|
|
9
|
-
export { formatBytes } from './util/Dataformat';
|
|
9
|
+
export { formatBytes, stripSurroundingBrackets, formatValueForDisplay } from './util/Dataformat';
|
|
10
10
|
export { default as AddToCart } from './wrapper/components/AddToCart/ReduxAddToCart';
|
package/src/util/Dataformat.js
CHANGED
|
@@ -31,3 +31,42 @@ export const formatColumnValues = (columns, data) => {
|
|
|
31
31
|
}
|
|
32
32
|
return data;
|
|
33
33
|
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Remove wrapping square brackets from OpenSearch array-as-string values.
|
|
37
|
+
* "[Complete Response]" => "Complete Response"; "[]" => "".
|
|
38
|
+
*/
|
|
39
|
+
export const stripSurroundingBrackets = (value) => {
|
|
40
|
+
if (value == null) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
return value.map((item) => stripSurroundingBrackets(item));
|
|
45
|
+
}
|
|
46
|
+
if (typeof value !== 'string') {
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
const text = value.trim();
|
|
50
|
+
if (text === '[]') {
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
if (text.startsWith('[') && text.endsWith(']')) {
|
|
54
|
+
return text.slice(1, -1).trim();
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** Display helper: strip wrapping brackets and join arrays. */
|
|
60
|
+
export const formatValueForDisplay = (value) => {
|
|
61
|
+
const stripped = stripSurroundingBrackets(value);
|
|
62
|
+
if (Array.isArray(stripped)) {
|
|
63
|
+
return stripped
|
|
64
|
+
.map((item) => (item == null ? '' : String(item)))
|
|
65
|
+
.filter(Boolean)
|
|
66
|
+
.join(', ');
|
|
67
|
+
}
|
|
68
|
+
if (stripped == null) {
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
return String(stripped);
|
|
72
|
+
};
|
|
@@ -1,6 +1,40 @@
|
|
|
1
|
-
import { formatBytes, formatColumnValues } from './Dataformat';
|
|
1
|
+
import { formatBytes, formatColumnValues, stripSurroundingBrackets } from './Dataformat';
|
|
2
2
|
import { actionCellTypes, notIncludedCellStyle } from './Types';
|
|
3
3
|
|
|
4
|
+
const AGE_FIELDS = new Set([
|
|
5
|
+
'age_at_diagnosis',
|
|
6
|
+
'participant_age_at_collection',
|
|
7
|
+
'age_at_treatment_start',
|
|
8
|
+
'age_at_treatment_end',
|
|
9
|
+
'age_at_response',
|
|
10
|
+
'age_at_last_known_survival_status',
|
|
11
|
+
'age_at_event_free_survival_status',
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Sentinel OpenSearch age values (-999) become "Not Reported" for CSV/JSON download.
|
|
16
|
+
* Supports scalars, arrays (files table), and bracketed strings.
|
|
17
|
+
*/
|
|
18
|
+
export function formatAgeForDownload(value) {
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
if (value.length === 0) {
|
|
21
|
+
return 'Not Reported';
|
|
22
|
+
}
|
|
23
|
+
return value.map((item) => formatAgeForDownload(item)).join('; ');
|
|
24
|
+
}
|
|
25
|
+
if (value === -999 || value === '-999' || value == null || value === '') {
|
|
26
|
+
return 'Not Reported';
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === 'string' && value.startsWith('[') && value.endsWith(']')) {
|
|
29
|
+
const inner = value.slice(1, -1).trim();
|
|
30
|
+
if (!inner) {
|
|
31
|
+
return 'Not Reported';
|
|
32
|
+
}
|
|
33
|
+
return inner.split(',').map((item) => formatAgeForDownload(item.trim())).join('; ');
|
|
34
|
+
}
|
|
35
|
+
return String(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
4
38
|
export function createFileName(fileName, type) {
|
|
5
39
|
const date = new Date();
|
|
6
40
|
const yyyy = date.getFullYear();
|
|
@@ -40,22 +74,25 @@ export function convertToCSV(jsonse, keysToInclude, header) {
|
|
|
40
74
|
if (line !== '') line += ',';
|
|
41
75
|
if (keyName === 'file_size') {
|
|
42
76
|
line += entry[keyName] !== null ? `"${formatBytes(entry[keyName])}"` : ' ';
|
|
43
|
-
} else if (keyName
|
|
44
|
-
if (entry[keyName]
|
|
45
|
-
line += '
|
|
77
|
+
} else if (AGE_FIELDS.has(keyName)) {
|
|
78
|
+
if (entry[keyName] == null) {
|
|
79
|
+
line += ' ';
|
|
46
80
|
} else {
|
|
47
|
-
line +=
|
|
81
|
+
line += `"${formatAgeForDownload(entry[keyName])}"`;
|
|
48
82
|
}
|
|
49
|
-
} else
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
line += `"${entry[keyName].toString().substring(1, entry[keyName].length - 1)}"`;
|
|
83
|
+
} else {
|
|
84
|
+
const raw = entry[keyName];
|
|
85
|
+
if (raw == null) {
|
|
86
|
+
line += ' ';
|
|
54
87
|
} else {
|
|
55
|
-
|
|
88
|
+
const stripped = stripSurroundingBrackets(raw);
|
|
89
|
+
if (stripped === '' || stripped === '[]') {
|
|
90
|
+
line += '';
|
|
91
|
+
} else {
|
|
92
|
+
const display = Array.isArray(stripped) ? stripped.join(', ') : stripped;
|
|
93
|
+
line += `"${display}"`;
|
|
94
|
+
}
|
|
56
95
|
}
|
|
57
|
-
} else {
|
|
58
|
-
line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
|
|
59
96
|
}
|
|
60
97
|
return line;
|
|
61
98
|
});
|
|
@@ -100,58 +137,20 @@ export function downloadJson(tableData, table, downloadFileName) {
|
|
|
100
137
|
.filter(({ display }) => display);
|
|
101
138
|
let formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
102
139
|
formatDataVal = formatDataVal.map((entry) => {
|
|
103
|
-
let survivalStatus = entry.last_known_survival_status;
|
|
104
|
-
let sampleId = entry.sample_id;
|
|
105
|
-
let dataCategory = entry.data_category;
|
|
106
|
-
let participantId = entry.participant_id;
|
|
107
|
-
let anatomicSite = entry.anatomic_site;
|
|
108
|
-
let ageAtCollection = entry.participant_age_at_collection;
|
|
109
|
-
let sampleDescription = entry.sample_description;
|
|
110
|
-
let percentTumor = entry.percent_tumor;
|
|
111
|
-
let percentNecrosis = entry.percent_necrosis;
|
|
112
|
-
let consentCodes = entry.consent_codes;
|
|
113
140
|
const toReturn = { ...entry };
|
|
114
141
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
toReturn[
|
|
126
|
-
}
|
|
127
|
-
if (participantId && participantId.toString().charAt(0) === '[' && participantId.toString().charAt(participantId.toString().length - 1) === ']') {
|
|
128
|
-
participantId = participantId.toString().substring(1, participantId.length - 1);
|
|
129
|
-
toReturn['Participant ID'] = participantId;
|
|
130
|
-
}
|
|
131
|
-
if (anatomicSite && anatomicSite.toString().charAt(0) === '[' && anatomicSite.toString().charAt(anatomicSite.toString().length - 1) === ']') {
|
|
132
|
-
anatomicSite = anatomicSite.toString().substring(1, anatomicSite.length - 1);
|
|
133
|
-
toReturn['Anatomic Site'] = anatomicSite;
|
|
134
|
-
}
|
|
135
|
-
if (ageAtCollection && ageAtCollection.toString().charAt(0) === '[' && ageAtCollection.toString().charAt(ageAtCollection.toString().length - 1) === ']') {
|
|
136
|
-
ageAtCollection = ageAtCollection.toString().substring(1, ageAtCollection.length - 1);
|
|
137
|
-
toReturn['Age at Collection'] = ageAtCollection;
|
|
138
|
-
}
|
|
139
|
-
if (sampleDescription && sampleDescription.toString().charAt(0) === '[' && sampleDescription.toString().charAt(sampleDescription.toString().length - 1) === ']') {
|
|
140
|
-
sampleDescription = sampleDescription.toString().substring(1, sampleDescription.length - 1);
|
|
141
|
-
toReturn['Sample Description'] = sampleDescription;
|
|
142
|
-
}
|
|
143
|
-
if (percentTumor && percentTumor.toString().charAt(0) === '[' && percentTumor.toString().charAt(percentTumor.toString().length - 1) === ']') {
|
|
144
|
-
percentTumor = percentTumor.toString().substring(1, percentTumor.length - 1);
|
|
145
|
-
toReturn['Percent Tumor'] = percentTumor;
|
|
146
|
-
}
|
|
147
|
-
if (percentNecrosis && percentNecrosis.toString().charAt(0) === '[' && percentNecrosis.toString().charAt(percentNecrosis.toString().length - 1) === ']') {
|
|
148
|
-
percentNecrosis = percentNecrosis.toString().substring(1, percentNecrosis.length - 1);
|
|
149
|
-
toReturn['Percent Necrosis'] = percentNecrosis;
|
|
150
|
-
}
|
|
151
|
-
if (consentCodes && consentCodes.toString().charAt(0) === '[' && consentCodes.toString().charAt(consentCodes.toString().length - 1) === ']') {
|
|
152
|
-
consentCodes = consentCodes.toString().substring(1, consentCodes.length - 1);
|
|
153
|
-
toReturn['Consent Codes'] = consentCodes;
|
|
154
|
-
}
|
|
142
|
+
AGE_FIELDS.forEach((field) => {
|
|
143
|
+
if (Object.prototype.hasOwnProperty.call(entry, field) && entry[field] != null) {
|
|
144
|
+
toReturn[field] = formatAgeForDownload(entry[field]);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
Object.keys(toReturn).forEach((key) => {
|
|
149
|
+
if (AGE_FIELDS.has(key)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
toReturn[key] = stripSurroundingBrackets(toReturn[key]);
|
|
153
|
+
});
|
|
155
154
|
|
|
156
155
|
toDelete.forEach((column) => delete toReturn[column.dataField]);
|
|
157
156
|
return toReturn;
|