-
Notifications
You must be signed in to change notification settings - Fork 842
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
Add enableSorting prop to EuiBasicTable for default sorting of table. #2906
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
Jenkins, test this |
Preview documentation changes for this PR: https://eui.elastic.co/pr_2906/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Anupam-dagar. Though the PR is not quite complete. I have listed out some more tasks that need to be done. Meanwhile, I'll check for functionality.
@@ -189,6 +189,7 @@ interface BasicTableProps<T> extends Omit<EuiTableProps, 'onChange'> { | |||
rowProps?: object | RowPropsCallback<T>; | |||
selection?: EuiTableSelectionType<T>; | |||
sorting?: EuiTableSortingType<T>; | |||
enableSorting?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few more things that will need to be done when we add new props.
1. Add a prop docs comment to this so consumers understand what it does. Something like:
enableSorting?: boolean; | |
/** | |
* Attempts to enable the default sorting ability for each column | |
**/ | |
enableSorting?: boolean; |
EuiBasicTable is also unique in that it has it's own props docs configuration file buried in the docs site. You'll find that file here, in which you'll need to add another section for this new prop and add a description similar to the comment above.
2. Add a test for this prop in basic_table.test.tsx
You can follow the pattern by copying and pasting this block and changing the configs to test the enableSorting
prop.
3. Add a sentence to the table sorting section alluding to this new prop.
This section is where it talks about sorting.
eui/src-docs/src/views/tables/sorting/sorting_section.js
Lines 23 to 28 in ca74ad3
<p> | |
The following example shows how to configure column sorting via the{' '} | |
<EuiCode>sorting</EuiCode> | |
property and flagging the sortable columns as{' '} | |
<EuiCode>sortable: true</EuiCode> | |
</p> |
I'd change it to read something like:
<p>
The following example shows how to configure column sorting via the{' '}
<EuiCode>sorting</EuiCode>
property and flagging the sortable columns as{' '}
<EuiCode>sortable: true</EuiCode>. You can also attempt to enable the default sorting behavior of all
columns by passing <EuiCode>enableSorting: true</EuiCode> to EuiBasicTable without the need to specify
it for each individual column.
</p>
4. Add a changelog entry
@Anupam-dagar Have you tested this new option in the docs? I'm not seeing any change to the EuiBasicTable render (none of the table columns have the sorting functionality) when I change the prop to be true. |
@cchaos Thanks for your review! |
fac4dad
to
07bf3f7
Compare
@chandlerprall I have moved the prop to |
07bf3f7
to
4894b42
Compare
@chandlerprall I have made the requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One final change requested.
4894b42
to
055ccaa
Compare
@chandlerprall Implemented the requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM!; Pulled and tested locally
@cchaos mind taking another pass at the documentation side?
Jenkins, test this |
Preview documentation changes for this PR: https://eui.elastic.co/pr_2906/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<EuiCode>sortable: true</EuiCode>. You can also set the default sorting | ||
behavior of field columns by passing | ||
<EuiCode>enableAllColumns: true</EuiCode> to <EuiCode>sorting</EuiCode> | ||
prop of EuiBasicTable without the need to specify it for each individual | ||
column. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<EuiCode>sortable: true</EuiCode>. You can also set the default sorting | |
behavior of field columns by passing | |
<EuiCode>enableAllColumns: true</EuiCode> to <EuiCode>sorting</EuiCode> | |
prop of EuiBasicTable without the need to specify it for each individual | |
column. | |
<EuiCode>sortable: true</EuiCode>. To enable the default sorting ability to <strong>every</strong> | |
column, pass <EuiCode>enableAllColumns: true</EuiCode> to the <EuiCode>sorting</EuiCode> | |
prop. |
d24e4a5
to
8eb439b
Compare
@cchaos I have made the changes to make the prop work for the mobile view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Anupam-dagar! As a side note, it's really helpful to reviewers if you don't merge down all new commits to the PR. It helps us as reviewers to see the latest change by viewing individual commits. When we merge the PR, then we squash commits so atleast master
will only have one commit per PR.
@@ -24,7 +24,11 @@ export const section = { | |||
The following example shows how to configure column sorting via the{' '} | |||
<EuiCode>sorting</EuiCode> | |||
property and flagging the sortable columns as{' '} | |||
<EuiCode>sortable: true</EuiCode> | |||
<EuiCode>sortable: true</EuiCode>.To enable the default sorting ability to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here (my fault)
<EuiCode>sortable: true</EuiCode>.To enable the default sorting ability to | |
<EuiCode>sortable: true</EuiCode>.To enable the default sorting ability for |
Also, when there's a line break and then element tags, it gets parsed as not having any space. You then need to add {' '}
as you'll notice in the previous lines. I'd suggest installing a linter that can auto-fix when you save. I know it helps me a lot.
@cchaos I'll remember to not merge down my commits on my next PR's. I have fixed the typo in the sorting section. |
jenkins test this |
Preview documentation changes for this PR: https://eui.elastic.co/pr_2906/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one failing test snapshot that needs updating; please run yarn test-unit -u
and commit the result.
@@ -24,7 +24,11 @@ export const section = { | |||
The following example shows how to configure column sorting via the{' '} | |||
<EuiCode>sorting</EuiCode> | |||
property and flagging the sortable columns as{' '} | |||
<EuiCode>sortable: true</EuiCode> | |||
<EuiCode>sortable: true</EuiCode>.To enable the default sorting ability |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last formatting issue that I can see
<EuiCode>sortable: true</EuiCode>.To enable the default sorting ability | |
<EuiCode>sortable: true</EuiCode>. To enable the default sorting ability |
0fe58d7
to
37b0d49
Compare
@chandlerprall requested changes done. I hope the PR is now complete. yarn run v1.21.1
$ yarn tsc --noEmit && yarn lint-es && yarn lint-sass
$ /home/anupam/github/eui/node_modules/.bin/tsc --noEmit
src/components/combo_box/combo_box.tsx:651:39 - error TS2339: Property 'copyInputStyles' does not exist on type 'AutosizeInput & HTMLDivElement'.
651 this.autoSizeInputRefInstance.copyInputStyles();
~~~~~~~~~~~~~~~
Found 1 error. |
Jenkins, test this |
Preview documentation changes for this PR: https://eui.elastic.co/pr_2906/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM!
Fixes: #1866
Summary
This PR adds an
enableSorting
prop toEuiBasicTable
component. This prop when set to true will make all columns sortable by settingsortable
property of each column totrue
.Checklist
As pointed out by @cchaos in the issue, this PR doesn't yet handle the case if the data in the column isn't what the sorting function accepts. I would implement it as the discussion continues over it in this PR.