From 8f3dd1768b52db2d181a285e9301e3ffdcc986f7 Mon Sep 17 00:00:00 2001 From: gizmo385 Date: Wed, 25 Dec 2024 01:07:34 -0700 Subject: [PATCH] Add ability to set keys when adding multiple rows --- lazy_github/ui/widgets/common.py | 8 ++++++-- lazy_github/ui/widgets/pull_requests.py | 2 +- lazy_github/ui/widgets/repositories.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lazy_github/ui/widgets/common.py b/lazy_github/ui/widgets/common.py index 00c0d23..f94552d 100644 --- a/lazy_github/ui/widgets/common.py +++ b/lazy_github/ui/widgets/common.py @@ -88,12 +88,16 @@ def add_row(self, *cells: str | int, key: str | None = None) -> None: self._rows_cache.append(tuple(cells)) self.table.add_row(*cells, key=key) - def add_rows(self, rows: Iterable[tuple[str | int, ...]]) -> None: + def add_rows(self, rows: Iterable[tuple[str | int, ...]], keys: Iterable[str] | None = None) -> None: """Add new rows to the currently displayed table and cache""" self._rows_cache.extend(rows) # TODO: Should this actually call handle_submitted_search so that new rows which don't match criteria aren't # shown? - self.table.add_rows(rows) + if keys: + for row, key in zip(rows, keys): + self.table.add_row(*row, key=key) + else: + self.table.add_rows(rows) self.sort() def set_rows(self, rows: list[tuple[str | int, ...]]) -> None: diff --git a/lazy_github/ui/widgets/pull_requests.py b/lazy_github/ui/widgets/pull_requests.py index b65cda4..bf28056 100644 --- a/lazy_github/ui/widgets/pull_requests.py +++ b/lazy_github/ui/widgets/pull_requests.py @@ -67,7 +67,7 @@ async def action_lookup_pull_request(self) -> None: if pr := await self.app.push_screen_wait(LookupPullRequestModal()): if pr.number not in self.pull_requests: self.pull_requests[pr.number] = pr - self.searchable_table.add_rows([pull_request_to_cell(pr)]) + self.searchable_table.add_row(*pull_request_to_cell(pr), str(pr.number)) self.post_message(PullRequestSelected(pr)) lg.info(f"Looked up PR #{pr.number}") diff --git a/lazy_github/ui/widgets/repositories.py b/lazy_github/ui/widgets/repositories.py index bb7ac94..53c4777 100644 --- a/lazy_github/ui/widgets/repositories.py +++ b/lazy_github/ui/widgets/repositories.py @@ -79,7 +79,7 @@ async def get_selected_repo(self) -> Repository: async def add_repo_to_table(self, repo: Repository) -> None: self.repos[repo.full_name] = repo - self.searchable_table.add_rows([_repo_to_row(repo)]) + self.searchable_table.add_row(*_repo_to_row(repo), repo.full_name) @work async def action_lookup_repository(self) -> None: