Adding visual return when error

This commit is contained in:
2025-07-12 09:52:56 +02:00
parent d0f7536fa0
commit 2754312141
7 changed files with 163 additions and 76 deletions

View File

@@ -11,7 +11,7 @@ from components.workflows.commands import WorkflowDesignerCommandManager
from components.workflows.components.WorkflowPlayer import WorkflowPlayer
from components.workflows.constants import WORKFLOW_DESIGNER_INSTANCE_ID, ProcessorTypes
from components.workflows.db_management import WorkflowsDesignerSettings, WorkflowComponent, \
Connection, WorkflowsDesignerDbManager, WorkflowsPlayerSettings, WorkflowComponentRuntimeState
Connection, WorkflowsDesignerDbManager, WorkflowsPlayerSettings, WorkflowComponentRuntimeState, ComponentState
from components_helpers import apply_boundaries, mk_tooltip, mk_dialog_buttons, mk_icon
from core.instance_manager import InstanceManager
from core.utils import get_unique_id, make_safe_id
@@ -84,8 +84,8 @@ class WorkflowDesigner(BaseComponent):
def refresh_designer(self):
return self._mk_elements()
def refresh_properties(self):
return self._mk_properties()
def refresh_properties(self, oob=False):
return self._mk_properties(oob)
def add_component(self, component_type, x, y):
self._state.component_counter += 1
@@ -109,11 +109,12 @@ class WorkflowDesigner(BaseComponent):
def move_component(self, component_id, x, y):
if component_id in self._state.components:
self._state.selected_component_id = component_id
self._state.components[component_id].x = int(x)
self._state.components[component_id].y = int(y)
self._db.save_state(self._key, self._state) # update db
return self.refresh_designer()
return self.refresh_designer(), self.refresh_properties(True)
def delete_component(self, component_id):
# Remove component
@@ -189,17 +190,18 @@ class WorkflowDesigner(BaseComponent):
return self.refresh_properties()
def play_workflow(self, boundaries: dict):
if self._state.selected_component_id is None:
self._error_message = "No component selected"
return self.tabs_manager.refresh()
self._error_message = None
try:
self._player.run()
self._player.run()
if self._player.global_error:
# Show the error message in the same tab
self._error_message = self._player.global_error
else:
# change the tab and display the results
self.tabs_manager.add_tab(f"Workflow {self._designer_settings.workflow_name}", self._player, self._player.key)
except Exception as e:
self._error_message = str(e)
return self.tabs_manager.refresh()
def on_processor_details_event(self, component_id: str, event_name: str, details: dict):
@@ -260,14 +262,48 @@ class WorkflowDesigner(BaseComponent):
</svg>
"""
def _mk_component(self, component: WorkflowComponent, runtime_state: WorkflowComponentRuntimeState):
info = COMPONENT_TYPES[component.type]
is_selected = self._state.selected_component_id == component.id
if runtime_state.state == ComponentState.FAILURE:
state_class = 'error' # To be styled with a red highlight
elif runtime_state.state == ComponentState.NOT_RUN:
state_class = 'not-run' # To be styled as greyed-out
else:
state_class = ''
return Div(
# Input connection point
Div(cls="wkf-connection-point wkf-input-point",
data_component_id=component.id,
data_point_type="input"),
# Component content
Div(
Span(info["icon"], cls="text-xl mb-1"),
H4(component.title, cls="font-semibold text-xs"),
cls=f"wkf-component-content {info['color']} {state_class}"
),
# Output connection point
Div(cls="wkf-connection-point wkf-output-point",
data_component_id=component.id,
data_point_type="output"),
cls=f"wkf-workflow-component w-32 {'selected' if is_selected else ''}",
style=f"left: {component.x}px; top: {component.y}px;",
data_component_id=component.id,
draggable="true"
)
def _mk_elements(self):
return Div(
# Render connections
*[NotStr(self._mk_connection_svg(conn)) for conn in self._state.connections],
# Render components
*[self._mk_workflow_component(comp, state) for comp, state in zip(self._state.components.values(),
self._player.runtime_states)],
*[self._mk_component(comp, state) for comp, state in zip(self._state.components.values(),
self._player.runtime_states)],
)
def _mk_canvas(self, oob=False):
@@ -293,7 +329,7 @@ class WorkflowDesigner(BaseComponent):
self._mk_toolbox(), # (Left side)
self._mk_canvas(), # (Right side)
cls="wkf-designer flex gap-4",
cls="wkf-designer flex gap-1",
id=f"d_{self._id}",
style=f"height:{self._state.designer_height}px;"
)
@@ -374,11 +410,12 @@ class WorkflowDesigner(BaseComponent):
Script(f"bindFormData('f_{self._id}_{component_id}');")
)
def _mk_properties(self):
def _mk_properties(self, oob=False):
return Div(
self._mk_properties_details(self._state.selected_component_id),
cls="p-2 bg-base-100 rounded-lg border",
style=f"height:{self._get_properties_height()}px;",
hx_swap_oob='true' if oob else None,
id=f"p_{self._id}",
)
@@ -503,30 +540,3 @@ class WorkflowDesigner(BaseComponent):
draggable="true",
data_type=component_type
)
@staticmethod
def _mk_workflow_component(component: WorkflowComponent, component_state: WorkflowComponentRuntimeState):
info = COMPONENT_TYPES[component.type]
return Div(
# Input connection point
Div(cls="wkf-connection-point wkf-input-point",
data_component_id=component.id,
data_point_type="input"),
# Component content
Div(
Span(info["icon"], cls="text-xl mb-1"),
H4(component.title, cls="font-semibold text-xs"),
cls=f"wkf-component-content {info['color']} {'error' if component_state.has_error else ''}"
),
# Output connection point
Div(cls="wkf-connection-point wkf-output-point",
data_component_id=component.id,
data_point_type="output"),
cls="wkf-workflow-component w-32",
style=f"left: {component.x}px; top: {component.y}px;",
data_component_id=component.id,
draggable="true"
)