Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Add popups displaying specific alerts
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Pashev <pashev.igor@gmail.com>
  • Loading branch information
ip1981 committed Apr 14, 2020
1 parent 7caf1c8 commit 46a90c6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
57 changes: 38 additions & 19 deletions iml-gui/crate/src/components/alert_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
// license that can be found in the LICENSE file.

use crate::{
components::{attrs, font_awesome_outline, tooltip, Placement},
components::{attrs, font_awesome_outline, popover, tooltip, Placement},
generated::css_classes::C,
};
use im::HashMap;
use iml_wire_types::{warp_drive::ArcValuesExt, Alert, AlertSeverity, ToCompositeId};
use seed::{prelude::*, *};
use std::{cmp::max, collections::BTreeSet, iter::FromIterator, sync::Arc};
use std::{collections::BTreeSet, iter::FromIterator, sync::Arc};

pub(crate) fn alert_indicator<T>(
alerts: &HashMap<u32, Arc<Alert>>,
all_alerts: &HashMap<u32, Arc<Alert>>,
x: &dyn ToCompositeId,
compact: bool,
tt_placement: Placement,
) -> Node<T> {
let composite_id = x.composite_id();

let alerts: Vec<&Alert> = alerts
let mut alerts = all_alerts
.arc_values()
.filter_map(|x| {
let xs = x.affected_composite_ids.as_ref()?;
Expand All @@ -28,24 +28,16 @@ pub(crate) fn alert_indicator<T>(

Some(x)
})
.collect();
.collect::<Vec<_>>();

if compact && alerts.is_empty() {
return empty![];
}

let count = alerts.len();

let msg = if count == 0 {
"No Alerts".into()
} else if count == 1 {
alerts[0].message.clone()
} else {
format!("{} Alerts", alerts.len())
};

let health = alerts.into_iter().map(|x| x.severity).fold(AlertSeverity::INFO, max);
// Put the most severe alerts first:
alerts.sort_unstable_by(|a, b| b.severity.cmp(&a.severity));

let health = alerts.get(0).map(|a| a.severity).unwrap_or(AlertSeverity::INFO);
let cls = if health == AlertSeverity::INFO {
C.text_blue_500
} else if health == AlertSeverity::WARNING {
Expand All @@ -56,13 +48,40 @@ pub(crate) fn alert_indicator<T>(

let icon = font_awesome_outline(class![cls, C.inline, C.h_4, C.w_4], "bell");

if compact {
let count = alerts.len();

let txt = if count == 0 {
"No Alerts".into()
} else if count == 1 {
alerts[0].message.clone()
} else {
format!("{} Alerts", alerts.len())
};

let mut el = if compact {
span![
class![C.inline_block],
span![attrs::container(), icon, tooltip::view(&msg, tt_placement)],
attrs::container(),
icon,
tooltip::view(&txt, tt_placement),
sup![class![cls], count.to_string()]
]
} else {
span![icon, span![class![C.ml_1], &msg]]
span![icon, attrs::container(), span![class![C.ml_1], &txt]]
};

if count > 1 {
let pop = popover::view(
popover::content_view(ul![
class![C.list_disc, C.px_4, C.whitespace_no_wrap, C.text_left],
alerts.iter().map(|a| li![a.message.clone()]).collect::<Vec<_>>()
]),
Placement::Bottom,
);
el.add_child(pop)
.add_class(C.cursor_pointer)
.add_attr(At::TabIndex.as_str(), 0);
}

el
}
5 changes: 4 additions & 1 deletion iml-gui/crate/src/components/lock_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@ fn indicator<T>(lcks: &HashSet<LockChange>) -> Node<T> {
fn mk_lock_list<T>(locks: &HashSet<&LockChange>) -> Node<T> {
let mut items: Vec<&String> = locks.iter().map(|x| &x.description).collect();
items.sort_unstable();
ul![class![C.list_disc, C.px_4], items.iter().map(|x| li![x])]
ul![
class![C.list_disc, C.px_4, C.whitespace_no_wrap, C.text_left],
items.iter().map(|x| li![x])
]
}
2 changes: 1 addition & 1 deletion iml-gui/crate/src/components/popover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn title_view<T>(content: &str) -> Node<T> {
}

pub fn content_view<T>(content: impl View<T>) -> Node<T> {
div![class![C.py_2, C.px_3, C.w_64, C.text_sm], content.els()]
div![class![C.py_2, C.px_3, C.text_sm], content.els()]
}

pub fn view<T>(content: impl View<T>, placement: Placement) -> Node<T> {
Expand Down

0 comments on commit 46a90c6

Please sign in to comment.