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

[Table/EditableCell] Only update saved and dirty values if value changed #1651

Merged
merged 2 commits into from
Oct 5, 2017

Conversation

gscshoyru
Copy link
Contributor

Fixes #1261

Changes proposed in this pull request:

We were updating saved and dirty value to match the value whenever any prop changed, no matter what. Even if shouldComponentUpdate would have returned false, because componentWillReceiveProps is always true. So if there were any changes made before rendering got there (because batched rendering), it'd reset those changes. Now this no longer happens.

Reviewers should focus on:

Is componentWillReceiveProps even the right place for this? It apparently can't live in componentWillUpdate because that won't take a setState, but... is there a better lifecycle spot for this?

Or more generally: is there a better way to do what I'm doing?

@blueprint-bot
Copy link

Only update saved and dirty values if value changed

Preview: documentation | table
Coverage: core | datetime

this.setState({ savedValue: value, dirtyValue: value });
if (value !== this.props.value) {
this.setState({ savedValue: value, dirtyValue: value });
}
Copy link
Contributor

@cmslewis cmslewis Oct 3, 2017

Choose a reason for hiding this comment

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

Cool! Now, how do we unit-test this?

(Or more explicitly: can you add one?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh. It should be doable, I guess.

@cmslewis cmslewis changed the title Only update saved and dirty values if value changed [Table/EditableCell] Only update saved and dirty values if value changed Oct 3, 2017
@gscshoyru gscshoyru force-pushed the gsc/fix-editable-value-update branch from 79f9d62 to 44b009c Compare October 3, 2017 20:22
@blueprint-bot
Copy link

Add test

Preview: documentation | table
Coverage: core | datetime

expect(input.element).to.equal(document.activeElement);

// edit
input.change("my-changed-value");
Copy link
Contributor

Choose a reason for hiding this comment

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

Whaaat is this glorious .change(...) magic.

expect(onConfirm.called).to.be.false;
expect(elem.find(".pt-editable-content").text()).to.equal("my-changed-value");

harness.mount(
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is functionally equivalent to setProps?

@cmslewis cmslewis merged commit 97ce8f9 into master Oct 5, 2017
@cmslewis cmslewis deleted the gsc/fix-editable-value-update branch October 5, 2017 18:48
@cmslewis cmslewis mentioned this pull request Oct 6, 2017
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.

3 participants