michael-s-molina commented on a change in pull request #14872:
URL: https://github.com/apache/superset/pull/14872#discussion_r641578057



##########
File path: superset-frontend/src/CRUD/CollectionTable.tsx
##########
@@ -181,15 +205,75 @@ export default class CRUDCollection extends 
React.PureComponent<
     }));
   }
 
+  sortColumn(col: string, sort = 0) {
+    const { sortColumns } = this.props;
+    // default sort logic sorting string, boolean and number
+    const compareSort = (m: any, n: any) => {
+      if (typeof m === 'string') {
+        return (m || ' ').localeCompare(n);
+      }
+      return m - n;
+    };
+    return () => {
+      if (sortColumns?.includes(col)) {
+        // display in random order if no sort specified
+        if (sort === 0) {
+          const collection = createKeyedCollection(this.props.collection);
+          this.setState({
+            collectionArray: createCollectionArray(collection),
+            sortColumn: '',
+            sort,
+          });
+          return;
+        }
+
+        this.setState(prevState => {
+          // newly ordered collection
+          const newCollection = prevState.collectionArray
+            .sort((a: object, b: object) =>
+              sort === 1
+                ? compareSort(a[col], b[col])
+                : compareSort(b[col], a[col]),

Review comment:
       I'm assuming that `sort` can have 3 states (ascending, descending, 
unsorted). If that's the case, this `if` should account for the 3 possible 
states. If `sort` can only have 2 states, then it would be better represented 
as a `boolean`.




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to