Reject the currently selected draft chunk.
(app: &App, tx: mpsc::UnboundedSender<Event>)
| 1803 | |
| 1804 | /// Reject the currently selected draft chunk. |
| 1805 | fn spawn_draft_reject(app: &App, tx: mpsc::UnboundedSender<Event>) { |
| 1806 | let mut client = app.client.clone(); |
| 1807 | let name = match app.selected_sandbox_name() { |
| 1808 | Some(n) => n.to_string(), |
| 1809 | None => return, |
| 1810 | }; |
| 1811 | let abs = app.draft_scroll + app.draft_selected; |
| 1812 | let chunk_id = match app.draft_chunks.get(abs) { |
| 1813 | Some(c) => c.id.clone(), |
| 1814 | None => return, |
| 1815 | }; |
| 1816 | let rule_name = app |
| 1817 | .draft_chunks |
| 1818 | .get(abs) |
| 1819 | .map_or_else(String::new, |c| c.rule_name.clone()); |
| 1820 | |
| 1821 | tokio::spawn(async move { |
| 1822 | let req = openshell_core::proto::RejectDraftChunkRequest { |
| 1823 | name, |
| 1824 | chunk_id, |
| 1825 | reason: String::new(), |
| 1826 | }; |
| 1827 | match tokio::time::timeout(Duration::from_secs(5), client.reject_draft_chunk(req)).await { |
| 1828 | Ok(Ok(_)) => { |
| 1829 | let _ = tx.send(Event::DraftActionResult(Ok(format!( |
| 1830 | "Rejected '{rule_name}'" |
| 1831 | )))); |
| 1832 | } |
| 1833 | Ok(Err(e)) => { |
| 1834 | let _ = tx.send(Event::DraftActionResult(Err(e.message().to_string()))); |
| 1835 | } |
| 1836 | Err(_) => { |
| 1837 | let _ = tx.send(Event::DraftActionResult( |
| 1838 | Err("reject timed out".to_string()), |
| 1839 | )); |
| 1840 | } |
| 1841 | } |
| 1842 | }); |
| 1843 | } |
| 1844 | |
| 1845 | /// Approve all pending draft chunks via the bulk `ApproveAllDraftChunks` RPC. |
| 1846 | /// |
no test coverage detected