Skip to content

Commit 4b34963

Browse files
committed
PlannerGUI - Refresh the issues list on certain interactions.
1 parent 79ff9ff commit 4b34963

1 file changed

Lines changed: 64 additions & 19 deletions

File tree

  • crates/planner_gui_egui/src/project

crates/planner_gui_egui/src/project/mod.rs

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,14 @@ impl Project {
10371037
(tasks, update_placement_actions)
10381038
}
10391039

1040-
fn handle_update_placement_actions(tasks: &mut Vec<Task<ProjectAction>>, actions: Vec<UpdatePlacementAction>) {
1040+
fn handle_update_placement_actions(
1041+
tasks: &mut Vec<Task<ProjectAction>>,
1042+
actions: Vec<UpdatePlacementAction>,
1043+
request_issues_refresh: &mut bool,
1044+
) {
1045+
// Updating placements can create/clear issues.
1046+
*request_issues_refresh = true;
1047+
10411048
for action in actions {
10421049
if let Some(task) = match action {
10431050
UpdatePlacementAction::RefreshPhases => Some(Task::done(ProjectAction::UiCommand(
@@ -1175,7 +1182,9 @@ impl UiComponent for Project {
11751182
) -> Option<Self::UiAction> {
11761183
let (key, command) = command;
11771184

1178-
match command {
1185+
let mut request_issues_refresh = false;
1186+
1187+
let action = match command {
11791188
ProjectUiCommand::None => None,
11801189
ProjectUiCommand::Create => {
11811190
let state = self.project_ui_state.lock().unwrap();
@@ -1484,6 +1493,8 @@ impl UiComponent for Project {
14841493
ProjectView::ProjectReport(report) => {
14851494
info!("report:\n{:?}", report);
14861495

1496+
request_issues_refresh = false;
1497+
14871498
let mut state = self.project_ui_state.lock().unwrap();
14881499

14891500
state.issues_ui.update_report(report)
@@ -1621,6 +1632,9 @@ impl UiComponent for Project {
16211632

16221633
let mut tasks = vec![];
16231634

1635+
// Adding PCBs can clear issues.
1636+
request_issues_refresh = true;
1637+
16241638
match self
16251639
.planner_core_service
16261640
.update(Event::AddPcb {
@@ -1663,6 +1677,9 @@ impl UiComponent for Project {
16631677
.into_actions()
16641678
{
16651679
Ok(actions) => {
1680+
// Adding phases can clear issues.
1681+
request_issues_refresh = true;
1682+
16661683
let mut tasks = actions
16671684
.into_iter()
16681685
.map(Task::done)
@@ -1920,12 +1937,16 @@ impl UiComponent for Project {
19201937
match overview_ui_action {
19211938
None => None,
19221939
Some(OverviewTabUiAction::None) => None,
1923-
Some(OverviewTabUiAction::DeletePhase(reference)) => self
1924-
.planner_core_service
1925-
.update(Event::DeletePhase {
1926-
reference: reference.clone(),
1927-
})
1928-
.when_ok(key, |_| Some(ProjectUiCommand::PhaseDeleted(reference))),
1940+
Some(OverviewTabUiAction::DeletePhase(reference)) => {
1941+
// Deleting phases can create issues (no phases, unassigned placements)
1942+
request_issues_refresh = true;
1943+
1944+
self.planner_core_service
1945+
.update(Event::DeletePhase {
1946+
reference: reference.clone(),
1947+
})
1948+
.when_ok(key, |_| Some(ProjectUiCommand::PhaseDeleted(reference)))
1949+
}
19291950
}
19301951
}
19311952
ProjectUiCommand::PartsTabUiCommand(command) => {
@@ -2068,22 +2089,26 @@ impl UiComponent for Project {
20682089
new_placement,
20692090
old_placement,
20702091
);
2071-
Self::handle_update_placement_actions(&mut tasks, actions);
2092+
Self::handle_update_placement_actions(&mut tasks, actions, &mut request_issues_refresh);
20722093

20732094
Some(ProjectAction::Task(key, Task::batch(tasks)))
20742095
}
20752096
Some(PhaseTabUiAction::AddPartsToLoadout {
20762097
phase,
20772098
manufacturer_pattern,
20782099
mpn_pattern,
2079-
}) => self
2080-
.planner_core_service
2081-
.update(Event::AddPartsToLoadout {
2082-
phase,
2083-
manufacturer: manufacturer_pattern,
2084-
mpn: mpn_pattern,
2085-
})
2086-
.when_ok(key, |_| None),
2100+
}) => {
2101+
// Adding parts to loadouts can clear issues
2102+
request_issues_refresh = true;
2103+
2104+
self.planner_core_service
2105+
.update(Event::AddPartsToLoadout {
2106+
phase,
2107+
manufacturer: manufacturer_pattern,
2108+
mpn: mpn_pattern,
2109+
})
2110+
.when_ok(key, |_| None)
2111+
}
20872112
Some(PhaseTabUiAction::SetPlacementOrderings(args)) => self
20882113
.planner_core_service
20892114
.update(Event::SetPlacementOrdering {
@@ -2280,6 +2305,9 @@ impl UiComponent for Project {
22802305
part,
22812306
feeder,
22822307
}) => {
2308+
// Changing loadouts can create/clear issues.
2309+
request_issues_refresh = true;
2310+
22832311
debug!(
22842312
"update feeder. phase: {:?}, part: {:?}, feeder: {:?}",
22852313
phase, part, feeder
@@ -2318,7 +2346,7 @@ impl UiComponent for Project {
23182346
new_placement,
23192347
old_placement,
23202348
);
2321-
Self::handle_update_placement_actions(&mut tasks, actions);
2349+
Self::handle_update_placement_actions(&mut tasks, actions, &mut request_issues_refresh);
23222350

23232351
Some(ProjectAction::Task(key, Task::batch(tasks)))
23242352
}
@@ -2362,7 +2390,7 @@ impl UiComponent for Project {
23622390

23632391
actions.dedup_by(|a, b| a == b);
23642392

2365-
Self::handle_update_placement_actions(&mut tasks, actions);
2393+
Self::handle_update_placement_actions(&mut tasks, actions, &mut request_issues_refresh);
23662394

23672395
Some(ProjectAction::Task(key, Task::batch(tasks)))
23682396
}
@@ -2419,6 +2447,9 @@ impl UiComponent for Project {
24192447
pcb_index,
24202448
variant_map,
24212449
})) => {
2450+
// Changing assignments can create/clear issues.
2451+
request_issues_refresh = true;
2452+
24222453
let mut events = vec![];
24232454

24242455
for (pcb_unit_index, variant_name) in variant_map.iter().enumerate() {
@@ -2432,6 +2463,8 @@ impl UiComponent for Project {
24322463
});
24332464
}
24342465

2466+
// TODO support un-assigning, no-events are created when the map doesn't contain any entries.
2467+
24352468
let mut tasks = vec![];
24362469
for event in events {
24372470
match self
@@ -2570,7 +2603,19 @@ impl UiComponent for Project {
25702603
}
25712604
Some(ProjectAction::Task(key, Task::batch(tasks)))
25722605
}
2606+
};
2607+
2608+
//
2609+
// Issues refresh
2610+
//
2611+
if request_issues_refresh {
2612+
self.component.send((
2613+
key,
2614+
ProjectUiCommand::RequestProjectView(ProjectViewRequest::ProjectReport),
2615+
))
25732616
}
2617+
2618+
action
25742619
}
25752620
}
25762621

0 commit comments

Comments
 (0)