Skip to content

Commit

Permalink
Add binding (backspace) to delete a request
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Aug 14, 2024
1 parent c832c16 commit fe08b31
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Binary file modified .coverage
Binary file not shown.
4 changes: 4 additions & 0 deletions src/posting/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ def save_to_disk(self, path: Path) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(yaml_content, encoding="utf-8")

def delete_from_disk(self) -> None:
if self.path:
self.path.unlink()

def __lt__(self, other: RequestModel) -> bool:
return request_sort_key(self) < request_sort_key(other)

Expand Down
16 changes: 16 additions & 0 deletions src/posting/widgets/collection/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ class CollectionTree(PostingTree[CollectionNode]):
"Quick Dupe",
# tooltip="Duplicate the request and automatically assign a unique name.",
),
Binding(
"backspace",
"delete_request",
"Delete",
# tooltip="Delete the request under the cursor.",
),
]

COMPONENT_CLASSES = {
Expand Down Expand Up @@ -444,6 +450,16 @@ def action_quick_duplicate_request(self) -> None:
after=cursor_node,
)

def action_delete_request(self) -> None:
cursor_node = self.cursor_node
if cursor_node is None:
return

if isinstance(cursor_node.data, RequestModel):
cursor_request = cursor_node.data
cursor_request.delete_from_disk()
cursor_node.remove()

def cache_request(self, request: RequestModel) -> None:
def get_base_url(url: str) -> str | None:
try:
Expand Down

0 comments on commit fe08b31

Please sign in to comment.