Skip to content

Commit

Permalink
Add ability to set keys when adding multiple rows
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo385 committed Dec 25, 2024
1 parent ec03fbf commit 8f3dd17
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lazy_github/ui/widgets/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lazy_github/ui/widgets/pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion lazy_github/ui/widgets/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8f3dd17

Please sign in to comment.