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

Add support for Polls Widget on ZT. #1551

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from zulipterminal.config.symbols import (
CHECK_MARK,
COLUMN_TITLE_BAR_LINE,
INVALID_MARKER,
PINNED_STREAMS_DIVIDER,
SECTION_DIVIDER_LINE,
)
Expand Down Expand Up @@ -2172,3 +2173,37 @@ def keypress(self, size: urwid_Size, key: str) -> str:
self.controller.exit_popup()
return key
return super().keypress(size, key)


class PollResultsView(PopUpView):
def __init__(
self,
controller: Any,
poll_question: str,
poll_options: Dict[str, Dict[str, Any]],
Copy link
Collaborator

Choose a reason for hiding this comment

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

This type seems inaccurate? This is one benefit of defining more complex data types that you're passing around, even if via typeddicts, since you can refer to them as a name and update them in one place.

) -> None:
poll_results_content: List[Tuple[str, List[Tuple[str, str]]]] = [("", [])]

for option_key, option_data in poll_options.items():
option_text = option_data["option"]
if len(option_text) >= 13:
option_text = option_text[:10] + "…"
Comment on lines +2189 to +2190
Copy link
Collaborator

Choose a reason for hiding this comment

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

We definitely need a cut-off length, since otherwise this causes problems :) However, this length seems rather small? For example, even something like 'None of the above' doesn't fit, or 'long long long'?

  • User names can be up to 100 characters, so that doesn't help with calculating this if we're aiming to work down to ~80x24 size. I'm sure we could try something like 30 at least, or was there as reason you picked these values?
  • In any case, please hoist these into a constant and use it consistently in the calculation
  • Is there a reason you have 13 vs 10?

voter_names = option_data["votes"]

voters_display = (
"\n".join(map(str, voter_names))
if voter_names
else f"{INVALID_MARKER} No votes yet"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does make it stand out better 👍

)

poll_results_content[0][1].append((option_text, voters_display))

popup_width, column_widths = self.calculate_table_widths(
poll_results_content, len(poll_question)
)

widgets = self.make_table_with_categories(poll_results_content, column_widths)

super().__init__(
controller, widgets, "SHOW_POLL_VOTES", popup_width, poll_question
)