FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

chore(table): add types, examples, and demo for onRowClick by seanforyou23 · Pull Request #3265 · patternfly/patternfly-react · GitHub

chore(table): add types, examples, and demo for onRowClick - #3265

Merged
tlabaj merged 2 commits into
patternfly:masterfrom
seanforyou23:table-rowclick
Nov 5, 2019
Merged

chore(table): add types, examples, and demo for onRowClick#3265
tlabaj merged 2 commits into
patternfly:masterfrom
seanforyou23:table-rowclick

Conversation

Copy link
Copy Markdown
Contributor

What: This PR adds an example of how to use the onRowClick prop, and specifies more specific types for this handler function. It also adds a demo in react-integration and tests. I also noticed that the default onRowClick function would fire on ever row click, even if it wasn't defined by the user, so I added a check so that it only fires if a handler is provided by the user.

Additional issues: #3263

@KKoukiou FYI

add IComputedData type
provide type for onRowClick handler
add onRowClick example to docs
add onRowClick test for table
add on row click demo in react-integration
clean up customRowWrapper demo/example
only fire onRowClick when it is provided by user

Copy link
Copy Markdown
Collaborator

PatternFly-React preview: https://patternfly-react-pr-3265.surge.sh

codecov-io commented Nov 5, 2019
edited
Loading

Copy link
Copy Markdown

Codecov Report

Merging #3265 into master will increase coverage by 2.68%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #3265      +/-   ##
==========================================
+ Coverage   64.74%   67.43%   +2.68%     
==========================================
  Files         481      892     +411     
  Lines       11702    24869   +13167     
  Branches     2141     2140       -1     
==========================================
+ Hits         7577    16771    +9194     
- Misses       3119     7094    +3975     
+ Partials     1006     1004       -2
Flag Coverage Δ
#misc 95.45% <ø> (?)
#patternfly3 69.3% <ø> (?)
#patternfly4 64.76% <100%> (+0.01%) ⬆️
Impacted Files Coverage Δ
...ernfly-4/react-table/src/components/Table/Body.tsx 75% <100%> (+2.08%) ⬆️
...patternfly-react/src/components/Spinner/Spinner.js 64.51% <0%> (-35.49%) ⬇️
...y-3/patternfly-react/src/components/Badge/index.js 62.5% <0%> (-20.84%) ⬇️
...-3/patternfly-react/src/components/Switch/index.js 62.5% <0%> (-20.84%) ⬇️
...patternfly-react/src/components/Toolbar/Toolbar.js 83.05% <0%> (-16.95%) ⬇️
...-3/patternfly-react/src/components/Button/index.js 88.23% <0%> (-11.77%) ⬇️
...ly-3/patternfly-react/src/components/Tabs/index.js 71.42% <0%> (-9.83%) ⬇️
...atternfly-react/src/components/Breadcrumb/index.js 72.22% <0%> (-9.03%) ⬇️
...ernfly-react/src/components/Wizard/WizardFooter.js 77.41% <0%> (-8.3%) ⬇️
...ponents/ApplicationLauncher/ApplicationLauncher.js 90.66% <0%> (-3.22%) ⬇️
... and 457 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5991033...1356799. Read the comment docs.

karelhala left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looking good! Just one question, but overall looks good.

children = null as React.ReactNode,
rowKey = 'id' as string,
onRowClick = (...args: any) => undefined as any,
onRowClick = undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is there any reason why you removed the empty function with undefined and if?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, I suppose it was two-fold. I replaced the default function because it executed every time a row was clicked, even if the table doesn't specify an onRowClick prop, which kinda looked like an error. Having two instances of any along with the type assertion undefined as any in the same function signature made me think it was just temporary implementation details that could stand to be cleaned up.

Copy link
Copy Markdown
Contributor

I also noticed that the default onRowClick function would fire on ever row click, even if it wasn't defined by the user

I don't think that it's a bad behavior, the function that is called is just an empty function. If we change this to undefined we have to check for it to be defined and that adds to a complexity of this already really complex component.

provide type for onRowClick handler
add onRowClick example to docs
add onRowClick test for table
add on row click demo in react-integration
clean up customRowWrapper demo/example
only fire onRowClick when it is provided by user

Copy link
Copy Markdown
Contributor Author

Thx @karelhala - I added the default function back and removed the check. I still feel kinda weird about firing stub function handlers like this as it could lead to performance issues if the pattern is repeated across many features of many components. I did take the time to add a type for the handler, though, so at least now it's a little more type-safe. Lemme know if you find anything else!

Copy link
Copy Markdown
Collaborator

PatternFly-React preview: https://patternfly-react-pr-3265.surge.sh

isButton: (event.target as HTMLElement).tagName !== 'BUTTON'
};

onRowClick(event, row, rowProps, computedData);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should we test if onRowClick exists first? That way you don't need to fire a stub function?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That's what was in the previous version and it's not really that good. Firing empty function is nothig compared to checking if function exists. The undefined instead of empty function might hurt us in future when we forgot to check if this function is defined and blow UI.

Overall it boils down to be consistent and since almost every other component is using either () => undefined or Function() instead of checking before call I think empty function is better.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, we use this pattern a lot with stateless components. Don't agree it would "blow UI", but don't feel strongly about it.

tlabaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

tlabaj merged commit 2034af9 into patternfly:master Nov 5, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

6 participants


Back | FazBrowse Home | New Git URL