From 5a775ea4fa6f82d495182ec65486f8d33817aba2 Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Sat, 28 Oct 2023 22:33:52 +0000 Subject: [PATCH] Improve the implementation of submission blocker --- src/aiidalab_qe/app/main.py | 27 ++++++++-------------- src/aiidalab_qe/app/submission/__init__.py | 24 +++++-------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/aiidalab_qe/app/main.py b/src/aiidalab_qe/app/main.py index e9b7f67f4..7e95dc128 100644 --- a/src/aiidalab_qe/app/main.py +++ b/src/aiidalab_qe/app/main.py @@ -4,8 +4,9 @@ Authors: AiiDAlab team """ +import copy + import ipywidgets as ipw -import traitlets as tl from aiida.orm import load_node from aiidalab_widgets_base import WizardAppWidget, WizardAppWidgetStep @@ -19,9 +20,6 @@ class App(ipw.VBox): """The main widget that combines all the application steps together.""" - # use to store the blocker messages for each step - _submission_blockers = tl.Dict() - def __init__(self, qe_auto_setup=True): # Create the application steps self.structure_step = StructureSelectionStep(auto_advance=True) @@ -54,10 +52,6 @@ def __init__(self, qe_auto_setup=True): (self.configure_step, "configuration_parameters"), (self.submit_step, "input_parameters"), ) - ipw.dlink( - (self, "_submission_blockers"), - (self.submit_step, "_outside_submission_blockers"), - ) ipw.dlink( (self.submit_step, "process"), @@ -74,10 +68,6 @@ 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 @@ -117,22 +107,25 @@ def _observe_selected_index(self, change): with self.submit_step.hold_sync(): new_idx = change["new"] # if entering the submit step, udpate the blocker messages - blockers = self._submission_blockers.copy() if new_idx == 2: # check the structure step is saved for i in range(2): # check if the step is saved + blockers = copy.deepcopy( + self.submit_step.external_submission_blockers + ) if not self.steps[i][1].is_saved(): self.steps[i][1].state = WizardAppWidgetStep.State.CONFIGURED - blockers[i] = [ + blockers.append( 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 + blockers = [] + + self.submit_step.external_submission_blockers = blockers def _observe_process_selection(self, change): from aiida.orm.utils.serialize import deserialize_unsafe diff --git a/src/aiidalab_qe/app/submission/__init__.py b/src/aiidalab_qe/app/submission/__init__.py index 74a0bced5..e67ad6504 100644 --- a/src/aiidalab_qe/app/submission/__init__.py +++ b/src/aiidalab_qe/app/submission/__init__.py @@ -60,8 +60,8 @@ class SubmitQeAppWorkChainStep(ipw.VBox, WizardAppWidgetStep): process = tl.Instance(orm.WorkChainNode, allow_none=True) previous_step_state = tl.UseEnum(WizardAppWidgetStep.State) input_parameters = tl.Dict() - _submission_blockers = tl.List(tl.Unicode()) - _outside_submission_blockers = tl.Dict() + internal_submission_blockers = tl.List(tl.Unicode()) + external_submission_blockers = tl.List(tl.Unicode()) def __init__(self, qe_auto_setup=True, **kwargs): self.message_area = ipw.Output() @@ -139,13 +139,7 @@ def __init__(self, qe_auto_setup=True, **kwargs): ] ) - @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") + @tl.observe("internal_submission_blockers", "external_submission_blockers") def _observe_submission_blockers(self, change): """Observe the submission blockers and update the message area.""" if change["new"]: @@ -158,13 +152,7 @@ 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._outside_submission_blockers.values(): - for msg in msgs: - yield msg + """Validate the inputs and identify blockers for the submission.""" # Do not submit while any of the background setup processes are running. if self.qe_setup_status.busy or self.sssp_installation_status.busy: yield "Background setup processes must finish." @@ -199,11 +187,11 @@ def _update_state(self, _=None): blockers = list(self._identify_submission_blockers()) if any(blockers): - self._submission_blockers = blockers + self.internal_submission_blockers = blockers self.state = self.State.READY return - self._submission_blockers = [] + self.internal_submission_blockers = [] self.state = self.state.CONFIGURED def _toggle_install_widgets(self, change):