Review nested message kind groups with exact timer scope
This commit is contained in:
@@ -46,6 +46,7 @@ pub struct Draft {
|
||||
pub inputs: BTreeMap<String, Input>,
|
||||
pub exact_strings: bool,
|
||||
context: Option<Value>,
|
||||
message_timer_draft: Option<Input>,
|
||||
port_contract_drafts: BTreeMap<String, Value>,
|
||||
pub value_browsers: BTreeMap<String, ValueBrowser>,
|
||||
}
|
||||
@@ -85,6 +86,7 @@ impl Draft {
|
||||
inputs: BTreeMap::new(),
|
||||
exact_strings: false,
|
||||
context: None,
|
||||
message_timer_draft: None,
|
||||
port_contract_drafts: BTreeMap::new(),
|
||||
value_browsers: BTreeMap::new(),
|
||||
};
|
||||
@@ -248,6 +250,29 @@ impl Draft {
|
||||
self.rebuild_retaining(|old| (!within(old, path)).then(|| old.to_owned()));
|
||||
Ok(())
|
||||
}
|
||||
/// Message-kind selection preserves the timer's exact input/editor state
|
||||
/// while its payload is temporarily hidden by another kind.
|
||||
pub fn message_kind_variant(&mut self, path: &str, value: Value) -> Result<(), String> {
|
||||
serde_json::from_value::<MessageKind>(value.clone()).map_err(|e| e.to_string())?;
|
||||
let current = self
|
||||
.value
|
||||
.pointer(path)
|
||||
.ok_or("Message kind no longer exists.")?;
|
||||
if same_variant(current, &value) {
|
||||
return Ok(());
|
||||
}
|
||||
let timer_path = format!("{path}/Timer/expression");
|
||||
if let Some(input) = self.inputs.remove(&timer_path) {
|
||||
self.message_timer_draft = Some(input);
|
||||
}
|
||||
self.shape_scoped(path, value)?;
|
||||
if self.inputs.contains_key(&timer_path)
|
||||
&& let Some(input) = self.message_timer_draft.take()
|
||||
{
|
||||
self.inputs.insert(timer_path, input);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn rebuild_retaining(&mut self, new_path: impl Fn(&str) -> Option<String>) {
|
||||
let previous = std::mem::take(&mut self.inputs);
|
||||
self.rebuild();
|
||||
|
||||
Reference in New Issue
Block a user