rusticity_term/ecr/
repo.rs1use crate::common::{format_iso_timestamp, ColumnTrait, UTC_TIMESTAMP_WIDTH};
2use crate::ui::table::Column as TableColumn;
3use ratatui::prelude::*;
4
5#[derive(Debug, Clone)]
6pub struct Repository {
7 pub name: String,
8 pub uri: String,
9 pub created_at: String,
10 pub tag_immutability: String,
11 pub encryption_type: String,
12}
13
14#[derive(Debug, Clone, Copy, PartialEq)]
15pub enum Column {
16 Name,
17 Uri,
18 CreatedAt,
19 TagImmutability,
20 EncryptionType,
21}
22
23impl Column {
24 pub fn all() -> Vec<Column> {
25 vec![
26 Column::Name,
27 Column::Uri,
28 Column::CreatedAt,
29 Column::TagImmutability,
30 Column::EncryptionType,
31 ]
32 }
33}
34
35impl ColumnTrait for Column {
36 fn name(&self) -> &'static str {
37 match self {
38 Column::Name => "Repository name",
39 Column::Uri => "URI",
40 Column::CreatedAt => "Created at",
41 Column::TagImmutability => "Tag immutability",
42 Column::EncryptionType => "Encryption type",
43 }
44 }
45}
46
47impl TableColumn<Repository> for Column {
48 fn name(&self) -> &str {
49 ColumnTrait::name(self)
50 }
51
52 fn width(&self) -> u16 {
53 ColumnTrait::name(self).len().max(match self {
54 Column::Name => 30,
55 Column::Uri => 50,
56 Column::CreatedAt => UTC_TIMESTAMP_WIDTH as usize,
57 Column::TagImmutability => 18,
58 Column::EncryptionType => 18,
59 }) as u16
60 }
61
62 fn render(&self, item: &Repository) -> (String, Style) {
63 let text = match self {
64 Column::Name => item.name.clone(),
65 Column::Uri => item.uri.clone(),
66 Column::CreatedAt => format_iso_timestamp(&item.created_at),
67 Column::TagImmutability => item.tag_immutability.clone(),
68 Column::EncryptionType => match item.encryption_type.as_str() {
69 "AES256" => "AES-256".to_string(),
70 "KMS" => "KMS".to_string(),
71 other => other.to_string(),
72 },
73 };
74 (text, Style::default())
75 }
76}