Add option to change volume

This commit is contained in:
Emilia Allison 2023-06-07 17:08:43 -04:00
parent 85670fe86e
commit afc06d7dd5
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
5 changed files with 37 additions and 3 deletions

View File

@ -58,4 +58,7 @@ input {
&[type="number"] {
width: 2em;
}
&.volume_input {
width: 4em;
}
}

View File

@ -9,11 +9,13 @@ use crate::data::transfer::Transfer;
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Store)]
#[store(storage = "session")]
#[non_exhaustive]
pub struct CurrentTransfer {
pub transfer: Transfer,
}
#[derive(Default, PartialEq, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MainState {
pub source_plates: Vec<PlateInstance>,
pub destination_plates: Vec<PlateInstance>,

View File

@ -134,6 +134,20 @@ pub fn TransferMenu() -> Html {
})
};
let on_volume_change = {
let ct_dispatch = ct_dispatch.clone();
Callback::from(move |e: Event| {
let input = e.target().expect("Event must have target")
.dyn_into::<HtmlInputElement>().ok().expect("Must have been emitted by input");
if let Ok(num) = input.value().parse::<f32>() {
ct_dispatch.reduce_mut(|state| {
state.transfer.volume = num;
});
}
})
};
let new_transfer_button_callback = {
let main_dispatch = main_dispatch.clone();
let main_state = main_state.clone();
@ -267,6 +281,13 @@ pub fn TransferMenu() -> Html {
onchange={on_dest_interleave_y_change}
value={ct_state.transfer.transfer_region.interleave_dest.1.to_string()}/>
</div>
<div>
<label for="volume"><h3>{"Volume"}</h3></label>
<input type="number" name="volume" class="volume_input"
min="0" step="0.1"
onchange={on_volume_change}
value={ct_state.transfer.volume.to_string()}/>
</div>
<div id="controls">
<input type="button" name="new_transfer" onclick={new_transfer_button_callback}
value={"New"} />

View File

@ -16,9 +16,9 @@ struct TransferRecord {
#[serde(rename = "Destination Well")]
destination_well: String,
#[serde(rename = "Volume")]
volume: f64,
volume: f32,
#[serde(rename = "Concentration")]
concentration: Option<f64>,
concentration: Option<f32>,
}
pub fn state_to_csv(state: &MainState) -> Result<String, Box<dyn Error>> {
@ -62,7 +62,7 @@ fn transfer_to_records(
source_well: format!("{}{}", num_to_letters(s_well.0).unwrap(), s_well.1),
destination_plate: dest_barcode.to_string(),
destination_well: format!("{}{}", num_to_letters(d_well.0).unwrap(), d_well.1),
volume: 2.5, // Default value since not yet implemented
volume: tr.volume,
concentration: None,
})
}

View File

@ -5,12 +5,19 @@ use serde::Serialize;
use uuid::Uuid;
#[derive(PartialEq, Clone, Default, Debug, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Transfer {
pub source_id: Uuid,
pub dest_id: Uuid,
pub name: String,
id: Uuid,
pub transfer_region: TransferRegion,
#[serde(default = "default_volume")]
pub volume: f32,
}
fn default_volume() -> f32 {
2.5f32
}
impl Transfer {
@ -26,6 +33,7 @@ impl Transfer {
name,
id: Uuid::new_v4(),
transfer_region: tr,
volume: 2.5,
}
}