Browse Source

refine code

czhen 3 years ago
parent
commit
84913cafab
2 changed files with 4 additions and 3 deletions
  1. 2 2
      client/src/pages/query/Query.tsx
  2. 2 1
      client/src/utils/Format.ts

+ 2 - 2
client/src/pages/query/Query.tsx

@@ -82,8 +82,8 @@ const Query: FC<{
   );
 
   const csvDataMemo = useMemo(() => {
-    const headers = fields?.map(i => i.name);
-    if (headers && queryResult) {
+    const headers: string[] = fields?.map(i => i.name);
+    if (headers?.length && queryResult?.length) {
       return generateCsvData(headers, queryResult);
     }
     return '';

+ 2 - 1
client/src/utils/Format.ts

@@ -201,7 +201,8 @@ export const generateCsvData = (headers: string[], rows: any[]) => {
       if (typeof val === 'string') {
         prev += val;
       } else if (typeof val === 'object') {
-        prev += `"[${val}]"`;
+        // Use double quote to ensure csv display correctly
+        prev += `"${JSON.stringify(val)}"`;
       } else {
         prev += `${val}`;
       }