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

Saving head and foot values on the state upon toggling #19038

Conversation

abdel-h
Copy link
Contributor

@abdel-h abdel-h commented Dec 10, 2019

Description

Fixes #18919

How has this been tested?

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

Hey @devdivdev Thanks for taking a look at this so quickly. I left some comments.

I'm also adding Needs decision label, as initially it was decided this functionality wasn't required. There's some more info about that here:
#18919 (comment)

if ( ! isEmptyTableSection( state[ sectionName ] ) ) {
return { [ sectionName ]: [] };
return { [ sectionName ]: [], [ sectionSaved ]: [ ...state[ sectionName ] ] };
Copy link
Contributor

Choose a reason for hiding this comment

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

You can see here the values returned by toggleSection get saved as attributes:
https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/table/edit.js#L239

This kind of transient state isn't really the intended use case for the block attributes. I think ideally headSaved and footSaved would instead be stored in component state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep I noticed that when Travis ran the tests, the attributes object seems to be excpected to be always having the same structure without any extra props.

return { [ sectionName ]: [], [ sectionSaved ]: [ ...state[ sectionName ] ] };
}

// Check if we already have this section
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny thing, but part of the coding standards is to have a period at the end of comments

Suggested change
// Check if we already have this section
// Check if we already have this section.

// Check if we already have this section
if ( state[ sectionSaved ] ) {
return {
[ sectionName ]: [ ...state[ sectionSaved ] ],
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be good to also clear sectionSaved state when the data is restored. At the moment the issue following happens:

  1. Add a table
  2. Toggle on header rows
  3. Add some text to the header
  4. Use the 'Delete row' option to delete the header.
  5. Toggle the header back on

Expected Result: The header text shouldn't have been restored since it was deleted.
Actual Result: The header text was restored.

@talldan talldan added [Block] Table Affects the Table Block [Type] Enhancement A suggestion for improvement. labels Dec 11, 2019
@talldan talldan added the Needs Decision Needs a decision to be actionable or relevant label Dec 16, 2019
Base automatically changed from master to trunk March 1, 2021 15:42
@youknowriad
Copy link
Contributor

Looks like the original issue has been fixed already. Thanks for your efforts here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Table Affects the Table Block Needs Decision Needs a decision to be actionable or relevant [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Table Block: Toggling Header/Footer rows results in lost data
3 participants