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 2021/06/10 18:44:46 UTC

[GitHub] [superset] pkdotson commented on a change in pull request #14872: feat(Explore): add sort to edit dataset modal

pkdotson commented on a change in pull request #14872:
URL: https://github.com/apache/superset/pull/14872#discussion_r649436432



##########
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:
       Yes that is the default behavior in some of the sorting list that we have but it's not standard across.




-- 
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:
users@infra.apache.org



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