Skip to content

Commit

Permalink
Show overview on issue selection
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo385 committed Sep 1, 2024
1 parent 6991cd1 commit af48997
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
10 changes: 8 additions & 2 deletions lazy_github/ui/screens/primary.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from lazy_github.lib.github.client import GithubClient
from lazy_github.lib.github.issues import list_all_issues
from lazy_github.lib.github.pull_requests import get_full_pull_request
from lazy_github.lib.messages import IssuesAndPullRequestsFetched, PullRequestSelected, RepoSelected
from lazy_github.lib.messages import IssuesAndPullRequestsFetched, IssueSelected, PullRequestSelected, RepoSelected
from lazy_github.ui.widgets.actions import ActionsContainer
from lazy_github.ui.widgets.command_log import CommandLogSection
from lazy_github.ui.widgets.common import LazyGithubContainer
from lazy_github.ui.widgets.issues import IssuesContainer
from lazy_github.ui.widgets.issues import IssueOverviewTabPane, IssuesContainer
from lazy_github.ui.widgets.pull_requests import (
PrConversationTabPane,
PrDiffTabPane,
Expand Down Expand Up @@ -171,6 +171,12 @@ async def on_pull_request_selected(self, message: PullRequestSelected) -> None:
await tabbed_content.add_pane(PrConversationTabPane(self.client, full_pr))
tabbed_content.children[0].focus()

async def on_issue_selected(self, message: IssueSelected) -> None:
tabbed_content = self.query_one("#selection_detail_tabs", TabbedContent)
await tabbed_content.clear_panes()
await tabbed_content.add_pane(IssueOverviewTabPane(message.issue))
tabbed_content.children[0].focus()


class LazyGithubMainScreen(Screen):
BINDINGS = [("r", "refresh_repos", "Refresh global repo state")]
Expand Down
49 changes: 46 additions & 3 deletions lazy_github/ui/widgets/issues.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from typing import Dict

from textual import on
from textual.app import ComposeResult
from textual.containers import ScrollableContainer
from textual.coordinate import Coordinate
from textual.widgets import Label, Markdown, Rule, TabPane

from lazy_github.lib.messages import IssuesAndPullRequestsFetched
from lazy_github.models.github import Issue
from lazy_github.lib.messages import IssuesAndPullRequestsFetched, IssueSelected
from lazy_github.lib.string_utils import link
from lazy_github.models.github import Issue, IssueState
from lazy_github.ui.widgets.command_log import log_event
from lazy_github.ui.widgets.common import LazyGithubContainer, LazyGithubDataTable, SearchableLazyGithubDataTable


Expand All @@ -15,7 +21,6 @@ class IssuesContainer(LazyGithubContainer):

def compose(self) -> ComposeResult:
self.border_title = "[3] Issues"
# yield LazyGithubDataTable(id="issues_table")
yield SearchableLazyGithubDataTable(
id="searchable_issues_table", table_id="issues_table", search_input_id="issues_search", sort_key="number"
)
Expand Down Expand Up @@ -49,3 +54,41 @@ async def on_issues_and_pull_requests_fetched(self, message: IssuesAndPullReques
self.issues[issue.number] = issue
rows.append((issue.state, issue.number, issue.user.login, issue.title))
self.searchable_table.add_rows(rows)

async def get_selected_issue(self) -> Issue:
pr_number_coord = Coordinate(self.table.cursor_row, self.number_column_index)
number = self.table.get_cell_at(pr_number_coord)
return self.issues[number]

@on(LazyGithubDataTable.RowSelected, "#issues_table")
async def issue_selected(self) -> None:
issue = await self.get_selected_issue()
log_event(f"Selected Issue: #{issue.number}")
self.post_message(IssueSelected(issue))


class IssueOverviewTabPane(TabPane):
DEFAULT_CSS = """
IssueOverviewTabPane {
overflow-y: auto;
}
"""

def __init__(self, issue: Issue) -> None:
super().__init__("Overview", id="issue_overview_pane")
self.issue = issue

def compose(self) -> ComposeResult:
issue_link = link(f"(#{self.issue.number})", self.issue.html_url)
user_link = link(self.issue.user.login, self.issue.user.html_url)

if self.issue.state == IssueState.OPEN:
issue_status = "[frame green]Open[/frame green]"
else:
issue_status = "[frame purple]Closed[/frame purple]"

with ScrollableContainer():
yield Label(f"{issue_status} [b]{self.issue.title}[b] {issue_link} by {user_link}")

yield Rule()
yield Markdown(self.issue.body)

0 comments on commit af48997

Please sign in to comment.