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

widgets: Polish poll widget. #9833

Merged
merged 4 commits into from Jul 1, 2018
Merged

widgets: Polish poll widget. #9833

merged 4 commits into from Jul 1, 2018

Conversation

rheaparekh
Copy link
Collaborator

@rheaparekh rheaparekh commented Jun 26, 2018

I added this PR mainly to familiarize myself with the widget structure, so that I can work on a TODO widget.

Tasks:

  • Add basic styling for poll widget
  • Add question in the widget
  • Restrict question to one user
  • Add edit question feature
  • /poll question
  • Don't vote while adding options

commit 1:

Before and After styling for poll widget:

screen shot 2018-06-26 at 5 03 54 pm
screen shot 2018-06-26 at 5 04 03 pm

commit 2

Add question in the widget itself
ezgif com-video-to-gif 2

@showell
Copy link
Contributor

showell commented Jun 27, 2018

Looks good so far, can you rebase to get the build passing? I think I fixed the test flake.

@zulipbot zulipbot added size: L and removed size: M labels Jun 27, 2018
@rheaparekh rheaparekh force-pushed the poll_widget branch 3 times, most recently from e5a985b to 0fcf15e Compare June 27, 2018 19:23
@rheaparekh
Copy link
Collaborator Author

rheaparekh commented Jun 27, 2018

@showell Updated this! The tests are failing because of lint errors, I'll update it again.

@showell
Copy link
Contributor

showell commented Jun 27, 2018

The first commit looks great!

For asking the question, do we want to restrict this feature to the person that created the poll?

Also, I think it will be useful to say "/poll What do you want for dinner?" so that the question can be created from the compose box.

@rheaparekh
Copy link
Collaborator Author

rheaparekh commented Jun 27, 2018

Hmm, now that I think about it, restricting question to one user does seem right. Also, /poll What do you want for dinner? sounds good. Maybe we can have both: If the question is not mentioned, we prompt using the input box, and if it is mentioned, we show it directly. What are your thoughts?

@zulipbot zulipbot added size: XL and removed size: L labels Jun 28, 2018
@rheaparekh rheaparekh force-pushed the poll_widget branch 4 times, most recently from 76739f0 to b472f19 Compare June 28, 2018 19:23
@rheaparekh rheaparekh changed the title [WIP] widgets: Polish poll widget. widgets: Polish poll widget. Jun 28, 2018
@showell
Copy link
Contributor

showell commented Jun 28, 2018

I provided a bit of feedback on chat:

  • structure code more to clearly divide the is-my-poll and is-not-my-poll logic
  • add comments about why we show disabled input boxes
  • squash two commits adding poll

@showell
Copy link
Contributor

showell commented Jun 29, 2018

The build seems to be failing here. It may be a test flake.

@showell
Copy link
Contributor

showell commented Jun 29, 2018

You can probably still squash the questions changes a bit more, so that this PR just has one commit related to the UI side of adding question (so basically squash the "Restrict poll question..." into the prior commit). I'd still leave the other commit by itself (the one that parses what you typed in the compose box).

@rheaparekh
Copy link
Collaborator Author

@showell I have squashed the commit. (I kept the commits atomic to make it easier to review). And yes, the tests were failing because of test flake.

@rheaparekh
Copy link
Collaborator Author

@showell the build is passing now.

if content in ['/poll', '/tictactoe']:
widget_type = content[1:]

tokens = content.split(' ')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to handle that tokens[0] could theoretically throw IndexError or whatever.

I would consider something like this.

def get_widget_type() -> Optional[str]:
    valid_widget_types = ['tictactoe', 'poll']
    tokens = content.split(' ')
    if not tokens:
        return None

    if tokens[0].startswith('/'):
        widget_type = tokens[0][1:]
        if widget_type in valid_widget_types:
            return widget_type
    return None

widget_type = get_widget_type()
if widget_type is None:
    return

@showell
Copy link
Contributor

showell commented Jun 30, 2018

I tried testing this out, and I got some errors. Sorry, I don't have the errors handy, but basically extra_data was null and it confused some JS module. I think you can reproduce this as follows:

  • go to master
  • make some widgets (poll, tictactoe, etc.)
  • go to your branch
  • run the app

I'd also re-work the last commit a bit. I think you can take that function I gave you and extend it to return both widget_type and extra_data as a tuple, so that all the parsing more or less happens up front. And it will return (None, None) if it's not a slash command. I think this will be slightly cleaner and may fix the bug.

@rheaparekh
Copy link
Collaborator Author

@showell Thanks for pointing that bug out. It was basically being caused by no question being set in from the extra_data of the polls started in the master. I have added these lines to fix that. Also refracted the last commit.

The user can also edit the question after adding it.

The question in the poll can only be added/edited
by the user who started the poll.

The input bar will be disabled for the other users
if the question is not yet added. If the question is
added, the input bar will not be visible to the other
users.
Use the command '/poll question?', to start a question.
@showell showell merged commit b22d266 into zulip:master Jul 1, 2018
@showell
Copy link
Contributor

showell commented Jul 1, 2018

Merged, thanks @rheaparekh! I really like the experience here for the "other" people. For the person creating the poll, I could see us getting some feedback, like maybe we should leave the question in the input box next to "Edit question" to make it easy to edit typos or something. I'm looking forward to the next deploy!

@veerjainATgmail
Copy link

veerjainATgmail commented Jul 2, 2018 via email

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

Successfully merging this pull request may close these issues.

None yet

4 participants