Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Fixes arrow in sorted column header when field use sortBy props #2600

Merged
merged 3 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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