Files
ARCADIA-Studio/crates/oa-desktop/src/semantic_review/artifacts_view.rs
T

148 lines
6.3 KiB
Rust

use super::artifacts::{Editor, Event, Raw};
use super::*;
use iced::{
Element as View, Fill,
widget::{button, checkbox, column, pick_list, row, text, text_editor, text_input},
};
pub(super) fn pairs<'a>(editor: &'a Editor, p: &'a Project, trace: &'a Trace) -> View<'a, Event> {
let mut content=column![text("Artifact links and metadata").size(16),text("Pair links attached to these reviewed owners. Presence is attachment to the owner; taking identified source absence deletes the destination link, while a destination-only link is retained.").size(12),text_input("Filter artifact identities",&editor.search).on_input(Event::Search).padding(7)].spacing(9);
for (layer, label, selected) in [
(Layer::Oa, "Operational", editor.oa.clone()),
(Layer::Sa, "System", editor.sa.clone()),
] {
content = content.push(text(label).size(12)).push(
row![
pick_list(editor.choices(p, trace, layer), selected, move |v| {
Event::Pick(layer, Some(v))
})
.placeholder("Choose exact artifact identity")
.width(Fill)
.padding(7),
button("No identity")
.padding(7)
.on_press(Event::Pick(layer, None))
]
.spacing(7),
);
}
content.push(row![button("Reserve a new destination counterpart").padding(7).on_press(Event::Reserve),button("Review this exact artifact pair").padding(7).on_press(Event::Stage)].spacing(7).wrap()).push(text("Reservation retains a fresh identity and seeds metadata from the source. It creates nothing until Presence and all seven metadata facets are explicitly reviewed and the combined Apply succeeds. New unrelated links use ordinary artifact creation.").size(11)).padding(iced::Padding::default().right(18)).into()
}
pub(super) fn candidate<'a>(
editor: &'a Editor,
p: &'a Project,
facet: &'a FacetSelector,
) -> Option<View<'a, Event>> {
let value = editor.drafts.get(facet)?;
let (_, which) = artifacts::parts(facet)?;
let mut content =
column![text(format!("Final artifact {}", artifacts::field(which)?)).size(12)].spacing(7);
match value {
Raw::Text(_) if which == ArtifactFacet::Description => {
let draft = editor.descriptions.get(facet)?;
let facet = facet.clone();
content = content.push(
text_editor(draft)
.height(110)
.on_action(move |action| Event::Description(facet.clone(), action)),
);
}
Raw::Text(value) => {
let facet = facet.clone();
content = content.push(
text_input("Exact text", value)
.on_input(move |value| Event::Input(facet.clone(), Raw::Text(value)))
.padding(7),
);
}
Raw::Owner(value) => {
let mut choices: Vec<_> = p
.identities()
.into_iter()
.map(|(id, alias)| Choice {
id,
label: format!("{} · @{alias}", p.named(id)),
})
.collect();
choices.sort_by_cached_key(|c| c.label.to_lowercase());
let selected = value.parse::<Id>().ok().map(|id| view::choice(p, id));
let raw_facet = facet.clone();
let pick_facet = facet.clone();
content = content
.push(
pick_list(choices, selected, move |v: Choice| {
Event::Input(pick_facet.clone(), Raw::Owner(v.id.to_string()))
})
.placeholder("Explicit final owner")
.width(Fill)
.padding(7),
)
.push(
text_input("Owner identity (retains rejected input)", value)
.on_input(move |v| Event::Input(raw_facet.clone(), Raw::Owner(v)))
.padding(7),
);
}
Raw::Relation(value) => {
let facet = facet.clone();
let variants = [
ArtifactRelation::References,
ArtifactRelation::Satisfies,
ArtifactRelation::Verifies,
ArtifactRelation::Implements,
ArtifactRelation::DerivedFrom,
];
let choices: Vec<_> = variants.into_iter().map(RelationChoice).collect();
content = content.push(
pick_list(choices, Some(RelationChoice(*value)), move |v| {
Event::Input(facet.clone(), Raw::Relation(v.0))
})
.padding(7),
);
}
Raw::Optional {
present,
text: value,
} => {
let toggle_facet = facet.clone();
let retained = value.clone();
let input_facet = facet.clone();
let enabled = *present;
content = content
.push(
checkbox(*present)
.label("Present (checked with empty text means an explicit empty value)")
.on_toggle(move |present| {
Event::Input(
toggle_facet.clone(),
Raw::Optional {
present,
text: retained.clone(),
},
)
}),
)
.push(
text_input("Retained optional text", value)
.on_input(move |text| {
Event::Input(
input_facet.clone(),
Raw::Optional {
present: enabled,
text,
},
)
})
.padding(7),
);
}
}
Some(content.into())
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
struct RelationChoice(ArtifactRelation);
impl std::fmt::Display for RelationChoice {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.0)
}
}