Skip to content

Commit

Permalink
update the blocker message when entering submit step
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Oct 27, 2023
1 parent a6dbe2e commit 12fdf73
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
8 changes: 5 additions & 3 deletions src/aiidalab_qe/app/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ def confirm(self, _=None):
self.state = self.State.SUCCESS
self.is_confirmed = True

def has_unconfirmed_changes(self):
"""Check if the current step has unconfirmed changes"""
def is_saved(self):
"""Check if the current step is saved.
That all changes are confirmed.
"""
new_parameters = self.get_configuration_parameters()
return new_parameters != self.configuration_parameters
return new_parameters == self.configuration_parameters

@tl.default("state")
def _default_state(self):
Expand Down
52 changes: 23 additions & 29 deletions src/aiidalab_qe/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, qe_auto_setup=True):
)
ipw.dlink(
(self, "_submission_blockers"),
(self.submit_step, "_app_submission_blockers"),
(self.submit_step, "_outside_submission_blockers"),
)

ipw.dlink(
Expand All @@ -73,6 +73,10 @@ def __init__(self, qe_auto_setup=True):
("Status & Results", self.results_step),
]
)
# init the blocker messages
self._submission_blockers = {
i: [] for i in range(len(self._wizard_app_widget.steps))
}
self._wizard_app_widget.observe(self._observe_selected_index, "selected_index")

# Add process selection header
Expand All @@ -99,38 +103,28 @@ def steps(self):
return self._wizard_app_widget.steps

def _observe_selected_index(self, change):
"""Check unconfirmed change in the step when leaving the step."""
"""Check unsaved change in the step when leaving the step."""
with self.submit_step.hold_sync():
if change["old"] is None:
return
# check if the step is confirmed before
# if not, we don't need to check the unconfirmed changes
old_idx_step = self.steps[change["old"]][1]
if not getattr(old_idx_step, "is_confirmed", False):
if change["new"] is None:
return
new_idx = change["new"]
# if entering the submit step, udpate the blocker messages
blockers = self._submission_blockers.copy()
# check if the step is changed
if old_idx_step.has_unconfirmed_changes():
# reset the state of the step
old_idx_step.state = WizardAppWidgetStep.State.CONFIGURED
# update the blocker message, this will trigger the observer
# to update the blocker message of the submit step
blockers[change["old"]] = [
f"There are unconfirmed changes in the Step {change['old']+1}: {self.steps[change['old']][0]}"
]
if new_idx == 2:
# check the structure step is saved
for i in range(2):
# check if the step is saved
if not self.steps[i][1].is_saved():
self.steps[i][1].state = WizardAppWidgetStep.State.CONFIGURED
blockers[i] = [
f"There are unsaved changes in the Step {i+1}: {self.steps[i][0]}"
]
# update the blocker message, this will trigger the observer
# to update the blocker message of the submit step
else:
# remove the blocker message if the step has all changes confirmed
blockers[i] = []
self._submission_blockers = blockers
else:
# remove the blocker message if the step has all changes confirmed
if blockers[change["old"]] != []:
blockers[change["old"]] = []
self._submission_blockers = blockers

def _observe_submission_blockers(self, change):
if change["new"]:
# udpate the blocker message of the submit step
self.submit_step._submission_blockers = list(
self.submit_step._identify_submission_blockers()
)

def _observe_process_selection(self, change):
from aiida.orm.utils.serialize import deserialize_unsafe
Expand Down
7 changes: 4 additions & 3 deletions src/aiidalab_qe/app/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ def confirm(self, _=None):
self.message_area.value = ""
self.is_confirmed = True

def has_unconfirmed_changes(self):
"""Check if the current structure is unconfirmed."""
return self.confirmed_structure != self.structure
def is_saved(self):
"""Check if the current structure is saved.
That all changes are confirmed."""
return self.confirmed_structure == self.structure

def can_reset(self):
return self.confirmed_structure is not None
Expand Down
15 changes: 10 additions & 5 deletions src/aiidalab_qe/app/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SubmitQeAppWorkChainStep(ipw.VBox, WizardAppWidgetStep):
previous_step_state = tl.UseEnum(WizardAppWidgetStep.State)
input_parameters = tl.Dict()
_submission_blockers = tl.List(tl.Unicode())
_app_submission_blockers = tl.Dict()
_outside_submission_blockers = tl.Dict()

def __init__(self, qe_auto_setup=True, **kwargs):
self.message_area = ipw.Output()
Expand Down Expand Up @@ -139,13 +139,15 @@ def __init__(self, qe_auto_setup=True, **kwargs):
]
)

@tl.observe("_app_submission_blockers")
def _observe_app_submission_blockers(self, change):
"""Observe the submission blockers from the app."""
@tl.observe("_outside_submission_blockers")
def _observe_outside_submission_blockers(self, _=None):
"""Observe the submission blockers from the app, and update the
submission blockers of the submit step."""
self._submission_blockers = list(self._identify_submission_blockers())

@tl.observe("_submission_blockers")
def _observe_submission_blockers(self, change):
"""Observe the submission blockers and update the message area."""
if change["new"]:
fmt_list = "\n".join((f"<li>{item}</li>" for item in sorted(change["new"])))
self._submission_blocker_messages.value = f"""
Expand All @@ -156,8 +158,11 @@ def _observe_submission_blockers(self, change):
self._submission_blocker_messages.value = ""

def _identify_submission_blockers(self):
"""Identify the blockers for the submission.
Include the blockers from the app and the blockers from the submit step itself.
"""
# blocker messages from the app
for msgs in self._app_submission_blockers.values():
for msgs in self._outside_submission_blockers.values():
for msg in msgs:
yield msg
# Do not submit while any of the background setup processes are running.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def test_reload_and_reset(submit_app_generator, generate_qeapp_workchain):
assert app.submit_step.resources_config.num_cpus.value == 1


def test_unconfirmed_changes(app_to_submit):
"""Test if the unconfirmed changes are handled correctly"""
def test_unsaved_changes(app_to_submit):
"""Test if the unsaved changes are handled correctly"""
from aiidalab_widgets_base import WizardAppWidgetStep

app = app_to_submit
Expand Down

0 comments on commit 12fdf73

Please sign in to comment.