use crate::components::{select::*, skeleton::*};
use crate::loader::Loader;
use csv::{ReaderBuilder, StringRecord};
use dioxus::prelude::*;
use dioxus_primitives::toast::{use_toast, ToastOptions};
use dioxus_sdk_time::*;
use std::collections::HashMap;
use std::f32::consts::PI;
use std::fmt;
use std::str::FromStr;
use std::time::Duration;
use strum::{EnumCount, IntoEnumIterator};
const PAGE_SIZE: usize = 100_usize;
// Wrapper for displaying a duration in h:m:s (integer seconds, rounded down)
struct HMSDuration(Duration);
impl fmt::Display for HMSDuration {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut ms = self.0.as_millis();
let hours = ms / 3_600_000;
ms %= 3_600_000;
let mins = ms / 60_000;
ms %= 60_000;
let secs = ms / 1000;
ms %= 1000;
if hours > 0 {
write!(f, "{}:{:02}:{:02}.{}", hours, mins, secs, ms)
} else if mins > 0 {
write!(f, "0:{}:{:02}.{}", mins, secs, ms)
} else {
write!(f, "0:0:{}.{}", secs, ms)
}
}
}
#[derive(
Debug,
Eq,
Hash,
Clone,
Copy,
PartialEq,
strum::EnumCount,
strum::EnumIter,
strum::Display,
strum::EnumString,
)]
enum TestStatus {
Pass,
Fail,
Warn,
Skip,
Crash,
Timeout,
}
impl TestStatus {
const fn emoji(&self) -> &'static str {
match self {
TestStatus::Pass => "✅",
TestStatus::Fail => "❌",
TestStatus::Skip => "❎",
TestStatus::Timeout => "⏱️",
TestStatus::Warn => "⚠️",
TestStatus::Crash => "💥",
}
}
const fn color(&self) -> &'static str {
match self {
TestStatus::Pass => "#22c55e",
TestStatus::Fail => "#ff6467",
TestStatus::Skip => "#38bdf8",
TestStatus::Timeout => "#F77600",
TestStatus::Warn => "#ffdf20",
TestStatus::Crash => "#e7000b",
}
}
}
fn percentage(count: usize, total: f32) -> f32 {
(count as f32 * 100.0) / total
}
#[component]
fn LandingPlaceholder() -> Element {
let stats_cards = TestStatus::iter().map(|s| {
rsx! {
StatCardPlaceholder {
name: s.to_string(),
color: s.color().to_string(),
count: 0,
stat: 0.0_f32,
}
}
});
let statuses = TestStatus::iter().enumerate().map(|(i, s)| {
rsx! {
SelectOption::