Browse Source

[frontend] improved copy result to clipboard support

Björn Alm 3 years ago
parent
commit
d83107392a

+ 2 - 2
desktop/core/src/desktop/js/utils/hueUtils.ts

@@ -38,7 +38,7 @@ import stripHtmlFromFunctions from './html/stripHtmlForFunctions';
 import deleteAllEmptyStringKeys from './string/deleteAllEmptyStringKeys';
 import equalIgnoreCase from './string/equalIgnoreCase';
 import parseHivePseudoJson from './string/parseHivePseudoJson';
-import isComplexDBTypeDefinition from './string/isComplexDBTypeDefinition';
+import includesComplexDBTypeDefinition from './string/includesComplexDBTypeDefinition';
 import UUID from './string/UUID';
 
 import waitForObservable from './timing/waitForObservable';
@@ -74,11 +74,11 @@ export default {
   hueLocalStorage,
   html2text,
   htmlEncode,
+  includesComplexDBTypeDefinition,
   isFullScreen,
   isOverflowing,
   logError,
   parseHivePseudoJson,
-  isComplexDBTypeDefinition,
   removeURLParameter,
   replaceURL,
   scrollbarWidth,

+ 3 - 3
desktop/core/src/desktop/js/utils/string/isComplexDBTypeDefinition.ts → desktop/core/src/desktop/js/utils/string/includesComplexDBTypeDefinition.ts

@@ -15,9 +15,9 @@
 // limitations under the License.
 
 // Complex data type definitions used by Hive
-const complexTypes = /^(map|struct|array|uniontype)<.*>$/i;
+const complexTypes = /(map|struct|array|uniontype)<.*>/i;
 
-const isComplexDBTypeDefinition = (dataType: string | number): boolean =>
+const includesComplexDBTypeDefinition = (dataType: string | number): boolean =>
   typeof dataType === 'string' ? complexTypes.test(dataType) : false;
 
-export default isComplexDBTypeDefinition;
+export default includesComplexDBTypeDefinition;

+ 85 - 0
desktop/core/src/desktop/js/utils/string/includesComplexDBTypeDefinitionComplexDBTypeDefinition.test.js

@@ -0,0 +1,85 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import includesComplexDBTypeDefinition from './includesComplexDBTypeDefinition';
+
+describe('hue.utils.js', () => {
+  describe('includesComplexDBTypeDefinition', () => {
+    beforeEach(() => {});
+
+    it('returns true for strings including complex DB type definitions', () => {
+      expect(includesComplexDBTypeDefinition('map<string,array<string>>')).toEqual(true);
+      expect(includesComplexDBTypeDefinition('MAP<string,array<string>>')).toEqual(true);
+      expect(includesComplexDBTypeDefinition('array<string>')).toEqual(true);
+      expect(includesComplexDBTypeDefinition('ARRAY<string>')).toEqual(true);
+      expect(includesComplexDBTypeDefinition('struct<f1:bigint,f2:bigint>')).toEqual(true);
+      expect(includesComplexDBTypeDefinition('STRUCT<f1:bigint,f2:bigint>')).toEqual(true);
+      expect(
+        includesComplexDBTypeDefinition(
+          'uniontype<int, double, array<string>, struct<a:int,b:string>>'
+        )
+      ).toEqual(true);
+      expect(
+        includesComplexDBTypeDefinition(
+          'UNIONTYPE<int, double, array<string>, struct<a:int,b:string>>'
+        )
+      ).toEqual(true);
+
+      expect(includesComplexDBTypeDefinition('"blabla" map<string,array<string>>')).toEqual(true);
+      expect(includesComplexDBTypeDefinition('MAP<string,array<string>> "blabla"')).toEqual(true);
+      expect(includesComplexDBTypeDefinition('test array<string>')).toEqual(true);
+      expect(includesComplexDBTypeDefinition('ARRAY<string> test')).toEqual(true);
+      expect(includesComplexDBTypeDefinition('xx struct<f1:bigint,f2:bigint>')).toEqual(true);
+      expect(includesComplexDBTypeDefinition('STRUCT<f1:bigint,f2:bigint> x')).toEqual(true);
+      expect(
+        includesComplexDBTypeDefinition(
+          'test uniontype<int, double, array<string>, struct<a:int,b:string>>'
+        )
+      ).toEqual(true);
+      expect(
+        includesComplexDBTypeDefinition(
+          'UNIONTYPE<int, double, array<string>, struct<a:int,b:string>> test'
+        )
+      ).toEqual(true);
+
+      expect(includesComplexDBTypeDefinition('<string,array<string>>')).toEqual(true);
+    });
+
+    it('returns false for strings not including complex DB type definitions', () => {
+      expect(includesComplexDBTypeDefinition('<b>test</b>')).toEqual(false);
+      expect(includesComplexDBTypeDefinition('<string>')).toEqual(false);
+      expect(includesComplexDBTypeDefinition('xxx<f1:bigint,f2:bigint>')).toEqual(false);
+      expect(includesComplexDBTypeDefinition('map')).toEqual(false);
+      expect(includesComplexDBTypeDefinition('MAP')).toEqual(false);
+      expect(includesComplexDBTypeDefinition('ARRAY')).toEqual(false);
+      expect(includesComplexDBTypeDefinition('array')).toEqual(false);
+      expect(includesComplexDBTypeDefinition('struc')).toEqual(false);
+      expect(includesComplexDBTypeDefinition('STRUCT')).toEqual(false);
+      expect(includesComplexDBTypeDefinition('uniontype')).toEqual(false);
+      expect(includesComplexDBTypeDefinition('UNIONTYPE')).toEqual(false);
+    });
+
+    it('returns false for all non string based input', () => {
+      expect(includesComplexDBTypeDefinition(12)).toEqual(false);
+      expect(includesComplexDBTypeDefinition(-12)).toEqual(false);
+      expect(includesComplexDBTypeDefinition({})).toEqual(false);
+      expect(includesComplexDBTypeDefinition(undefined)).toEqual(false);
+      expect(includesComplexDBTypeDefinition(new Date())).toEqual(false);
+      expect(includesComplexDBTypeDefinition(null)).toEqual(false);
+      expect(includesComplexDBTypeDefinition([])).toEqual(false);
+    });
+  });
+});

+ 0 - 63
desktop/core/src/desktop/js/utils/string/isComplexDBTypeDefinition.test.js

@@ -1,63 +0,0 @@
-// Licensed to Cloudera, Inc. under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  Cloudera, Inc. licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-import isComplexDBTypeDefinition from './isComplexDBTypeDefinition';
-
-describe('hue.utils.js', () => {
-  describe('isComplexDBTypeDefinition', () => {
-    beforeEach(() => {});
-
-    it('returns true for complex DB type definitions', () => {
-      expect(isComplexDBTypeDefinition('map<string,array<string>>')).toEqual(true);
-      expect(isComplexDBTypeDefinition('MAP<string,array<string>>')).toEqual(true);
-      expect(isComplexDBTypeDefinition('array<string>')).toEqual(true);
-      expect(isComplexDBTypeDefinition('ARRAY<string>')).toEqual(true);
-      expect(isComplexDBTypeDefinition('struct<f1:bigint,f2:bigint>')).toEqual(true);
-      expect(isComplexDBTypeDefinition('STRUCT<f1:bigint,f2:bigint>')).toEqual(true);
-      expect(
-        isComplexDBTypeDefinition('uniontype<int, double, array<string>, struct<a:int,b:string>>')
-      ).toEqual(true);
-      expect(
-        isComplexDBTypeDefinition('UNIONTYPE<int, double, array<string>, struct<a:int,b:string>>')
-      ).toEqual(true);
-    });
-
-    it('returns false for other strings', () => {
-      expect(isComplexDBTypeDefinition('<string,array<string>>')).toEqual(false);
-      expect(isComplexDBTypeDefinition('<b>test</b>')).toEqual(false);
-      expect(isComplexDBTypeDefinition('<string>')).toEqual(false);
-      expect(isComplexDBTypeDefinition('xxx<f1:bigint,f2:bigint>')).toEqual(false);
-      expect(isComplexDBTypeDefinition('map')).toEqual(false);
-      expect(isComplexDBTypeDefinition('MAP')).toEqual(false);
-      expect(isComplexDBTypeDefinition('ARRAY')).toEqual(false);
-      expect(isComplexDBTypeDefinition('array')).toEqual(false);
-      expect(isComplexDBTypeDefinition('struc')).toEqual(false);
-      expect(isComplexDBTypeDefinition('STRUCT')).toEqual(false);
-      expect(isComplexDBTypeDefinition('uniontype')).toEqual(false);
-      expect(isComplexDBTypeDefinition('UNIONTYPE')).toEqual(false);
-    });
-
-    it('returns false for all non string based input', () => {
-      expect(isComplexDBTypeDefinition(12)).toEqual(false);
-      expect(isComplexDBTypeDefinition(-12)).toEqual(false);
-      expect(isComplexDBTypeDefinition({})).toEqual(false);
-      expect(isComplexDBTypeDefinition(undefined)).toEqual(false);
-      expect(isComplexDBTypeDefinition(new Date())).toEqual(false);
-      expect(isComplexDBTypeDefinition(null)).toEqual(false);
-      expect(isComplexDBTypeDefinition([])).toEqual(false);
-    });
-  });
-});

+ 1 - 1
desktop/core/src/desktop/templates/common_notebook_ko_components.mako

@@ -409,7 +409,7 @@ else:
                 result += '<tr>';
                 for (var i = 1; i < row.length; i++) { // Skip the row number column              
                   var htmlDecodedValue = hueUtils.html2text(row[i]);
-                  var needsToStayEncoded = hueUtils.isComplexDBTypeDefinition(htmlDecodedValue)
+                  var needsToStayEncoded = hueUtils.includesComplexDBTypeDefinition(htmlDecodedValue);
                   result += '<td>' + ( needsToStayEncoded ? row[i] : htmlDecodedValue) + '</td>';
                 }
                 result += '</tr>';