fix generator option reordering bug
This commit is contained in:
parent
f924332491
commit
cfbd5185cb
@ -1,9 +1,8 @@
|
|||||||
use gloo::console::{console, console_dbg};
|
|
||||||
use gloo::file::callbacks::FileReader;
|
use gloo::file::callbacks::FileReader;
|
||||||
use gloo::file::File;
|
use gloo::file::File;
|
||||||
use gloo::storage::{LocalStorage, Storage};
|
use gloo::storage::{LocalStorage, Storage};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::{self, HashMap};
|
use std::collections::HashMap;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use web_sys::{DragEvent, Event, FileList, HtmlInputElement, MouseEvent};
|
use web_sys::{DragEvent, Event, FileList, HtmlInputElement, MouseEvent};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::HashMap, str::FromStr};
|
use std::str::FromStr;
|
||||||
|
|
||||||
use web_sys::{Event, HtmlInputElement};
|
use web_sys::{Event, HtmlInputElement};
|
||||||
use yew::{html, AttrValue, Callback, Html, TargetCast};
|
use yew::{html, AttrValue, Callback, Html, TargetCast};
|
||||||
@ -12,9 +12,9 @@ use crate::{
|
|||||||
|
|
||||||
fn show_dropdown_picker(selected: &str, options: &[AttrValue], onchange: Callback<String>) -> Html {
|
fn show_dropdown_picker(selected: &str, options: &[AttrValue], onchange: Callback<String>) -> Html {
|
||||||
html! {
|
html! {
|
||||||
<select onchange={Callback::from(move |e: Event| {
|
<select onchange={onchange.reform(move |e: Event| {
|
||||||
let value = e.target_unchecked_into::<HtmlInputElement>().value();
|
let value = e.target_unchecked_into::<HtmlInputElement>().value();
|
||||||
onchange.emit(value);
|
value
|
||||||
})}>
|
})}>
|
||||||
{
|
{
|
||||||
options.iter().map(|value| {
|
options.iter().map(|value| {
|
||||||
@ -25,12 +25,12 @@ fn show_dropdown_picker(selected: &str, options: &[AttrValue], onchange: Callbac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_enum_dropdown<T: PartialEq + Clone + 'static>(
|
fn show_enum_dropdown< T: PartialEq + Clone + 'static>(
|
||||||
selected: &T,
|
selected: &T,
|
||||||
options: HashMap<AttrValue, T>,
|
options: &Vec<(AttrValue, T)>,
|
||||||
onchange: Callback<T>,
|
onchange: Callback<T>,
|
||||||
) -> Html {
|
) -> Html {
|
||||||
let keys = options.keys().map(AttrValue::clone).collect::<Vec<_>>();
|
let keys = options.iter().map(|(opt, _)| opt.clone()).collect::<Vec<_>>();
|
||||||
let guess_str = options
|
let guess_str = options
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, v)| v.eq(&selected))
|
.find(|(_, v)| v.eq(&selected))
|
||||||
@ -38,10 +38,17 @@ fn show_enum_dropdown<T: PartialEq + Clone + 'static>(
|
|||||||
.0
|
.0
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
|
let options = options.clone();
|
||||||
show_dropdown_picker(
|
show_dropdown_picker(
|
||||||
&guess_str,
|
&guess_str,
|
||||||
&keys,
|
&keys,
|
||||||
onchange.reform(move |value_str: String| options.get(value_str.as_str()).unwrap().clone()),
|
onchange.reform(move |value_str: String| {
|
||||||
|
let enum_value = &options.iter()
|
||||||
|
.find(|(v, _)| v.eq(&value_str))
|
||||||
|
.unwrap()
|
||||||
|
.1;
|
||||||
|
enum_value.clone()
|
||||||
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,54 +138,54 @@ pub fn generator_picker(
|
|||||||
onchange.reform(|(min, max)| SQLValueGuess::Float(min, max)),
|
onchange.reform(|(min, max)| SQLValueGuess::Float(min, max)),
|
||||||
),
|
),
|
||||||
SQLValueGuess::Date(guess) => {
|
SQLValueGuess::Date(guess) => {
|
||||||
let options = HashMap::from([
|
let options = vec![
|
||||||
("Now".into(), SQLTimeValueGuess::Now),
|
("Now".into(), SQLTimeValueGuess::Now),
|
||||||
("Future".into(), SQLTimeValueGuess::Future),
|
("Future".into(), SQLTimeValueGuess::Future),
|
||||||
("Past".into(), SQLTimeValueGuess::Past),
|
("Past".into(), SQLTimeValueGuess::Past),
|
||||||
]);
|
];
|
||||||
|
|
||||||
show_enum_dropdown(
|
show_enum_dropdown(
|
||||||
guess,
|
guess,
|
||||||
options,
|
&options,
|
||||||
onchange.reform(|enum_value| SQLValueGuess::Date(enum_value)),
|
onchange.reform(|enum_value| SQLValueGuess::Date(enum_value)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
SQLValueGuess::Time(guess) => {
|
SQLValueGuess::Time(guess) => {
|
||||||
let options = HashMap::from([
|
let options = vec![
|
||||||
("Now".into(), SQLTimeValueGuess::Now),
|
("Now".into(), SQLTimeValueGuess::Now),
|
||||||
("Future".into(), SQLTimeValueGuess::Future),
|
("Future".into(), SQLTimeValueGuess::Future),
|
||||||
("Past".into(), SQLTimeValueGuess::Past),
|
("Past".into(), SQLTimeValueGuess::Past),
|
||||||
]);
|
];
|
||||||
|
|
||||||
show_enum_dropdown(
|
show_enum_dropdown(
|
||||||
guess,
|
guess,
|
||||||
options,
|
&options,
|
||||||
onchange.reform(|enum_value| SQLValueGuess::Time(enum_value)),
|
onchange.reform(|enum_value| SQLValueGuess::Time(enum_value)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
SQLValueGuess::Datetime(guess) => {
|
SQLValueGuess::Datetime(guess) => {
|
||||||
let options = HashMap::from([
|
let options = vec![
|
||||||
("Now".into(), SQLTimeValueGuess::Now),
|
("Now".into(), SQLTimeValueGuess::Now),
|
||||||
("Future".into(), SQLTimeValueGuess::Future),
|
("Future".into(), SQLTimeValueGuess::Future),
|
||||||
("Past".into(), SQLTimeValueGuess::Past),
|
("Past".into(), SQLTimeValueGuess::Past),
|
||||||
]);
|
];
|
||||||
|
|
||||||
show_enum_dropdown(
|
show_enum_dropdown(
|
||||||
guess,
|
guess,
|
||||||
options,
|
&options,
|
||||||
onchange.reform(|enum_value| SQLValueGuess::Datetime(enum_value)),
|
onchange.reform(|enum_value| SQLValueGuess::Datetime(enum_value)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
SQLValueGuess::Bool(guess) => {
|
SQLValueGuess::Bool(guess) => {
|
||||||
let options = HashMap::from([
|
let options = vec![
|
||||||
("Random".into(), SQLBoolValueGuess::Random),
|
("Random".into(), SQLBoolValueGuess::Random),
|
||||||
("True".into(), SQLBoolValueGuess::True),
|
("True".into(), SQLBoolValueGuess::True),
|
||||||
("False".into(), SQLBoolValueGuess::False),
|
("False".into(), SQLBoolValueGuess::False),
|
||||||
]);
|
];
|
||||||
|
|
||||||
show_enum_dropdown(
|
show_enum_dropdown(
|
||||||
guess,
|
guess,
|
||||||
options,
|
&options,
|
||||||
onchange.reform(|enum_value| SQLValueGuess::Bool(enum_value)),
|
onchange.reform(|enum_value| SQLValueGuess::Bool(enum_value)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -189,23 +196,23 @@ pub fn generator_picker(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let options = HashMap::from([
|
let options = vec![
|
||||||
("Lorem Ipsum".into(), SQLStringValueGuess::LoremIpsum),
|
("Lorem Ipsum".into(), SQLStringValueGuess::LoremIpsum),
|
||||||
|
("Empty".into(), SQLStringValueGuess::Empty),
|
||||||
("First Name".into(), SQLStringValueGuess::FirstName),
|
("First Name".into(), SQLStringValueGuess::FirstName),
|
||||||
("Last Name".into(), SQLStringValueGuess::LastName),
|
("Last Name".into(), SQLStringValueGuess::LastName),
|
||||||
("Full Name".into(), SQLStringValueGuess::FullName),
|
("Full Name".into(), SQLStringValueGuess::FullName),
|
||||||
("Empty".into(), SQLStringValueGuess::Empty),
|
|
||||||
("Phone number".into(), SQLStringValueGuess::PhoneNumber),
|
("Phone number".into(), SQLStringValueGuess::PhoneNumber),
|
||||||
("City name".into(), SQLStringValueGuess::CityName),
|
("City name".into(), SQLStringValueGuess::CityName),
|
||||||
("Address".into(), SQLStringValueGuess::Address),
|
("Address".into(), SQLStringValueGuess::Address),
|
||||||
("Email".into(), SQLStringValueGuess::Email),
|
("Email".into(), SQLStringValueGuess::Email),
|
||||||
("URL".into(), SQLStringValueGuess::URL),
|
("URL".into(), SQLStringValueGuess::URL),
|
||||||
]);
|
];
|
||||||
|
|
||||||
let max_size = *max_size;
|
let max_size = *max_size;
|
||||||
show_enum_dropdown(
|
show_enum_dropdown(
|
||||||
guess,
|
guess,
|
||||||
options,
|
&options,
|
||||||
onchange.reform(move |enum_value| SQLValueGuess::String(max_size, enum_value)),
|
onchange.reform(move |enum_value| SQLValueGuess::String(max_size, enum_value)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ use fake::{
|
|||||||
},
|
},
|
||||||
Fake,
|
Fake,
|
||||||
};
|
};
|
||||||
use gloo::console::console_dbg;
|
|
||||||
use rand::{rngs::ThreadRng, seq::SliceRandom, Rng};
|
use rand::{rngs::ThreadRng, seq::SliceRandom, Rng};
|
||||||
|
|
||||||
use crate::magicdraw_parser::{SQLCheckConstraint, SQLColumn, SQLTable, SQLType};
|
use crate::magicdraw_parser::{SQLCheckConstraint, SQLColumn, SQLTable, SQLType};
|
||||||
|
Loading…
Reference in New Issue
Block a user