rusticity_term/sqs/
sub.rs1use crate::common::{translate_column, ColumnId};
2use crate::ui::table::Column as TableColumn;
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6pub fn init(i18n: &mut HashMap<String, String>) {
7 for col in Column::all() {
8 i18n.entry(col.id().to_string())
9 .or_insert_with(|| col.default_name().to_string());
10 }
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct SnsSubscription {
15 pub subscription_arn: String,
16 pub topic_arn: String,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq)]
20pub enum Column {
21 SubscriptionArn,
22 TopicArn,
23}
24
25impl Column {
26 const ID_SUBSCRIPTION_ARN: &'static str = "column.sqs.subscription.subscription_arn";
27 const ID_TOPIC_ARN: &'static str = "column.sqs.subscription.topic_arn";
28
29 pub const fn id(&self) -> ColumnId {
30 match self {
31 Column::SubscriptionArn => Self::ID_SUBSCRIPTION_ARN,
32 Column::TopicArn => Self::ID_TOPIC_ARN,
33 }
34 }
35
36 pub const fn default_name(&self) -> &'static str {
37 match self {
38 Column::SubscriptionArn => "Subscription ARN",
39 Column::TopicArn => "Topic ARN",
40 }
41 }
42
43 pub fn name(&self) -> String {
44 translate_column(self.id(), self.default_name())
45 }
46
47 pub fn from_id(id: &str) -> Option<Self> {
48 match id {
49 Self::ID_SUBSCRIPTION_ARN => Some(Column::SubscriptionArn),
50 Self::ID_TOPIC_ARN => Some(Column::TopicArn),
51 _ => None,
52 }
53 }
54
55 pub const fn all() -> [Column; 2] {
56 [Column::SubscriptionArn, Column::TopicArn]
57 }
58
59 pub fn ids() -> Vec<ColumnId> {
60 Self::all().iter().map(|c| c.id()).collect()
61 }
62}
63
64impl TableColumn<SnsSubscription> for Column {
65 fn name(&self) -> &str {
66 Box::leak(translate_column(self.id(), self.default_name()).into_boxed_str())
67 }
68
69 fn width(&self) -> u16 {
70 let translated = translate_column(self.id(), self.default_name());
71 translated.len().max(60) as u16
72 }
73
74 fn render(&self, item: &SnsSubscription) -> (String, ratatui::style::Style) {
75 let text = match self {
76 Column::SubscriptionArn => item.subscription_arn.clone(),
77 Column::TopicArn => item.topic_arn.clone(),
78 };
79 (text, ratatui::style::Style::default())
80 }
81}