You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/03/08 17:31:36 UTC

[GitHub] [superset] etr2460 commented on a change in pull request #19024: fix(time-series table): display null values in time-series table and sortable

etr2460 commented on a change in pull request #19024:
URL: https://github.com/apache/superset/pull/19024#discussion_r821902116



##########
File path: superset-frontend/src/visualizations/TimeTable/SortNumberWithMixedTypes.ts
##########
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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 { Row } from 'react-table';
+
+const sortNumberWithMixedTypes = (rowA: Row, rowB: Row, columnId: string) => {
+  const rowAVal = rowA.values[columnId].props['data-value'];
+  const rowBVal = rowB.values[columnId].props['data-value'];
+  if (typeof rowAVal === 'number' && typeof rowBVal === 'number') {
+    return rowAVal - rowBVal;
+  }
+  if (typeof rowAVal === 'number') {
+    return 1;
+  }
+  if (typeof rowBVal === 'number') {
+    return -1;
+  }
+  return 0;

Review comment:
       wanna add the test case where both are not a number?
   
   also, can these ever be strings or objects or other types? or only ever number or null?

##########
File path: superset-frontend/src/visualizations/TimeTable/sort.test.ts
##########
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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 sortFn from './SortNumberWithMixedTypes';
+
+describe('sort Number and mixed types', () => {
+  const columnId = 'mLnVxkc1g';
+  const rowA = {
+    values: {
+      metric: 'Albania',
+      mLnVxkc1g: {
+        props: {
+          'data-value': null,
+        },
+      },
+    },
+  };
+  const rowB = {
+    values: {
+      metric: 'Afghanistan',
+      mLnVxkc1g: {
+        props: {
+          'data-value': -0.6749999999999972,
+        },
+      },
+    },
+  };
+  const rowC = {
+    values: {
+      metric: 'Malawi',
+      mLnVxkc1g: {
+        props: {
+          'data-value': 4.852999999999994,
+        },
+      },
+    },
+  };
+
+  it('should treat null values as smallest', () => {
+    // @ts-ignore
+    expect(sortFn(rowA, rowB, columnId)).toBe(-1);
+    // @ts-ignore
+    expect(sortFn(rowA, rowC, columnId)).toBe(-1);
+    // @ts-ignore

Review comment:
       why do we need to ts ignore here? if the rows are the improper types, then you can define them as the correct ones above instead of ignoring types




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org