@bento-core/table 1.0.1-ccdiintegrated.3 → 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.
@@ -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
- label: row[dataField]
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");
@@ -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
- exports.formatColumnValues = formatColumnValues;
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;
@@ -86,16 +86,19 @@ function convertToCSV(jsonse, keysToInclude, header) {
86
86
  } else {
87
87
  line += "\"".concat(formatAgeForDownload(entry[keyName]), "\"");
88
88
  }
89
- } else if (keyName === 'last_known_survival_status' || keyName === 'sample_id' || keyName === 'data_category' || keyName === 'participant_id' || keyName === 'anatomic_site' || keyName === 'sample_description' || keyName === 'percent_tumor' || keyName === 'percent_necrosis' || keyName === 'consent_codes') {
90
- if (!entry[keyName] || entry[keyName] === '[]') {
91
- line += '';
92
- } else if (entry[keyName].toString().charAt(0) === '[' && entry[keyName].toString().charAt(entry[keyName].toString().length - 1) === ']') {
93
- line += "\"".concat(entry[keyName].toString().substring(1, entry[keyName].length - 1), "\"");
89
+ } else {
90
+ const raw = entry[keyName];
91
+ if (raw == null) {
92
+ line += ' ';
94
93
  } else {
95
- line += "\"".concat(entry[keyName], "\"");
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
+ }
96
101
  }
97
- } else {
98
- line += entry[keyName] !== null ? "\"".concat(entry[keyName], "\"") : ' ';
99
102
  }
100
103
  return line;
101
104
  });
@@ -185,57 +188,18 @@ function downloadJson(tableData, table, downloadFileName) {
185
188
  });
186
189
  let formatDataVal = (0, _Dataformat.formatColumnValues)(filterColumns, tableData);
187
190
  formatDataVal = formatDataVal.map(entry => {
188
- let survivalStatus = entry.last_known_survival_status;
189
- let sampleId = entry.sample_id;
190
- let dataCategory = entry.data_category;
191
- let participantId = entry.participant_id;
192
- let anatomicSite = entry.anatomic_site;
193
- let sampleDescription = entry.sample_description;
194
- let percentTumor = entry.percent_tumor;
195
- let percentNecrosis = entry.percent_necrosis;
196
- let consentCodes = entry.consent_codes;
197
191
  const toReturn = _objectSpread({}, entry);
198
192
  AGE_FIELDS.forEach(field => {
199
193
  if (Object.prototype.hasOwnProperty.call(entry, field) && entry[field] != null) {
200
194
  toReturn[field] = formatAgeForDownload(entry[field]);
201
195
  }
202
196
  });
203
- if (survivalStatus && survivalStatus.toString().charAt(0) === '[' && survivalStatus.toString().charAt(survivalStatus.toString().length - 1) === ']') {
204
- survivalStatus = survivalStatus.toString().substring(1, survivalStatus.length - 1);
205
- toReturn['Last Known Survival Status'] = survivalStatus;
206
- }
207
- if (sampleId && sampleId.toString().charAt(0) === '[' && sampleId.toString().charAt(sampleId.toString().length - 1) === ']') {
208
- sampleId = sampleId.toString().substring(1, sampleId.length - 1);
209
- toReturn['Sample Id'] = sampleId;
210
- }
211
- if (dataCategory && dataCategory.toString().charAt(0) === '[' && dataCategory.toString().charAt(dataCategory.toString().length - 1) === ']') {
212
- dataCategory = dataCategory.toString().substring(1, dataCategory.length - 1);
213
- toReturn['Data Category'] = dataCategory;
214
- }
215
- if (participantId && participantId.toString().charAt(0) === '[' && participantId.toString().charAt(participantId.toString().length - 1) === ']') {
216
- participantId = participantId.toString().substring(1, participantId.length - 1);
217
- toReturn['Participant ID'] = participantId;
218
- }
219
- if (anatomicSite && anatomicSite.toString().charAt(0) === '[' && anatomicSite.toString().charAt(anatomicSite.toString().length - 1) === ']') {
220
- anatomicSite = anatomicSite.toString().substring(1, anatomicSite.length - 1);
221
- toReturn['Anatomic Site'] = anatomicSite;
222
- }
223
- if (sampleDescription && sampleDescription.toString().charAt(0) === '[' && sampleDescription.toString().charAt(sampleDescription.toString().length - 1) === ']') {
224
- sampleDescription = sampleDescription.toString().substring(1, sampleDescription.length - 1);
225
- toReturn['Sample Description'] = sampleDescription;
226
- }
227
- if (percentTumor && percentTumor.toString().charAt(0) === '[' && percentTumor.toString().charAt(percentTumor.toString().length - 1) === ']') {
228
- percentTumor = percentTumor.toString().substring(1, percentTumor.length - 1);
229
- toReturn['Percent Tumor'] = percentTumor;
230
- }
231
- if (percentNecrosis && percentNecrosis.toString().charAt(0) === '[' && percentNecrosis.toString().charAt(percentNecrosis.toString().length - 1) === ']') {
232
- percentNecrosis = percentNecrosis.toString().substring(1, percentNecrosis.length - 1);
233
- toReturn['Percent Necrosis'] = percentNecrosis;
234
- }
235
- if (consentCodes && consentCodes.toString().charAt(0) === '[' && consentCodes.toString().charAt(consentCodes.toString().length - 1) === ']') {
236
- consentCodes = consentCodes.toString().substring(1, consentCodes.length - 1);
237
- toReturn['Consent Codes'] = consentCodes;
238
- }
197
+ Object.keys(toReturn).forEach(key => {
198
+ if (AGE_FIELDS.has(key)) {
199
+ return;
200
+ }
201
+ toReturn[key] = (0, _Dataformat.stripSurroundingBrackets)(toReturn[key]);
202
+ });
239
203
  toDelete.forEach(column => delete toReturn[column.dataField]);
240
204
  return toReturn;
241
205
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento-core/table",
3
- "version": "1.0.1-ccdiintegrated.3",
3
+ "version": "1.0.1-ccdiintegrated.4",
4
4
  "homepage": "https://github.com/CBIIT/bento-frontend#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/CBIIT/bento-frontend/issues"
@@ -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({ ...row, ...column, label: row[dataField] })}
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';
@@ -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,4 +1,4 @@
1
- import { formatBytes, formatColumnValues } from './Dataformat';
1
+ import { formatBytes, formatColumnValues, stripSurroundingBrackets } from './Dataformat';
2
2
  import { actionCellTypes, notIncludedCellStyle } from './Types';
3
3
 
4
4
  const AGE_FIELDS = new Set([
@@ -80,16 +80,19 @@ export function convertToCSV(jsonse, keysToInclude, header) {
80
80
  } else {
81
81
  line += `"${formatAgeForDownload(entry[keyName])}"`;
82
82
  }
83
- } else if (keyName === 'last_known_survival_status' || keyName === 'sample_id' || keyName === 'data_category' || keyName === 'participant_id' || keyName === 'anatomic_site' || keyName === 'sample_description' || keyName === 'percent_tumor' || keyName === 'percent_necrosis' || keyName === 'consent_codes') {
84
- if (!entry[keyName] || entry[keyName] === '[]') {
85
- line += '';
86
- } else if (entry[keyName].toString().charAt(0) === '[' && entry[keyName].toString().charAt(entry[keyName].toString().length - 1) === ']') {
87
- line += `"${entry[keyName].toString().substring(1, entry[keyName].length - 1)}"`;
83
+ } else {
84
+ const raw = entry[keyName];
85
+ if (raw == null) {
86
+ line += ' ';
88
87
  } else {
89
- line += `"${entry[keyName]}"`;
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
+ }
90
95
  }
91
- } else {
92
- line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
93
96
  }
94
97
  return line;
95
98
  });
@@ -134,15 +137,6 @@ export function downloadJson(tableData, table, downloadFileName) {
134
137
  .filter(({ display }) => display);
135
138
  let formatDataVal = formatColumnValues(filterColumns, tableData);
136
139
  formatDataVal = formatDataVal.map((entry) => {
137
- let survivalStatus = entry.last_known_survival_status;
138
- let sampleId = entry.sample_id;
139
- let dataCategory = entry.data_category;
140
- let participantId = entry.participant_id;
141
- let anatomicSite = entry.anatomic_site;
142
- let sampleDescription = entry.sample_description;
143
- let percentTumor = entry.percent_tumor;
144
- let percentNecrosis = entry.percent_necrosis;
145
- let consentCodes = entry.consent_codes;
146
140
  const toReturn = { ...entry };
147
141
 
148
142
  AGE_FIELDS.forEach((field) => {
@@ -151,42 +145,12 @@ export function downloadJson(tableData, table, downloadFileName) {
151
145
  }
152
146
  });
153
147
 
154
- if (survivalStatus && survivalStatus.toString().charAt(0) === '[' && survivalStatus.toString().charAt(survivalStatus.toString().length - 1) === ']') {
155
- survivalStatus = survivalStatus.toString().substring(1, survivalStatus.length - 1);
156
- toReturn['Last Known Survival Status'] = survivalStatus;
157
- }
158
- if (sampleId && sampleId.toString().charAt(0) === '[' && sampleId.toString().charAt(sampleId.toString().length - 1) === ']') {
159
- sampleId = sampleId.toString().substring(1, sampleId.length - 1);
160
- toReturn['Sample Id'] = sampleId;
161
- }
162
- if (dataCategory && dataCategory.toString().charAt(0) === '[' && dataCategory.toString().charAt(dataCategory.toString().length - 1) === ']') {
163
- dataCategory = dataCategory.toString().substring(1, dataCategory.length - 1);
164
- toReturn['Data Category'] = dataCategory;
165
- }
166
- if (participantId && participantId.toString().charAt(0) === '[' && participantId.toString().charAt(participantId.toString().length - 1) === ']') {
167
- participantId = participantId.toString().substring(1, participantId.length - 1);
168
- toReturn['Participant ID'] = participantId;
169
- }
170
- if (anatomicSite && anatomicSite.toString().charAt(0) === '[' && anatomicSite.toString().charAt(anatomicSite.toString().length - 1) === ']') {
171
- anatomicSite = anatomicSite.toString().substring(1, anatomicSite.length - 1);
172
- toReturn['Anatomic Site'] = anatomicSite;
173
- }
174
- if (sampleDescription && sampleDescription.toString().charAt(0) === '[' && sampleDescription.toString().charAt(sampleDescription.toString().length - 1) === ']') {
175
- sampleDescription = sampleDescription.toString().substring(1, sampleDescription.length - 1);
176
- toReturn['Sample Description'] = sampleDescription;
177
- }
178
- if (percentTumor && percentTumor.toString().charAt(0) === '[' && percentTumor.toString().charAt(percentTumor.toString().length - 1) === ']') {
179
- percentTumor = percentTumor.toString().substring(1, percentTumor.length - 1);
180
- toReturn['Percent Tumor'] = percentTumor;
181
- }
182
- if (percentNecrosis && percentNecrosis.toString().charAt(0) === '[' && percentNecrosis.toString().charAt(percentNecrosis.toString().length - 1) === ']') {
183
- percentNecrosis = percentNecrosis.toString().substring(1, percentNecrosis.length - 1);
184
- toReturn['Percent Necrosis'] = percentNecrosis;
185
- }
186
- if (consentCodes && consentCodes.toString().charAt(0) === '[' && consentCodes.toString().charAt(consentCodes.toString().length - 1) === ']') {
187
- consentCodes = consentCodes.toString().substring(1, consentCodes.length - 1);
188
- toReturn['Consent Codes'] = consentCodes;
189
- }
148
+ Object.keys(toReturn).forEach((key) => {
149
+ if (AGE_FIELDS.has(key)) {
150
+ return;
151
+ }
152
+ toReturn[key] = stripSurroundingBrackets(toReturn[key]);
153
+ });
190
154
 
191
155
  toDelete.forEach((column) => delete toReturn[column.dataField]);
192
156
  return toReturn;