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

Add enableSorting prop to EuiBasicTable for default sorting of table. #2906

Merged
merged 4 commits into from
Mar 10, 2020

Conversation

Anupam-dagar
Copy link
Contributor

Fixes: #1866

Summary

This PR adds an enableSorting prop to EuiBasicTable component. This prop when set to true will make all columns sortable by setting sortable property of each column to true.

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in IE11 and Firefox
  • Props have proper autodocs
  • Added documentation examples
  • Added or updated jest tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

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.

@kibanamachine
Copy link

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?

@cchaos
Copy link
Contributor

cchaos commented Feb 24, 2020

Jenkins, test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2906/

Copy link
Contributor

@cchaos cchaos left a 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;
Copy link
Contributor

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:

Suggested change
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.

<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

@cchaos cchaos requested a review from chandlerprall February 24, 2020 16:11
@cchaos
Copy link
Contributor

cchaos commented Feb 24, 2020

@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.

@Anupam-dagar
Copy link
Contributor Author

@cchaos Thanks for your review!
I tried this on the sorting, pagination and footer table example by adding enableSorting={true} to the props. I was able to see the sorting working. For sorting example, I removed sortable: true from all the columns to see if it is working.
With my understanding of the issue, please correct me if I am wrong, I assume that sort and onchange function will be provided and enableSorting will just make every column sortable.

I have attached the gif below on how I tested it.
euia-min

src/components/basic_table/basic_table.tsx Outdated Show resolved Hide resolved
src/components/basic_table/basic_table.tsx Outdated Show resolved Hide resolved
@Anupam-dagar
Copy link
Contributor Author

@chandlerprall I have moved the prop to sort prop itself. I kept it optional so that it doesn't break the current sorting implementations. I added the code block inside the field check, I guess sortable can be made true to field only columns since columns having render needs a function for sortable.

src/components/basic_table/table_types.ts Outdated Show resolved Hide resolved
src-docs/src/views/tables/sorting/sorting_section.js Outdated Show resolved Hide resolved
src-docs/src/views/tables/sorting/sorting_section.js Outdated Show resolved Hide resolved
@Anupam-dagar
Copy link
Contributor Author

@chandlerprall I have made the requested changes.

Copy link
Contributor

@chandlerprall chandlerprall left a 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.

src/components/basic_table/basic_table.tsx Outdated Show resolved Hide resolved
@Anupam-dagar
Copy link
Contributor Author

@chandlerprall Implemented the requested changes.

Copy link
Contributor

@chandlerprall chandlerprall left a 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?

@cchaos
Copy link
Contributor

cchaos commented Feb 27, 2020

Jenkins, test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2906/

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also had a thought to check the mobile view, and so I added the prop to the tables/mobile.js example file, and the desktop view correctly enables the sorting for all columns, but the mobile sort dropdown only lists the columns that have sortable: true directly on them.

Screen Shot 2020-02-27 at 16 31 52 PM

Comment on lines 27 to 31
<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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<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.

@Anupam-dagar Anupam-dagar force-pushed the default_sorting branch 2 times, most recently from d24e4a5 to 8eb439b Compare February 28, 2020 09:02
@Anupam-dagar
Copy link
Contributor Author

@cchaos I have made the changes to make the prop work for the mobile view.

Copy link
Contributor

@cchaos cchaos left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here (my fault)

Suggested change
<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.

@Anupam-dagar
Copy link
Contributor Author

@cchaos I'll remember to not merge down my commits on my next PR's. I have fixed the typo in the sorting section.

@chandlerprall
Copy link
Contributor

jenkins test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2906/

Copy link
Contributor

@chandlerprall chandlerprall left a 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
Copy link
Contributor

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

Suggested change
<EuiCode>sortable: true</EuiCode>.To enable the default sorting ability
<EuiCode>sortable: true</EuiCode>. To enable the default sorting ability

@Anupam-dagar
Copy link
Contributor Author

@chandlerprall requested changes done. I hope the PR is now complete.
I had to commit using -n flag since the pre commit test was giving the following error and I guess it is unrelated to the code I have edited. It's from the combo box.

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.

@cchaos
Copy link
Contributor

cchaos commented Mar 10, 2020

Jenkins, test this

@cchaos cchaos requested a review from chandlerprall March 10, 2020 14:25
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_2906/

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM!

@chandlerprall chandlerprall merged commit fa2ec10 into elastic:master Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default sortable to true for all table columns
4 participants