mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-28 22:10:27 +08:00
bin/inbox: Remove selection mode (id-only / operation)
This commit is contained in:
+4
-23
@@ -12,7 +12,7 @@ use radicle::storage::{HasRepoId, ReadRepository};
|
||||
use radicle_cli::terminal;
|
||||
use radicle_cli::terminal::{Args, Error, Help};
|
||||
|
||||
use self::common::{Mode, RepositoryMode, SelectionMode};
|
||||
use self::common::RepositoryMode;
|
||||
|
||||
use crate::commands::tui_inbox::common::InboxOperation;
|
||||
use crate::ui::items::notification::filter::{NotificationFilter, SortBy};
|
||||
@@ -28,14 +28,10 @@ Usage
|
||||
|
||||
List options
|
||||
|
||||
--mode <MODE> Set selection mode; see MODE below (default: operation)
|
||||
--json Return JSON on stderr instead of calling `rad`
|
||||
|
||||
--sort-by <field> Sort by `id` or `timestamp` (default: timestamp)
|
||||
--reverse, -r Reverse the list
|
||||
|
||||
The MODE argument can be 'operation' or 'id'. 'operation' selects a notification id and
|
||||
an operation, whereas 'id' selects a notification id only.
|
||||
--json Return JSON on stderr instead of calling `rad`
|
||||
|
||||
Other options
|
||||
|
||||
@@ -64,7 +60,7 @@ pub enum OperationName {
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
pub struct ListOptions {
|
||||
mode: Mode,
|
||||
mode: RepositoryMode,
|
||||
filter: NotificationFilter,
|
||||
sort_by: SortBy,
|
||||
json: bool,
|
||||
@@ -101,19 +97,6 @@ impl Args for Options {
|
||||
};
|
||||
}
|
||||
|
||||
// list options.
|
||||
Long("mode") | Short('m') if op == OperationName::List => {
|
||||
let val = parser.value()?;
|
||||
let val = val.to_str().unwrap_or_default();
|
||||
|
||||
let selection_mode = match val {
|
||||
"operation" => SelectionMode::Operation,
|
||||
"id" => SelectionMode::Id,
|
||||
unknown => anyhow::bail!("unknown mode '{}'", unknown),
|
||||
};
|
||||
list_opts.mode = list_opts.mode.with_selection(selection_mode)
|
||||
}
|
||||
|
||||
Long("reverse") | Short('r') => {
|
||||
reverse = Some(true);
|
||||
}
|
||||
@@ -165,9 +148,7 @@ impl Args for Options {
|
||||
return Err(Error::Help.into());
|
||||
}
|
||||
|
||||
list_opts.mode = list_opts
|
||||
.mode
|
||||
.with_repository(repository_mode.unwrap_or_default());
|
||||
list_opts.mode = repository_mode.unwrap_or_default();
|
||||
list_opts.sort_by = if let Some(field) = field {
|
||||
SortBy {
|
||||
field,
|
||||
|
||||
@@ -2,17 +2,6 @@ use serde::Serialize;
|
||||
|
||||
use radicle::{identity::RepoId, node::notifications::NotificationId};
|
||||
|
||||
/// The application's subject. It tells the application
|
||||
/// which widgets to render and which output to produce.
|
||||
///
|
||||
/// Depends on CLI arguments given by the user.
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
pub enum SelectionMode {
|
||||
Id,
|
||||
#[default]
|
||||
Operation,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Debug, PartialEq, Eq)]
|
||||
pub enum RepositoryMode {
|
||||
#[default]
|
||||
@@ -21,28 +10,6 @@ pub enum RepositoryMode {
|
||||
ByRepo((RepoId, Option<String>)),
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Debug, PartialEq, Eq)]
|
||||
pub struct Mode {
|
||||
selection: SelectionMode,
|
||||
repository: RepositoryMode,
|
||||
}
|
||||
|
||||
impl Mode {
|
||||
pub fn with_selection(mut self, selection: SelectionMode) -> Self {
|
||||
self.selection = selection;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_repository(mut self, repository: RepositoryMode) -> Self {
|
||||
self.repository = repository;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn repository(&self) -> &RepositoryMode {
|
||||
&self.repository
|
||||
}
|
||||
}
|
||||
|
||||
/// The selected issue operation returned by the operation
|
||||
/// selection widget.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
|
||||
|
||||
@@ -26,7 +26,7 @@ use tui::ui::im::{Borders, Show};
|
||||
use tui::ui::{BufferedValue, Column, Spacing};
|
||||
use tui::{Channel, Exit};
|
||||
|
||||
use super::common::{Mode, RepositoryMode};
|
||||
use super::common::RepositoryMode;
|
||||
use crate::commands::tui_inbox::common::InboxOperation;
|
||||
use crate::ui::items::filter::Filter;
|
||||
use crate::ui::items::notification::filter::{NotificationFilter, SortBy};
|
||||
@@ -47,7 +47,6 @@ const HELP: &str = r#"# Generic keybindings
|
||||
|
||||
# Specific keybindings
|
||||
|
||||
`enter`: Select notification (if --mode id)
|
||||
`enter`: Show notification
|
||||
`r`: Reload notifications
|
||||
`c`: Clear notification
|
||||
@@ -65,7 +64,7 @@ pub struct Context {
|
||||
pub profile: Profile,
|
||||
pub project: Project,
|
||||
pub rid: RepoId,
|
||||
pub mode: Mode,
|
||||
pub mode: RepositoryMode,
|
||||
pub filter: NotificationFilter,
|
||||
pub sort_by: SortBy,
|
||||
}
|
||||
@@ -352,7 +351,7 @@ impl App {
|
||||
Column::new(Span::raw("ID").bold(), Constraint::Length(8)).hide_medium(),
|
||||
Column::new(Span::raw("Summary").bold(), Constraint::Fill(1)),
|
||||
Column::new(Span::raw("Repository").bold(), Constraint::Length(16))
|
||||
.skip(*context.mode.repository() != RepositoryMode::All),
|
||||
.skip(context.mode != RepositoryMode::All),
|
||||
Column::new(Span::raw("OID").bold(), Constraint::Length(8)).hide_medium(),
|
||||
Column::new(Span::raw("Kind").bold(), Constraint::Length(20)).hide_small(),
|
||||
Column::new(Span::raw("Change").bold(), Constraint::Length(8)).hide_small(),
|
||||
@@ -667,19 +666,16 @@ impl App {
|
||||
}
|
||||
|
||||
// Set project name
|
||||
let mode = match context.mode.repository() {
|
||||
let mode = match context.mode {
|
||||
RepositoryMode::ByRepo((rid, _)) => {
|
||||
let name = context.project.name().to_string();
|
||||
context
|
||||
.mode
|
||||
.clone()
|
||||
.with_repository(RepositoryMode::ByRepo((*rid, Some(name))))
|
||||
RepositoryMode::ByRepo((rid, Some(name)))
|
||||
}
|
||||
_ => context.mode.clone(),
|
||||
};
|
||||
|
||||
// Sort by project if all notifications are shown
|
||||
if let RepositoryMode::All = mode.repository() {
|
||||
if let RepositoryMode::All = mode {
|
||||
items.sort_by(|a, b| a.project.cmp(&b.project));
|
||||
}
|
||||
}
|
||||
@@ -711,7 +707,7 @@ impl Task for NotificationLoader {
|
||||
type Return = Message;
|
||||
|
||||
fn run(&self) -> anyhow::Result<Vec<Self::Return>> {
|
||||
let notifications = match self.context.mode.repository() {
|
||||
let notifications = match self.context.mode {
|
||||
RepositoryMode::All => {
|
||||
let notifs = self.context.profile.notifications_mut()?;
|
||||
let all = notifs.all()?;
|
||||
@@ -743,7 +739,7 @@ impl Task for NotificationLoader {
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
RepositoryMode::ByRepo((rid, _)) => {
|
||||
let repo = self.context.profile.storage.repository(*rid)?;
|
||||
let repo = self.context.profile.storage.repository(rid)?;
|
||||
let project = repo.project()?;
|
||||
let notifs = self.context.profile.notifications_mut()?;
|
||||
let by_repo = notifs.by_repo(&repo.id, "timestamp")?;
|
||||
|
||||
Reference in New Issue
Block a user