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

Use getInitialSelectedItem if this.state.selected is empty #8915

Merged
merged 1 commit into from
Oct 26, 2016
Merged

Use getInitialSelectedItem if this.state.selected is empty #8915

merged 1 commit into from
Oct 26, 2016

Conversation

brunoscopelliti
Copy link
Contributor

Proposed fix for #8913 .

Since the problem is that this.state.selected has lost its value, I try to use it when it is set, otherwise I use getInitialSelectedItem to get the initial selected value.

@alisterscott alisterscott added [Feature Group] Appearance & Themes Features related to the appearance of sites. Framework [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Feature Group] Appearance & Themes Features related to the appearance of sites. labels Oct 24, 2016
@alisterscott
Copy link
Contributor

Thanks for your contribution @brunoscopelliti, it's very much appreciated.

I took a look at this and it works well and it seems to fix the issue I raised. I couldn't see any other issues introduced elsewhere in calypso, but since this is changing every select list in calypso I want to make sure that the code is correct, so I will ask someone else to do a code review, then I'm happy to ship it.

Before

587905b8-99d0-11e6-9160-def0bff044da

After

select list after

@brunoscopelliti
Copy link
Contributor Author

Thank you @alisterscott for the fast review.
If anybody else has some suggestion, it is more than welcome.

I noticed that the select-component dropdown is not covered by unit tests...
If you think this could be somehow useful, I will be happy to submit a new pull request with some tests in the next days.

Finally, I've a question: what do you use to record those screenshots?

@spen
Copy link
Contributor

spen commented Oct 24, 2016

Blame shows that this hasn't been updated since the initial commit, @retrofox & @ehg look to have done work nearby so may be of some help.

I noticed that there are no unit tests for this component - perhaps we could support his PR with some coverage? I'd be happy to help out there!

Also +1-ing the gif tip!

this.props.options, { value: this.state.selected }
const dropdownClassName = classNames( dropdownClasses );

let selectedText = this.props.selectedText;
Copy link
Contributor

Choose a reason for hiding this comment

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

Code looks good here, but we can maybe decompose this a bit with a helper method:

getSelectedText() {
    const { options, selectedText } = this.props;
    const { selected } = this.state;
    if ( selectedText ) {
        return selectedText;
    }
    //return currently selected text
    const selectedValue = selected ? selected : this.getInitialSelectedItem( this.props );
    return result( find( options, { value: selectedValue } ) );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice. This also pairs well with the idea of having unit tests...

I will update the pull request; by the way what is your workflow to update a pull request? Is it ok if I simply push a new commit on this branch?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it ok if I simply push a new commit on this branch?

Yes please do. 😄 We also prefer to rebase branches with master (rather than merge) to keep history clean. We'll of course make sure you'll get credit for the fix, so let's try to squash the changes on this branch to a single commit, so @alisterscott can do a merge commit into master.

See also our contributing doc

Copy link
Contributor Author

@brunoscopelliti brunoscopelliti Oct 25, 2016

Choose a reason for hiding this comment

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

I've update the pull request.

Is it ok that now other commits are bundled up in this pull request?

I've not great experience with rebase in Git, and I'm not sure I've followed the process correctly. @gwwar Could you please review the steps, and correct me if I did something wrong/not necessary?

I followed the following steps:

On my master branch

git pull Automattic master
git push

On the fix/issue-8913 branch

git rebase master

At this point the status was somehow not consistent:

#  Your branch and 'origin/fix/issue-8913' have diverged,
#  and have 10 and 1 different commits each, respectively.

I thought I've to do a rebase also with origin/fix/issue-8913. So still from the fix/issue-8913 branch

git rebase origin/fix/issue-8913

This restored the state, and I was able to proceed; I edited the file, commit, squash, and push.

ps. I don't care too much about the attribution of the commit (I'm here primarily to learn), if I screwed up the pull request seriously feel free to discard it, and restore the fix in a different branch.

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 think of rebase as picking out your updates, and replaying them on a fresh master. Your branch will diverge from origin if someone else has pushed to origin master. (See visual here: https://onlywei.github.io/explain-git-with-d3/ )

At this point

#  Your branch and 'origin/fix/issue-8913' have diverged,
#  and have 10 and 1 different commits each, respectively.

Your branch was fine, you just needed a git push --force to push changes to the origin branch. (Note that this is ok to do since you're the only one working in the branch).

To clean this up please rebase again with master, and do a force push to your origin branch. Let us know if you still need help and I can do this manually.

Copy link
Contributor

Choose a reason for hiding this comment

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

Almost, 😄 I think 68fbbcb snuck in. Perhaps make sure your local master is up to date.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gwwar Thank you very much for the explanation! I think now it should be ok.

@gwwar
Copy link
Contributor

gwwar commented Oct 24, 2016

👍 Left a suggestion, but this looks good to me.

@gwwar
Copy link
Contributor

gwwar commented Oct 24, 2016

Finally, I've a question: what do you use to record those screenshots?

I'm not sure what workflow @alisterscott uses, but I personally do a screen recording with QuickTime, then convert the movie into a gif using gify

@alisterscott
Copy link
Contributor

Finally, I've a question: what do you use to record those screenshots?

I used LiceCap which is free/open source and records animated GIFs directly from your screen - link

@gwwar
Copy link
Contributor

gwwar commented Oct 25, 2016

@alisterscott did you want to do a last test and merge this in? Let's make sure this goes in as a merge:
screen shot 2016-10-25 at 7 54 36 am

@alisterscott
Copy link
Contributor

Retested and LGTM - 🚢 this now

@alisterscott alisterscott added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Oct 26, 2016
@alisterscott alisterscott merged commit 5516a5d into Automattic:master Oct 26, 2016
@brunoscopelliti brunoscopelliti deleted the fix/issue-8913 branch October 26, 2016 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants