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

Added the ability to use DataTable rowDetails in a controlled way. #6571

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

aheintz
Copy link

@aheintz aheintz commented Jan 10, 2023

What does this PR do?

Extended rowDetails property to be either a function or a shape that may contain four functions, render, isExpanded, isExpandable and expandClick.

render is the equivalent of the current function rowDetails rendering the row details. isExpanded is the function which determines if the row details should be expanded isExpandable is a function which allows certain rows to be expandable or not (i.e. not expandable means no expand button or expand/collapse events) expandClick is a function which is fired when the expand/collapse button is clicked. All of these functions are called with the entire row object from data.

render is mandatory. expandClick can be handled using onClickRow or similar, in the absence of isExpandable the default is that the row is expandable and the absence of isExpanded falls back to the non-controlled behaviour as it is now.

Storybook example is provided.

Where should the reviewer start?

I think the "RowDetails Controlled" story insrc/js/components/DataTable/stories/RowDetailsControlled.js is a good place to start. The majority of the work is in Body.js

What testing has been done on this PR?

Added test to DataTable-test.js to verify the functionality. Existing tests for DataTable are untouched. Snapshots are updated.

How should this be manually tested?

Storybook is a good start, play around with that code according to the description above.

Do Jest tests follow these best practices?

Shit, no. Sorry. I've followed the pattern in the existing tests. I can look into updating the tests based on this.

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • userEvent is used in place of fireEvent.
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

We have a need for a way to control which rows details are open (only allowing one row open is certainly one case)

What are the relevant issues?

This PR resolves the second part of the issue(s) mentioned in this issue: #6344 This PR together with PR-6570 solves that issue.

Screenshots (if appropriate)

N/A

Do the grommet docs need to be updated?

Yes. The DataTable docs need updates to match the changing properties for DataTable.rowDetails.

Should this PR be mentioned in the release notes?

Possibly, I don't know if the change is "big" enough.

Is this change backwards compatible or is it a breaking change?

The change is fully backwards compatible (all previous tests for rowDetails are untouched as well as storybook).

@skuroyama-AoPS
Copy link

This would be super useful for us!

@jcfilben jcfilben added the PRty Biweekly PR reviews by grommet team with hoping of closing such PRs label Mar 29, 2023
@taysea
Copy link
Collaborator

taysea commented May 25, 2023

Thanks for the PR! I'm still familiarizing myself with the logic, but here is some quick feedback on variable naming. I think it might be more aligned with the terms and types we use in groupBy (https://v2.grommet.io/datatable#groupBy):

  • isExpanded --> expanded: (string | number)[] (where this is the primary key of the expanded rows)
  • isExpandable --> expandable: (string | number)[] (where this is the primary key of the expandable rows)
  • expandClick --> onClickExpand or onExpand: function

@taysea taysea added the waiting Awaiting response to latest comments label Jun 8, 2023
@jcfilben jcfilben removed the PRty Biweekly PR reviews by grommet team with hoping of closing such PRs label Jun 22, 2023
@aheintz aheintz closed this Jul 2, 2023
@aheintz aheintz force-pushed the datatable-controlled branch 2 times, most recently from 93a67a9 to 5a6ec98 Compare July 2, 2023 13:34
…feedback, renaming property names to `expanded`, `expandable` and `onClickExpand`. And a line length fix to allow a commit.
@aheintz aheintz reopened this Jul 2, 2023
@aheintz
Copy link
Author

aheintz commented Jul 2, 2023

Thanks for the PR! I'm still familiarizing myself with the logic, but here is some quick feedback on variable naming. I think it might be more aligned with the terms and types we use in groupBy (https://v2.grommet.io/datatable#groupBy):

  • isExpanded --> expanded: (string | number)[] (where this is the primary key of the expanded rows)
  • isExpandable --> expandable: (string | number)[] (where this is the primary key of the expandable rows)
  • expandClick --> onClickExpand or onExpand: function

It's taken me some(?) time to get around to fixing this, I've updated the PR with the requested changes, and updated from upstream/master.

I'm a bit eager to get this functionality so a renewed review would be appreciated @taysea & @jcfilben .

…feedback, renaming property names to `expanded`, `expandable` and `onClickExpand`. And a line length fix to allow a commit.
…able-controlled

# Conflicts:
#	src/js/components/DataTable/Body.js
@aheintz
Copy link
Author

aheintz commented Jul 2, 2023

Added a PR for documentation as well: grommet/grommet-site#484

@jcfilben jcfilben added PRty Biweekly PR reviews by grommet team with hoping of closing such PRs and removed waiting Awaiting response to latest comments labels Jul 6, 2023
@aheintz
Copy link
Author

aheintz commented Aug 16, 2023

Is it on the agenda to accept this PR anytime soon @jcfilben / @taysea , or is there anything you would like to see changed? In my opinion, it is a necessary feature for an expandable data table.

@aheintz
Copy link
Author

aheintz commented Oct 15, 2023

@jcfilben , @taysea is there any chance to get this approved? Feels a bit sad to spend time to try to contribute to an open source project and it just goes into the void. Provide additional feedback, approve it or if you don't like it, close it.

@jcfilben
Copy link
Collaborator

Hey @aheintz sorry for the delay on this one. Thank you for contributing, I think this PR is a valuable addition to Grommet. I'll try and get this reviewed early next week

Comment on lines +105 to +107
expanded: (row: TRowType) => boolean;
expandable: (row: TRowType) => boolean;
onClickExpand: (row: TRowType) => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

expanded, expandable, and onClickExpand should all be optional. Also in this comment @taysea mentioned changing expanded and expandable to be arrays of string or numbers where the items in the arrays are primary keys of rows.

<ExpanderCell
context={isExpanded ? 'groupHeader' : 'body'}
expanded={isExpanded}
disabled={!rowExpandable}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
disabled={!rowExpandable}
expandable={rowExpandable}

Can we change this prop name to expandable? I think the semantic html meaning of 'disabled' doesn't align with what we are doing here.

@@ -53,15 +53,15 @@ const ExpanderControl = ({ context, expanded, onToggle, pad, ...rest }) => {
return content;
};

const ExpanderCell = ({ background, border, context, ...rest }) => (
const ExpanderCell = ({ background, border, context, disabled, ...rest }) => (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const ExpanderCell = ({ background, border, context, disabled, ...rest }) => (
const ExpanderCell = ({ background, border, context, expandable, ...rest }) => (

<TableCell
background={background}
border={border}
size="xxsmall"
plain="noPad"
verticalAlign={context === 'groupEnd' ? 'bottom' : 'top'}
>
<ExpanderControl context={context} {...rest} />
{!disabled && <ExpanderControl context={context} {...rest} />}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{!disabled && <ExpanderControl context={context} {...rest} />}
{expandable && <ExpanderControl context={context} {...rest} />}

@jcfilben jcfilben added waiting Awaiting response to latest comments and removed PRty Biweekly PR reviews by grommet team with hoping of closing such PRs labels Oct 23, 2023
@kabincs
Copy link

kabincs commented Dec 14, 2023

Can we controlled the rowDetail props show expand icon on all the row. i want to show only to specific row. Can we achieve with current gromment DataTable. I think the above PR is for to achieve that functionality, when we can expect this in the grommet release

@jcfilben
Copy link
Collaborator

Can we controlled the rowDetail props show expand icon on all the row. i want to show only to specific row. Can we achieve with current gromment DataTable. I think the above PR is for to achieve that functionality, when we can expect this in the grommet release

Hey @kabincs the Grommet DataTable currently does not support having rowDetails only on specific rows. This PR would enable this functionality. Unfortunately I don't have a timeline for when this will be added to Grommet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting Awaiting response to latest comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants