Skip to content

Commit

Permalink
Merge pull request #2600 from louisbl/fix-sort-arrow-with-sortBy
Browse files Browse the repository at this point in the history
[RFR] Fixes arrow in sorted column header when field use sortBy props
  • Loading branch information
fzaninotto authored Dec 13, 2018
2 parents 1d2d45e + 5ff475f commit 968af0f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
25 changes: 25 additions & 0 deletions cypress/integration/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,29 @@ describe('List Page', () => {
cy.contains('1-10 of 10');
});
});

describe("Sorting", () => {
it('should display a sort arrow when clicking on a sortable column header', () => {
ListPagePosts.toggleColumnSort('id');
cy.get(ListPagePosts.elements.sortBy('id')).get("svg").should('be.visible');

ListPagePosts.toggleColumnSort('"tags.name"');
cy.get(ListPagePosts.elements.sortBy('"tags.name"')).get("svg").should('be.visible');
});

it('should hide the sort arrow when clicking on another sortable column header', () => {
ListPagePosts.toggleColumnSort('published_at');
cy.get(ListPagePosts.elements.sortBy('id')).get("svg").should('be.hidden');
cy.get(ListPagePosts.elements.sortBy('"tags.name"')).get("svg").should('be.hidden');
});

it('should reverse the sort arrow when clicking on an already sorted column header', () => {
ListPagePosts.toggleColumnSort('published_at');
ListPagePosts.toggleColumnSort('"tags.name"');
cy.get(ListPagePosts.elements.sortBy('"tags.name"')).get("[class*=iconDirectionAsc]").should('exist');

ListPagePosts.toggleColumnSort('"tags.name"');
cy.get(ListPagePosts.elements.sortBy('"tags.name"')).get("[class*=iconDirectionDesc]").should('exist');
});
})
});
5 changes: 5 additions & 0 deletions cypress/support/ListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default url => ({
recordRows: '.datagrid-body tr',
viewsColumn: '.datagrid-body tr td:nth-child(6)',
datagridHeaders: 'th',
sortBy: name => `th span[data-sort=${name}]`,
logout: '.logout',
bulkActionsToolbar: '[data-test=bulk-actions-toolbar]',
customBulkActionsButton:
Expand Down Expand Up @@ -101,4 +102,8 @@ export default url => ({
applyDeleteBulkAction() {
cy.get(this.elements.deleteBulkActionsButton).click();
},

toggleColumnSort(name) {
cy.get(this.elements.sortBy(name)).click();
}
});
1 change: 1 addition & 0 deletions examples/simple/src/posts/PostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const PostList = withStyles(styles)(({ classes, ...props }) => (
label="Tags"
reference="tags"
source="tags"
sortBy="tags.name"
cellClassName={classes.hiddenOnSmallScreens}
headerClassName={classes.hiddenOnSmallScreens}
>
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/list/Datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class Datagrid extends Component {
currentSort={currentSort}
field={field}
isSorting={
field.props.source ===
currentSort.field
currentSort.field ===
(field.props.sortBy || field.props.source)
}
key={field.props.source || index}
resource={resource}
Expand Down

0 comments on commit 968af0f

Please sign in to comment.