Skip to content

Commit 6f58f98

Browse files
committed
MB-68819 - problem copying non-objects as TSV
The "Copy as TSV" button in Morpheus works fine when the result contains JSON objects, but it doesn't work correctly when the result contains JSON primitive values such as strings. This change enhances the TSV code to handle cases where a document might be a primitive instead of an object For a demonstration of the problem and fix, see this video: https://drive.google.com/file/d/11iVTMfdKSdHGIQ7wDemm-ecnSMJJowlm/view?usp=share_link For information on how to set up the data, see this video: https: //drive.google.com/file/d/14feLMyZG-X0pw0ueLdQRC7Y3hm32vh6i/view?usp=share_link Change-Id: I795d225fece68018838a91f7a0aa437cf45f807d Reviewed-on: https://review.couchbase.org/c/query-ui/+/240098 Well-Formed: Restriction Checker Tested-by: Eben Haber <eben@couchbase.com> Reviewed-by: Raluca Lupu <raluca.lupu@couchbase.com>
1 parent c2ae260 commit 6f58f98

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

query-ui/angular-services/qw.json.csv.service.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ function getQwJsonCsvService() {
7070
//console.log("Converting result to CSV: " + _.isArray(docArray) + ", " + docArray.length);
7171

7272
// we need an array
73-
if (!_.isArray(docArray) || docArray.length == 0)
73+
if (!_.isArray(docArray))
74+
return([docArray]);
75+
76+
// we need an array with stuff in it
77+
if (docArray.length == 0)
7478
return(data);
7579

7680
// figure out what fields we have available, by looking at each doc
@@ -121,6 +125,12 @@ function getQwJsonCsvService() {
121125
//
122126

123127
function getFields(doc,fieldInfo) {
128+
// if we have a raw value, indicate as much
129+
if (!_.isPlainObject(doc)) {
130+
fieldInfo[''] = {nonobj:true};
131+
return;
132+
}
133+
124134
// assume docs are objects. docs are permitted to be raw values like a string or
125135
// number, but that can't be flattened into CSV
126136
for (var key in doc) {
@@ -165,6 +175,11 @@ function getQwJsonCsvService() {
165175
//
166176

167177
function convertDocToArray(doc,fieldInfo,valArray) {
178+
// if the document is a raw value, we just output it as the only value in the array
179+
if (fieldInfo['']?.nonobj && !_.isPlainObject(doc)) {
180+
valArray.push(doc);
181+
return;
182+
}
168183

169184
// for each field...
170185
Object.keys(fieldInfo).sort().forEach(function(fieldName,index) {

0 commit comments

Comments
 (0)