76 lines
2.9 KiB
Rust
76 lines
2.9 KiB
Rust
//! A target's projects: shown as chips, chosen with a checkbox list.
|
|
|
|
use compliance_core::models::Project;
|
|
use dioxus::prelude::*;
|
|
|
|
use crate::i18n::texts::projects as tx;
|
|
use crate::i18n::use_lang;
|
|
use crate::infrastructure::projects::projects_named;
|
|
|
|
/// The projects a target belongs to, as small chips. Nothing when it
|
|
/// belongs to none (or only to deleted ones).
|
|
#[component]
|
|
pub fn ProjectChips(ids: Vec<String>, projects: Vec<Project>) -> Element {
|
|
let lang = use_lang()();
|
|
let shown = projects_named(&ids, &projects);
|
|
if shown.is_empty() {
|
|
return rsx! {};
|
|
}
|
|
rsx! {
|
|
span { class: "project-chips",
|
|
for p in shown {
|
|
span {
|
|
key: "{p.id}",
|
|
class: "project-chip",
|
|
title: "{tx::kind(p.kind).get(lang)}",
|
|
"{p.name}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Choose a target's projects from the tenant's list.
|
|
#[component]
|
|
pub fn ProjectPicker(projects: Vec<Project>, mut selected: Signal<Vec<String>>) -> Element {
|
|
let lang = use_lang()();
|
|
rsx! {
|
|
fieldset { class: "project-picker",
|
|
legend { {tx::TITLE.get(lang)} }
|
|
if projects.is_empty() {
|
|
p { class: "project-picker-hint", {tx::NONE_YET.get(lang)} }
|
|
} else {
|
|
div { class: "project-picker-list",
|
|
for p in projects {
|
|
{
|
|
let id = p.id.clone();
|
|
let checked = selected.read().contains(&id);
|
|
rsx! {
|
|
label { key: "{p.id}", class: "project-picker-item",
|
|
input {
|
|
r#type: "checkbox",
|
|
checked,
|
|
onchange: move |e| {
|
|
let mut ids = selected.write();
|
|
if e.checked() {
|
|
if !ids.contains(&id) {
|
|
ids.push(id.clone());
|
|
}
|
|
} else {
|
|
ids.retain(|x| x != &id);
|
|
}
|
|
},
|
|
}
|
|
span { class: "project-picker-name", "{p.name}" }
|
|
span { class: "project-picker-kind", {tx::kind(p.kind).get(lang)} }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
p { class: "project-picker-hint", {tx::HINT.get(lang)} }
|
|
}
|
|
}
|
|
}
|
|
}
|