diff --git a/crates/atuin-history/src/stats.rs b/crates/atuin-history/src/stats.rs index fb6781fe..ab4127df 100644 --- a/crates/atuin-history/src/stats.rs +++ b/crates/atuin-history/src/stats.rs @@ -1,14 +1,16 @@ use std::collections::{HashMap, HashSet}; use crossterm::style::{Color, ResetColor, SetAttribute, SetForegroundColor}; - -use atuin_client::{history::History, settings::Settings}; +use serde::{Deserialize, Serialize}; use unicode_segmentation::UnicodeSegmentation; -pub struct Stats<'a> { +use atuin_client::{history::History, settings::Settings}; + +#[derive(Debug, Serialize, Deserialize)] +pub struct Stats { pub total_commands: usize, pub unique_commands: usize, - pub top: Vec<(Vec<&'a str>, usize)>, + pub top: Vec<(Vec, usize)>, } fn first_non_whitespace(s: &str) -> Option { @@ -161,12 +163,12 @@ pub fn pretty_print(stats: Stats, ngram_size: usize) { println!("Unique commands: {}", stats.unique_commands); } -pub fn compute<'a>( +pub fn compute( settings: &Settings, - history: &'a [History], + history: &[History], count: usize, ngram_size: usize, -) -> Option> { +) -> Option { let mut commands = HashSet::<&str>::with_capacity(history.len()); let mut total_unignored = 0; let mut prefixes = HashMap::, usize>::with_capacity(history.len()); @@ -212,7 +214,10 @@ pub fn compute<'a>( Some(Stats { unique_commands: unique, total_commands: total_unignored, - top, + top: top + .into_iter() + .map(|t| (t.0.into_iter().map(|s| s.to_string()).collect(), t.1)) + .collect(), }) } diff --git a/ui/backend/Cargo.lock b/ui/backend/Cargo.lock index 85736e2a..c8eace7c 100644 --- a/ui/backend/Cargo.lock +++ b/ui/backend/Cargo.lock @@ -288,6 +288,36 @@ dependencies = [ "tokio", ] +[[package]] +name = "atuin-history" +version = "0.1.0" +dependencies = [ + "async-trait", + "atuin-client", + "atuin-common", + "base64 0.21.7", + "crossterm", + "directories", + "eyre", + "fs-err", + "futures-util", + "indicatif", + "interim", + "itertools", + "log", + "semver", + "serde", + "serde_json", + "sysinfo", + "time", + "tokio", + "tracing", + "unicode-segmentation", + "unicode-width", + "uuid", + "whoami", +] + [[package]] name = "autocfg" version = "1.2.0" @@ -860,6 +890,32 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +[[package]] +name = "crossterm" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" +dependencies = [ + "bitflags 2.5.0", + "crossterm_winapi", + "filedescriptor", + "libc", + "mio", + "parking_lot", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -1324,6 +1380,17 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "filedescriptor" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7199d965852c3bac31f779ef99cbb4537f80e952e2d6aa0ffeb30cce00f4f46e" +dependencies = [ + "libc", + "thiserror", + "winapi", +] + [[package]] name = "finl_unicode" version = "1.2.0" @@ -2602,6 +2669,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", + "log", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] @@ -4114,6 +4182,27 @@ dependencies = [ "dirs", ] +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -4819,6 +4908,41 @@ dependencies = [ "tauri-utils", ] +[[package]] +name = "tauri-plugin" +version = "2.0.0-beta.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6baaee0a083db1e04a1b7a3b0670d86a4d95dd2a54e7cbfb5547762b8ed098d9" +dependencies = [ + "anyhow", + "glob", + "plist", + "schemars", + "serde", + "serde_json", + "tauri-utils", + "toml 0.8.12", + "walkdir", +] + +[[package]] +name = "tauri-plugin-sql" +version = "2.0.0-beta.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90c17360ef831e2789aab5439c241c8d7787ebd7c4fc40540181539b151f93bb" +dependencies = [ + "futures-core", + "log", + "serde", + "serde_json", + "sqlx", + "tauri", + "tauri-plugin", + "thiserror", + "time", + "tokio", +] + [[package]] name = "tauri-runtime" version = "2.0.0-beta.11" @@ -4864,16 +4988,16 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "2.0.0-beta.11" +version = "2.0.0-beta.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a148adf8077e1891c8b7d1c2be90c1c8eb8c7a071c35bb8edbdfe7cd9d8e23c" +checksum = "d4709765385f035338ecc330f3fba753b8ee283c659c235da9768949cdb25469" dependencies = [ "brotli", "cargo_metadata", "ctor", "dunce", "glob", - "heck 0.4.1", + "heck 0.5.0", "html5ever", "infer", "json-patch", @@ -5316,6 +5440,7 @@ dependencies = [ "atuin-client", "atuin-common", "atuin-dotfiles", + "atuin-history", "eyre", "serde", "serde_json", @@ -5323,6 +5448,7 @@ dependencies = [ "syntect", "tauri", "tauri-build", + "tauri-plugin-sql", "time", "uuid", ] diff --git a/ui/backend/Cargo.toml b/ui/backend/Cargo.toml index 9cf47436..1bc40b02 100644 --- a/ui/backend/Cargo.toml +++ b/ui/backend/Cargo.toml @@ -14,8 +14,8 @@ tauri-build = { version = "2.0.0-beta", features = [] } [dependencies] atuin-client = { path = "../../crates/atuin-client", version = "18.2.0" } atuin-common = { path = "../../crates/atuin-common", version = "18.2.0" } - atuin-dotfiles = { path = "../../crates/atuin-dotfiles", version = "0.2.0" } +atuin-history = { path = "../../crates/atuin-history", version = "0.1.0" } eyre = "0.6" tauri = { version = "2.0.0-beta", features = ["tray-icon"] } @@ -36,3 +36,7 @@ custom-protocol = ["tauri/custom-protocol"] #[lib] #crate-type = ["staticlib", "cdylib", "rlib"] + +[dependencies.tauri-plugin-sql] +features = ["sqlite"] # or "postgres", or "mysql" +version = "2.0.0-beta" diff --git a/ui/backend/capabilities/migrated.json b/ui/backend/capabilities/migrated.json index a47f2d7b..70b8b077 100644 --- a/ui/backend/capabilities/migrated.json +++ b/ui/backend/capabilities/migrated.json @@ -2,9 +2,7 @@ "identifier": "migrated", "description": "permissions that were migrated from v1", "context": "local", - "windows": [ - "main" - ], + "windows": ["main"], "permissions": [ "path:default", "event:default", @@ -12,13 +10,10 @@ "app:default", "resources:default", "menu:default", - "tray:default" + "tray:default", + "sql:allow-load", + "sql:allow-execute", + "sql:allow-select" ], - "platforms": [ - "linux", - "macOS", - "windows", - "android", - "iOS" - ] -} \ No newline at end of file + "platforms": ["linux", "macOS", "windows", "android", "iOS"] +} diff --git a/ui/backend/src/db.rs b/ui/backend/src/db.rs index c1aa4de9..7e29302a 100644 --- a/ui/backend/src/db.rs +++ b/ui/backend/src/db.rs @@ -15,6 +15,7 @@ use atuin_client::{ database::{Context, Database, OptFilters, Sqlite}, history::History, }; +use atuin_history::stats; // useful for preprocessing data for the frontend #[derive(Serialize, Debug)] @@ -28,6 +29,7 @@ pub struct GlobalStats { pub total_history: u64, pub daily: Vec>, + pub stats: Option, pub last_1d: u64, pub last_7d: u64, @@ -55,31 +57,33 @@ pub struct UIHistory { pub host: String, } -pub fn to_ui_history(history: History) -> UIHistory { - let parts: Vec = history.hostname.split(':').map(str::to_string).collect(); +impl From for UIHistory { + fn from(history: History) -> Self { + let parts: Vec = history.hostname.split(':').map(str::to_string).collect(); - let (host, user) = if parts.len() == 2 { - (parts[0].clone(), parts[1].clone()) - } else { - ("no-host".to_string(), "no-user".to_string()) - }; + let (host, user) = if parts.len() == 2 { + (parts[0].clone(), parts[1].clone()) + } else { + ("no-host".to_string(), "no-user".to_string()) + }; - let mac = format!("/Users/{}", user); - let linux = format!("/home/{}", user); + let mac = format!("/Users/{}", user); + let linux = format!("/home/{}", user); - let cwd = history.cwd.replace(mac.as_str(), "~"); - let cwd = cwd.replace(linux.as_str(), "~"); + let cwd = history.cwd.replace(mac.as_str(), "~"); + let cwd = cwd.replace(linux.as_str(), "~"); - UIHistory { - id: history.id.0, - timestamp: history.timestamp.unix_timestamp_nanos(), - duration: history.duration, - exit: history.exit, - command: history.command, - session: history.session, - host, - user, - cwd, + UIHistory { + id: history.id.0, + timestamp: history.timestamp.unix_timestamp_nanos(), + duration: history.duration, + exit: history.exit, + command: history.command, + session: history.session, + host, + user, + cwd, + } } } @@ -94,35 +98,47 @@ impl HistoryDB { Ok(Self(sqlite)) } - pub async fn list(&self, limit: Option, unique: bool) -> Result, String> { - let filters = vec![]; - - // bit of a hack but provide an empty context - // shell context makes _no sense_ in a GUI - let context = Context { - session: "".to_string(), - cwd: "".to_string(), - host_id: "".to_string(), - hostname: "".to_string(), - git_root: None, + pub async fn list( + &self, + offset: Option, + limit: Option, + ) -> Result, String> { + let query = if let Some(limit) = limit { + sqlx::query("select * from history order by timestamp desc limit ?1 offset ?2") + .bind(limit as i64) + .bind(offset.unwrap_or(0) as i64) + } else { + sqlx::query("select * from history order by timestamp desc") }; - let history = self - .0 - .list(&filters, &context, limit, unique, false) + let history: Vec = query + .map(|row: SqliteRow| { + History::from_db() + .id(row.get("id")) + .timestamp( + time::OffsetDateTime::from_unix_timestamp_nanos( + row.get::("timestamp") as i128, + ) + .unwrap(), + ) + .duration(row.get("duration")) + .exit(row.get("exit")) + .command(row.get("command")) + .cwd(row.get("cwd")) + .session(row.get("session")) + .hostname(row.get("hostname")) + .deleted_at(None) + .build() + .into() + }) + .fetch_all(&self.0.pool) .await .map_err(|e| e.to_string())?; - let history = history - .into_iter() - .filter(|h| h.duration > 0) - .map(to_ui_history) - .collect(); - Ok(history) } - pub async fn search(&self, query: &str) -> Result, String> { + pub async fn search(&self, offset: Option, query: &str) -> Result, String> { let context = Context { session: "".to_string(), cwd: "".to_string(), @@ -133,6 +149,7 @@ impl HistoryDB { let filters = OptFilters { limit: Some(200), + offset: offset.map(|offset| offset as i64), ..OptFilters::default() }; @@ -151,7 +168,7 @@ impl HistoryDB { let history = history .into_iter() .filter(|h| h.duration > 0) - .map(to_ui_history) + .map(|h| h.into()) .collect(); Ok(history) @@ -189,7 +206,7 @@ impl HistoryDB { .build() .into() }) - .map(to_ui_history) + .map(|h: History| h.into()) .fetch_all(&self.0.pool) .await .map_err(|e| e.to_string())?; @@ -240,6 +257,7 @@ impl HistoryDB { last_7d: week, last_1d: day, daily, + stats: None, }) } } diff --git a/ui/backend/src/main.rs b/ui/backend/src/main.rs index fe6271b8..ce248d61 100644 --- a/ui/backend/src/main.rs +++ b/ui/backend/src/main.rs @@ -13,6 +13,7 @@ mod store; use atuin_client::{ encryption, history::HISTORY_TAG, record::sqlite_store::SqliteStore, record::store::Store, }; +use atuin_history::stats; use db::{GlobalStats, HistoryDB, UIHistory}; use dotfiles::aliases::aliases; @@ -25,25 +26,30 @@ struct HomeInfo { } #[tauri::command] -async fn list() -> Result, String> { +async fn list(offset: Option) -> Result, String> { let settings = Settings::new().map_err(|e| e.to_string())?; let db_path = PathBuf::from(settings.db_path.as_str()); let db = HistoryDB::new(db_path, settings.local_timeout).await?; - let history = db.list(Some(100), false).await?; + let history = db + .list(Some(offset.unwrap_or(0)), Some(100)) + .await? + .into_iter() + .map(|h| h.into()) + .collect(); Ok(history) } #[tauri::command] -async fn search(query: String) -> Result, String> { +async fn search(query: String, offset: Option) -> Result, String> { let settings = Settings::new().map_err(|e| e.to_string())?; let db_path = PathBuf::from(settings.db_path.as_str()); let db = HistoryDB::new(db_path, settings.local_timeout).await?; - let history = db.search(query.as_str()).await?; + let history = db.search(offset, query.as_str()).await?; Ok(history) } @@ -54,11 +60,21 @@ async fn global_stats() -> Result { let db_path = PathBuf::from(settings.db_path.as_str()); let db = HistoryDB::new(db_path, settings.local_timeout).await?; - let stats = db.global_stats().await?; + let mut stats = db.global_stats().await?; + + let history = db.list(None, None).await?; + let history_stats = stats::compute(&settings, &history, 10, 1); + + stats.stats = history_stats; Ok(stats) } +#[tauri::command] +async fn config() -> Result { + Settings::new().map_err(|e| e.to_string()) +} + #[tauri::command] async fn home_info() -> Result { let settings = Settings::new().map_err(|e| e.to_string())?; @@ -115,6 +131,7 @@ fn main() { global_stats, aliases, home_info, + config, dotfiles::aliases::import_aliases, dotfiles::aliases::delete_alias, dotfiles::aliases::set_alias, @@ -122,6 +139,7 @@ fn main() { dotfiles::vars::delete_var, dotfiles::vars::set_var, ]) + .plugin(tauri_plugin_sql::Builder::default().build()) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/ui/package.json b/ui/package.json index e3025717..98163f01 100644 --- a/ui/package.json +++ b/ui/package.json @@ -16,7 +16,9 @@ "@radix-ui/react-slot": "^1.0.2", "@tailwindcss/forms": "^0.5.7", "@tanstack/react-table": "^8.15.3", + "@tanstack/react-virtual": "^3.5.0", "@tauri-apps/api": "2.0.0-beta.7", + "@tauri-apps/plugin-sql": "2.0.0-beta.2", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "core": "link:@tauri-apps/api/core", @@ -27,6 +29,8 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-spinners": "^0.13.8", + "react-window": "^1.8.10", + "react-window-infinite-loader": "^1.0.9", "recharts": "^2.12.4", "tailwind-merge": "^2.2.2", "tailwindcss-animate": "^1.0.7", diff --git a/ui/pnpm-lock.yaml b/ui/pnpm-lock.yaml index 1b4214fe..b777dd5f 100644 --- a/ui/pnpm-lock.yaml +++ b/ui/pnpm-lock.yaml @@ -23,9 +23,15 @@ dependencies: '@tanstack/react-table': specifier: ^8.15.3 version: 8.15.3(react-dom@18.2.0)(react@18.2.0) + '@tanstack/react-virtual': + specifier: ^3.5.0 + version: 3.5.0(react-dom@18.2.0)(react@18.2.0) '@tauri-apps/api': specifier: 2.0.0-beta.7 version: 2.0.0-beta.7 + '@tauri-apps/plugin-sql': + specifier: 2.0.0-beta.2 + version: 2.0.0-beta.2 class-variance-authority: specifier: ^0.7.0 version: 0.7.0 @@ -56,6 +62,12 @@ dependencies: react-spinners: specifier: ^0.13.8 version: 0.13.8(react-dom@18.2.0)(react@18.2.0) + react-window: + specifier: ^1.8.10 + version: 1.8.10(react-dom@18.2.0)(react@18.2.0) + react-window-infinite-loader: + specifier: ^1.0.9 + version: 1.0.9(react-dom@18.2.0)(react@18.2.0) recharts: specifier: ^2.12.4 version: 2.12.4(react-dom@18.2.0)(react@18.2.0) @@ -584,7 +596,7 @@ packages: react: ^16 || ^17 || ^18 react-dom: ^16 || ^17 || ^18 dependencies: - '@tanstack/react-virtual': 3.2.0(react-dom@18.2.0)(react@18.2.0) + '@tanstack/react-virtual': 3.5.0(react-dom@18.2.0)(react@18.2.0) client-only: 0.0.1 react: 18.2.0 react-dom: 18.2.0(react@18.2.0) @@ -1300,13 +1312,13 @@ packages: react-dom: 18.2.0(react@18.2.0) dev: false - /@tanstack/react-virtual@3.2.0(react-dom@18.2.0)(react@18.2.0): - resolution: {integrity: sha512-OEdMByf2hEfDa6XDbGlZN8qO6bTjlNKqjM3im9JG+u3mCL8jALy0T/67oDI001raUUPh1Bdmfn4ZvPOV5knpcg==} + /@tanstack/react-virtual@3.5.0(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-rtvo7KwuIvqK9zb0VZ5IL7fiJAEnG+0EiFZz8FUOs+2mhGqdGmjKIaT1XU7Zq0eFqL0jonLlhbayJI/J2SA/Bw==} peerDependencies: react: ^16.8.0 || ^17.0.0 || ^18.0.0 react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 dependencies: - '@tanstack/virtual-core': 3.2.0 + '@tanstack/virtual-core': 3.5.0 react: 18.2.0 react-dom: 18.2.0(react@18.2.0) dev: false @@ -1316,8 +1328,13 @@ packages: engines: {node: '>=12'} dev: false - /@tanstack/virtual-core@3.2.0: - resolution: {integrity: sha512-P5XgYoAw/vfW65byBbJQCw+cagdXDT/qH6wmABiLt4v4YBT2q2vqCOhihe+D1Nt325F/S/0Tkv6C5z0Lv+VBQQ==} + /@tanstack/virtual-core@3.5.0: + resolution: {integrity: sha512-KnPRCkQTyqhanNC0K63GBG3wA8I+D1fQuVnAvcBF8f13akOKeQp1gSbu6f77zCxhEk727iV5oQnbHLYzHrECLg==} + dev: false + + /@tauri-apps/api@2.0.0-beta.4: + resolution: {integrity: sha512-Nxtj28NYUo5iwYkpYslxmOPkdI2WkELU2e3UH9nbJm9Ydki2CQwJVGQxx4EANtdZcMNsEsUzRqaDTvEUYH1l6w==} + engines: {node: '>= 18', npm: '>= 6.6.0', yarn: '>= 1.19.1'} dev: false /@tauri-apps/api@2.0.0-beta.7: @@ -1432,6 +1449,12 @@ packages: '@tauri-apps/cli-win32-x64-msvc': 2.0.0-beta.2 dev: true + /@tauri-apps/plugin-sql@2.0.0-beta.2: + resolution: {integrity: sha512-gNX/4VjGl0TD4Ct58ar4bLF82iRp2L5sS79FmtzKlXYj7tVbkxenIi+mGIBz3Ut1JQP5WNL4/5wq74bkDlBggA==} + dependencies: + '@tauri-apps/api': 2.0.0-beta.4 + dev: false + /@types/babel__core@7.20.5: resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==} dependencies: @@ -2107,6 +2130,10 @@ packages: engines: {node: '>=12'} dev: false + /memoize-one@5.2.1: + resolution: {integrity: sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==} + dev: false + /merge2@1.4.1: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} engines: {node: '>= 8'} @@ -2381,6 +2408,30 @@ packages: react-dom: 18.2.0(react@18.2.0) dev: false + /react-window-infinite-loader@1.0.9(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-5Hg89IdU4Vrp0RT8kZYKeTIxWZYhNkVXeI1HbKo01Vm/Z7qztDvXljwx16sMzsa9yapRJQW3ODZfMUw38SOWHw==} + engines: {node: '>8.0.0'} + peerDependencies: + react: ^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0 + react-dom: ^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0 + dependencies: + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + dev: false + + /react-window@1.8.10(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-Y0Cx+dnU6NLa5/EvoHukUD0BklJ8qITCtVEPY1C/nL8wwoZ0b5aEw8Ff1dOVHw7fCzMt55XfJDd8S8W8LCaUCg==} + engines: {node: '>8.0.0'} + peerDependencies: + react: ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 + react-dom: ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 + dependencies: + '@babel/runtime': 7.24.4 + memoize-one: 5.2.1 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + dev: false + /react@18.2.0: resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==} engines: {node: '>=0.10.0'} diff --git a/ui/src/App.css b/ui/src/App.css index 5a32a1a5..cf6d3123 100644 --- a/ui/src/App.css +++ b/ui/src/App.css @@ -9,3 +9,19 @@ html { .logo.react:hover { filter: drop-shadow(0 0 2em #61dafb); } + +.history-header { + height: 150px; +} + +.history-search { + height: 64px; +} + +.history-list { + height: calc(100vh - 150px - 64px); +} + +.history-item { + height: 90px; +} diff --git a/ui/src/components/HistoryList.tsx b/ui/src/components/HistoryList.tsx index 9616ecf0..7cdeacd8 100644 --- a/ui/src/components/HistoryList.tsx +++ b/ui/src/components/HistoryList.tsx @@ -1,3 +1,4 @@ +import { useRef } from "react"; import { ChevronRightIcon } from "@heroicons/react/20/solid"; // @ts-ignore @@ -19,70 +20,81 @@ function msToTime(ms: number) { export default function HistoryList(props: any) { return ( -
    - {props.history.map((h: any) => ( -
  • -
    -
    -

    - {DateTime.fromMillis(h.timestamp / 1000000).toLocaleString( - DateTime.TIME_WITH_SECONDS, - )} -

    -

    - {DateTime.fromMillis(h.timestamp / 1000000).toLocaleString( - DateTime.DATE_SHORT, - )} -

    -
    -
    -
    -                {h.command}
    -              
    -

    - {h.user} + {props.items.map((i: any) => { + let h = props.history[i.index]; -  on  - - {h.host} - -  in  - - {h.cwd} -

    -
    -
    -
    -
    -

    {h.exit}

    - {h.duration ? ( -

    - + return ( +

  • +
    +
    +

    + {DateTime.fromMillis(h.timestamp / 1000000).toLocaleString( + DateTime.TIME_WITH_SECONDS, + )}

    - ) : ( -
    -
    -
    -
    -

    Online

    -
    - )} +

    + {DateTime.fromMillis(h.timestamp / 1000000).toLocaleString( + DateTime.DATE_SHORT, + )} +

    +
    +
    +
    +                  {h.command}
    +                
    +

    + {h.user} + +  on  + + {h.host} + +  in  + + {h.cwd} +

    +
    -
    -
  • - ))} -
+
+
+

{h.exit}

+ {h.duration ? ( +

+ +

+ ) : ( +
+ )} +
+
+ + ); + })} +
); } diff --git a/ui/src/components/HistorySearch.tsx b/ui/src/components/HistorySearch.tsx index 08bed2a8..b3c8492a 100644 --- a/ui/src/components/HistorySearch.tsx +++ b/ui/src/components/HistorySearch.tsx @@ -3,12 +3,12 @@ import { ArrowPathIcon } from "@heroicons/react/24/outline"; import { MagnifyingGlassIcon } from "@heroicons/react/20/solid"; interface HistorySearchProps { - refresh: (query: string) => void; + query: string; + refresh: () => void; + setQuery: (query: string) => void; } export default function HistorySearch(props: HistorySearchProps) { - let [searchQuery, setSearchQuery] = useState(""); - return (
{ - setSearchQuery(query.target.value); - props.refresh(query.target.value); + props.setQuery(query.target.value); + props.refresh(); }} />
@@ -45,7 +45,7 @@ export default function HistorySearch(props: HistorySearchProps) { type="button" className="-m-2.5 p-2.5 text-gray-400 hover:text-gray-500" onClick={() => { - props.refresh(searchQuery); + props.refresh(); }} >