@bento-core/table 1.0.0-c3dc.15 → 1.0.0-c3dc.16
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.
|
@@ -49,6 +49,26 @@ const DownloadButton = _ref => {
|
|
|
49
49
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
50
50
|
}
|
|
51
51
|
const client = (0, _client.useApolloClient)();
|
|
52
|
+
function cleanData(result) {
|
|
53
|
+
function hasHTMLTags(str) {
|
|
54
|
+
const htmlTagPattern = /<\/?[a-z][\s\S]*>/i; // Regex to match HTML tags
|
|
55
|
+
return htmlTagPattern.test(str);
|
|
56
|
+
}
|
|
57
|
+
const cleanedResult = result.map(res => {
|
|
58
|
+
const newObj = {};
|
|
59
|
+
Object.keys(res).forEach(key => {
|
|
60
|
+
if (hasHTMLTags(res[key])) {
|
|
61
|
+
const div = document.createElement('div');
|
|
62
|
+
div.innerHTML = res[key];
|
|
63
|
+
newObj[key] = div.textContent || div.innerText || res[key];
|
|
64
|
+
} else {
|
|
65
|
+
newObj[key] = res[key];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return newObj;
|
|
69
|
+
});
|
|
70
|
+
return cleanedResult;
|
|
71
|
+
}
|
|
52
72
|
async function downloadSCSVFile() {
|
|
53
73
|
const {
|
|
54
74
|
query,
|
|
@@ -68,7 +88,7 @@ const DownloadButton = _ref => {
|
|
|
68
88
|
}
|
|
69
89
|
return response.data;
|
|
70
90
|
});
|
|
71
|
-
(0, _downloadTable.downloadData)(result, table, table.downloadFileName, 'csv');
|
|
91
|
+
(0, _downloadTable.downloadData)(cleanData(result), table, table.downloadFileName, 'csv');
|
|
72
92
|
}
|
|
73
93
|
async function downloadJsonFile() {
|
|
74
94
|
const {
|
|
@@ -89,7 +109,7 @@ const DownloadButton = _ref => {
|
|
|
89
109
|
}
|
|
90
110
|
return response.data;
|
|
91
111
|
});
|
|
92
|
-
(0, _downloadTable.downloadData)(result, table, table.downloadFileName, 'json');
|
|
112
|
+
(0, _downloadTable.downloadData)(cleanData(result), table, table.downloadFileName, 'json');
|
|
93
113
|
}
|
|
94
114
|
const downloadTableCSV = (0, _react.useCallback)(() => {
|
|
95
115
|
downloadSCSVFile();
|
package/package.json
CHANGED
|
@@ -47,6 +47,27 @@ const DownloadButton = ({
|
|
|
47
47
|
|
|
48
48
|
const client = useApolloClient();
|
|
49
49
|
|
|
50
|
+
function cleanData(result) {
|
|
51
|
+
function hasHTMLTags(str) {
|
|
52
|
+
const htmlTagPattern = /<\/?[a-z][\s\S]*>/i; // Regex to match HTML tags
|
|
53
|
+
return htmlTagPattern.test(str);
|
|
54
|
+
}
|
|
55
|
+
const cleanedResult = result.map((res) => {
|
|
56
|
+
const newObj = {};
|
|
57
|
+
Object.keys(res).forEach((key) => {
|
|
58
|
+
if (hasHTMLTags(res[key])) {
|
|
59
|
+
const div = document.createElement('div');
|
|
60
|
+
div.innerHTML = res[key];
|
|
61
|
+
newObj[key] = div.textContent || div.innerText || res[key];
|
|
62
|
+
} else {
|
|
63
|
+
newObj[key] = res[key];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return newObj;
|
|
67
|
+
});
|
|
68
|
+
return cleanedResult;
|
|
69
|
+
}
|
|
70
|
+
|
|
50
71
|
async function downloadSCSVFile() {
|
|
51
72
|
const {
|
|
52
73
|
query,
|
|
@@ -69,7 +90,8 @@ const DownloadButton = ({
|
|
|
69
90
|
}
|
|
70
91
|
return response.data;
|
|
71
92
|
});
|
|
72
|
-
|
|
93
|
+
|
|
94
|
+
downloadData(cleanData(result), table, table.downloadFileName, 'csv');
|
|
73
95
|
}
|
|
74
96
|
|
|
75
97
|
async function downloadJsonFile() {
|
|
@@ -94,7 +116,7 @@ const DownloadButton = ({
|
|
|
94
116
|
}
|
|
95
117
|
return response.data;
|
|
96
118
|
});
|
|
97
|
-
downloadData(result, table, table.downloadFileName, 'json');
|
|
119
|
+
downloadData(cleanData(result), table, table.downloadFileName, 'json');
|
|
98
120
|
}
|
|
99
121
|
|
|
100
122
|
const downloadTableCSV = useCallback(() => {
|