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

Column functions are not always equal by josejulio · Pull Request #3612 · patternfly/patternfly-react · GitHub

Column functions are not always equal - #3612

Merged
tlabaj merged 1 commit into
patternfly:masterfrom
josejulio:functions-are-not-equal
Jan 30, 2020
Merged

Column functions are not always equal#3612
tlabaj merged 1 commit into
patternfly:masterfrom
josejulio:functions-are-not-equal

Conversation

josejulio commented Jan 29, 2020
edited
Loading

Copy link
Copy Markdown
Contributor

Fixes #3620

In my case, I'm using the Table and passing a onCollapse method within a React component that uses hooks.

I need the columns that are a function, but a different one, to be updated, I'm using as example onCollapse, but this applies to any other column.

Consider below code:

interface RowState {
    isOpen: boolean;
    // more stuff
}

export const PolicyTable: React.FunctionComponent<PolicyTableProps> = (props) => {

    const [ rowsState, setRowsState ] = React.useState<Record<string, RowState>>({});

    const onCollapse = (_event, idx: number, isOpen: boolean) => {
        const rowState = { ...rowsState[idx], isOpen };
        const newRowsState = { ...rowsState };
        newRowsState[idx] = rowState;
        setRowsState(setRowsState);
    }

    // Other props not show for simplicity
    return <Table
        onCollapse={ onCollapse }
    />
}

With this in place, on first render, all the rows have my initial rowState value.
If i click the first cell, only that cell is going to have the updated rowState (where it is open) and the others will have the old rowState (nothing open).
When clicking the second row, it will discard my modified rowState (because this cell doesn't have access to it) and only open what I clicked.

See below gif without the contents of this PR:

and with this PR content:

 - This is important when using React hooks

Copy link
Copy Markdown
Collaborator

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

codecov-io commented Jan 29, 2020
edited
Loading

Copy link
Copy Markdown

Codecov Report

Merging #3612 into master will not change coverage.
The diff coverage is 0%.

@@           Coverage Diff           @@
##           master    #3612   +/-   ##
=======================================
  Coverage   67.15%   67.15%           
=======================================
  Files         907      907           
  Lines       25559    25559           
  Branches     2267     2267           
=======================================
  Hits        17165    17165           
  Misses       7353     7353           
  Partials     1041     1041
Flag Coverage Δ
#misc 95.45% <ø> (ø) ⬆️
#patternfly3 69.29% <ø> (ø) ⬆️
#patternfly4 64.31% <0%> (ø) ⬆️
#patternfly4integration ?
Impacted Files Coverage Δ
...ble/src/components/Table/base/columns-are-equal.ts 33.33% <0%> (ø) ⬆️

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 0fd41b1...aac7801. Read the comment docs.

josejulio requested a review from priley86 January 30, 2020 03:17

Copy link
Copy Markdown
Contributor Author

Requesting review from @priley86 as per github's suggestion. Please let me know if I should do something else. Thanks!

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 really good!

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 b56c6fe into patternfly:master Jan 30, 2020
josejulio deleted the functions-are-not-equal branch January 31, 2020 03:22
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.

Using new functions don't trigger a render on the Table rows

6 participants


Back | FazBrowse Home | New Git URL