Approve the currently selected draft chunk.
(app: &App, tx: mpsc::UnboundedSender<Event>)
| 1764 | |
| 1765 | /// Approve the currently selected draft chunk. |
| 1766 | fn spawn_draft_approve(app: &App, tx: mpsc::UnboundedSender<Event>) { |
| 1767 | let mut client = app.client.clone(); |
| 1768 | let name = match app.selected_sandbox_name() { |
| 1769 | Some(n) => n.to_string(), |
| 1770 | None => return, |
| 1771 | }; |
| 1772 | let abs = app.draft_scroll + app.draft_selected; |
| 1773 | let chunk_id = match app.draft_chunks.get(abs) { |
| 1774 | Some(c) => c.id.clone(), |
| 1775 | None => return, |
| 1776 | }; |
| 1777 | let rule_name = app |
| 1778 | .draft_chunks |
| 1779 | .get(abs) |
| 1780 | .map_or_else(String::new, |c| c.rule_name.clone()); |
| 1781 | |
| 1782 | tokio::spawn(async move { |
| 1783 | let req = openshell_core::proto::ApproveDraftChunkRequest { name, chunk_id }; |
| 1784 | match tokio::time::timeout(Duration::from_secs(5), client.approve_draft_chunk(req)).await { |
| 1785 | Ok(Ok(resp)) => { |
| 1786 | let inner = resp.into_inner(); |
| 1787 | let _ = tx.send(Event::DraftActionResult(Ok(format!( |
| 1788 | "Approved '{}' -> policy v{}", |
| 1789 | rule_name, inner.policy_version |
| 1790 | )))); |
| 1791 | } |
| 1792 | Ok(Err(e)) => { |
| 1793 | let _ = tx.send(Event::DraftActionResult(Err(e.message().to_string()))); |
| 1794 | } |
| 1795 | Err(_) => { |
| 1796 | let _ = tx.send(Event::DraftActionResult(Err( |
| 1797 | "approve timed out".to_string() |
| 1798 | ))); |
| 1799 | } |
| 1800 | } |
| 1801 | }); |
| 1802 | } |
| 1803 | |
| 1804 | /// Reject the currently selected draft chunk. |
| 1805 | fn spawn_draft_reject(app: &App, tx: mpsc::UnboundedSender<Event>) { |
no test coverage detected