Skip to content

Commit

Permalink
chore: cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Oran-Dan committed Sep 5, 2024
1 parent 4f03400 commit 237fa26
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 31 deletions.
10 changes: 5 additions & 5 deletions src/backend/candidate_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn set_candidate_output_value(state: &mut AppState, push_transformation: boo
set_output_pointer(state);

for transformation in selected_transformations.iter() {
let transformation = define_transformation(state, transformation.clone());
let transformation = define_transformation(state, *transformation);

// todo: Can we we just get the key pointed to instead of copynig the entire repository?
let mut temp_repository = state.repository.clone();
Expand Down Expand Up @@ -51,7 +51,7 @@ pub fn define_transformation(state: &mut AppState, transformation: Transformatio

match transformation {
Transformations::LowerCase => {
return Transformation::OneToOne {
Transformation::OneToOne {
type_: OneToOne::toLowerCase,
source: DataLocation {
format: input_format.clone(),
Expand All @@ -64,7 +64,7 @@ pub fn define_transformation(state: &mut AppState, transformation: Transformatio
}
}
Transformations::UpperCase => {
return Transformation::OneToOne {
Transformation::OneToOne {
type_: OneToOne::toUpperCase,
source: DataLocation {
format: input_format.clone(),
Expand All @@ -79,7 +79,7 @@ pub fn define_transformation(state: &mut AppState, transformation: Transformatio
// todo: This clippy warning is known, this body is for 'DirectCopy' and all others until they
// get their own branches
Transformations::DirectCopy | _ => {
return Transformation::OneToOne {
Transformation::OneToOne {
type_: OneToOne::copy,
source: DataLocation {
format: input_format.clone(),
Expand All @@ -91,7 +91,7 @@ pub fn define_transformation(state: &mut AppState, transformation: Transformatio
},
}
}
};
}
}

pub fn set_output_pointer(state: &mut AppState) {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod candidate_value;
pub mod desm_mapping;
pub mod headless_cli;
pub mod jsonpointer;
Expand All @@ -6,5 +7,4 @@ pub mod logging;
pub mod preload_p2;
pub mod repository;
pub mod resolve;
pub mod candidate_value;
pub mod transformations;
2 changes: 1 addition & 1 deletion src/backend/preload_p2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub fn preload_p2(state: &mut AppState) {

trace_dbg!("Successfully loaded the mapping file");

// trace_dbg!(&state.repository);
state.repository.apply_transformations(transformations, state.mapping);
// todo: add applied transformation to completed fields
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn value_to_str(value: &Value) -> String {
} else {
let mut str_ = "[".to_string();
for e in a {
str_ = str_ + value_to_str(e).as_str() + ", "; //again we don't how many levels nested array/objects
str_ = str_ + value_to_str(e).as_str() + ", ";
}
str_.truncate(str_.len() - 2);
str_ += "]";
Expand Down
29 changes: 12 additions & 17 deletions src/events/p2_p3_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ pub fn handle_up(state: &mut AppState) {
}
// Scroll up through output fields
P2P3Tabs::OutputFields => {
if state.page == Pages::RequiredDataP2 && state.selected_output_field > 1 {
state.selected_output_field -= 1;
} else if state.selected_output_field > 1 {
if state.selected_output_field > 1 {
state.selected_output_field -= 1;
}
}
Expand All @@ -125,9 +123,7 @@ pub fn handle_down(state: &mut AppState) {
}
}
P2P3Tabs::OutputFields => {
if state.page == Pages::RequiredDataP2 && state.selected_output_field <= state.amount_output_fields {
state.selected_output_field += 1;
} else if state.selected_output_field <= state.amount_output_fields {
if state.selected_output_field <= state.amount_output_fields {
state.selected_output_field += 1;
}
}
Expand Down Expand Up @@ -219,7 +215,7 @@ pub fn handle_enter(state: &mut AppState) -> bool {
// Fast-track mapping, Copy to output result value and reset values
if state.mapping_option == MappingOptions::DirectCopy {
// "Your input >>" needs to be selected to perform the mapping
if state.output_display_subset[1].0 == "Your input >>".to_string()
if state.output_display_subset[1].0 == *"Your input >>"
&& state.selected_output_field == 1
{
confirm_mapping(state);
Expand All @@ -242,7 +238,7 @@ pub fn handle_enter(state: &mut AppState) -> bool {
if !state.popup_mapping_p2_p3 {
set_candidate_output_value(state, false);
state.popup_mapping_p2_p3 = true;
} else if state.output_display_subset[1].0 == "Your input >>".to_string()
} else if state.output_display_subset[1].0 == *"Your input >>"
&& state.selected_output_field == 1
{
confirm_mapping(state);
Expand All @@ -256,7 +252,7 @@ pub fn handle_enter(state: &mut AppState) -> bool {
if !state.popup_mapping_p2_p3 {
set_candidate_output_value(state, false);
state.popup_mapping_p2_p3 = true;
} else if state.output_display_subset[1].0 == "Your input >>".to_string()
} else if state.output_display_subset[1].0 == *"Your input >>"
&& state.selected_output_field == 1
{
confirm_mapping(state);
Expand All @@ -266,7 +262,7 @@ pub fn handle_enter(state: &mut AppState) -> bool {
// Complete a mapping from the view popup
if state.popup_mapping_p2_p3 {
// "Your input >>" needs to be selected to perform the mapping
if state.output_display_subset[1].0 == "Your input >>".to_string()
if state.output_display_subset[1].0 == *"Your input >>"
&& state.selected_output_field == 1
{
confirm_mapping(state);
Expand Down Expand Up @@ -353,8 +349,7 @@ pub fn handle_scroll_up(state: &mut AppState, mouse_event: MouseEvent) {
pub fn handle_mouse_up(state: &mut AppState, mouse_event: MouseEvent) {
if is_mouse_over_area(state.complete_button, mouse_event.column, mouse_event.row) {
if state.output_display_subset.len() - 1 == state.completed_required_fields.len() {
// todo: refactor if statement
// todo: len() fetch incorrectly in multiple locations
// todo: refactor completed fields checking for p2
next_page(state);
} else if state.page == Pages::OptionalDataP3 {
next_page(state);
Expand All @@ -369,7 +364,7 @@ pub fn handle_mouse_up(state: &mut AppState, mouse_event: MouseEvent) {
clear_button(state);
} else if is_mouse_over_area(state.confirm_button, mouse_event.column, mouse_event.row) {
// "Your input >>" needs to be selected to perform the mapping
if state.output_display_subset[1].0 == "Your input >>".to_string() && state.selected_output_field == 1 {
if state.output_display_subset[1].0 == *"Your input >>" && state.selected_output_field == 1 {
confirm_mapping(state);
}
} else if is_mouse_over_area(state.prev_page_button, mouse_event.column, mouse_event.row) {
Expand Down Expand Up @@ -463,11 +458,11 @@ pub fn clear_button(state: &mut AppState) {
// todo: bandaid code, not fully implemented yet
else {
if state.page == Pages::RequiredDataP2 {
if let Some(_) = state
if state
.resolved_subsets
.get(&state.missing_field_pointer)
.unwrap()
.get("Your input >>")
.get("Your input >>").is_some()
{
*state
.resolved_subsets
Expand All @@ -480,11 +475,11 @@ pub fn clear_button(state: &mut AppState) {
.completed_required_fields
.retain(|(first, _)| first != &state.missing_field_pointer);
} else {
if let Some(_) = state
if state
.resolved_subsets
.get(&state.optional_field_pointer)
.unwrap()
.get("Your input >>")
.get("Your input >>").is_some()
{
*state
.resolved_subsets
Expand Down
4 changes: 2 additions & 2 deletions src/render/p2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ pub fn render_required_data_p2(area: Rect, buf: &mut Buffer, state: &mut AppStat
.map(|(key, value)| {
let mut row = Row::new(vec![key.deref(), value.deref()]);
if state.completed_required_fields.iter().any(|(first, _)| {
first.to_string() == state.missing_field_pointer
|| first.to_string() == state.missing_field_pointer.as_str().to_owned() + "/" + key.as_str()
*first == state.missing_field_pointer
|| *first == state.missing_field_pointer.as_str().to_owned() + "/" + key.as_str()
})
// this checks wether to pointer (equal to the breadcrumb in the CLI) has already been entered as completed, or that any in the fields under the current pointer have been completed
{
Expand Down
4 changes: 2 additions & 2 deletions src/render/p3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ pub fn render_optional_data_p3(area: Rect, buf: &mut Buffer, state: &mut AppStat
.map(|(key, value)| {
let mut row = Row::new(vec![key.deref(), value.deref()]);
if state.completed_optional_fields.iter().any(|(first, _)| {
first.to_string() == state.optional_field_pointer
|| first.to_string() == state.optional_field_pointer.as_str().to_owned() + "/" + key.as_str()
*first == state.optional_field_pointer
|| *first == state.optional_field_pointer.as_str().to_owned() + "/" + key.as_str()
})
// this checks wether to pointer (equal to the breadcrumb in the CLI) has already been entered as completed, or that any in the fields under the current pointer have been completed
{
Expand Down
4 changes: 2 additions & 2 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ pub struct AppState {
pub selected_output_field: usize,
pub amount_output_fields: usize,
pub output_pointer: String,

pub missing_field_pointer: String,
pub optional_field_pointer: String,
pub completed_required_fields: Vec<(String, String)>, // (required_field_path, input_field_path)
pub completed_optional_fields: Vec<(String, String)>, // (optional_field_path, input_field_path)

// Backend
pub target_schema: Value,
pub resolved_subsets: HashMap<String, Value>, // <JsonPointer, Value> JsonPointers is unnecessary complexity for now.
Expand Down

0 comments on commit 237fa26

Please sign in to comment.