zhaoyongjie commented on a change in pull request #14872:
URL: https://github.com/apache/superset/pull/14872#discussion_r649649527
##########
File path: superset-frontend/src/CRUD/CollectionTable.tsx
##########
@@ -181,15 +207,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: Sort, n: Sort) => {
+ if (typeof m === 'string') {
+ return (m || ' ').localeCompare(n);
+ }
+ return m - n;
+ };
+ return () => {
+ if (sortColumns?.includes(col)) {
+ // display in random order if no sort specified
Review comment:
it's not a random order, this is the database column order(in other
words, you can check this order in sqllab)
##########
File path: superset-frontend/src/CRUD/CollectionTable.tsx
##########
@@ -181,15 +207,75 @@ export default class CRUDCollection extends
React.PureComponent<
}));
}
+ sortColumn(col: string, sort = 0) {
Review comment:
Is it a more readable enum being? for instance:
```
enum Sort {
asc = 1,
desc = 2,
unsort = 0,
}
```
##########
File path: superset-frontend/src/CRUD/CollectionTable.tsx
##########
@@ -181,15 +207,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: Sort, n: Sort) => {
+ 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 => {
Review comment:
```suggestion
this.setState(prevState => {
// newly ordered collection
const sorted = [...prevState.collectionArray].sort((a: object, b:
object) => compareSort(a[col], b[col]))
const newCollection = sort === 1 ? sorted : sorted.reverse()
return {
...prevState,
collectionArray: newCollection,
sortColumn: col,
sort,
};
});
}
```
--
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]