Skip to content

Commit da197d4

Browse files
author
Andrei Neagu
committed
refactor stop dialog
1 parent 926d88d commit da197d4

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/frontend/routes/_index.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,34 @@ def _render_buttons(node_id: NodeID, service: TrackedServiceModel) -> None:
7575
if service.current_state != SchedulerServiceState.RUNNING:
7676
return
7777

78-
with ui.dialog() as confirm_dialog, ui.card():
79-
80-
async def stop_process_task():
81-
confirm_dialog.submit("Stop")
82-
83-
await httpx.AsyncClient(timeout=10).get(
84-
f"http://localhost:{DEFAULT_FASTAPI_PORT}/service/{node_id}:stop"
85-
)
86-
87-
ui.notify(
88-
f"Submitted stop request for {node_id}. Please give the service some time to stop!"
89-
)
90-
91-
ui.markdown(f"Stop service **{node_id}**?")
92-
ui.label("The service will be stopped and its data will be saved.")
93-
with ui.row():
94-
ui.button("Stop", color="red", on_click=stop_process_task)
95-
ui.button("No", on_click=lambda: confirm_dialog.submit("No"))
96-
9778
async def display_confirm_dialog():
98-
await confirm_dialog
79+
with ui.dialog() as confirm_dialog, ui.card():
80+
confirm_dialog.mark(marker_tags.INDEX_SERVICE_CARD_STOP_CONFIRM_DIALOG)
81+
82+
ui.markdown(f"Stop service **{node_id}**?")
83+
ui.label("The service will be stopped and its data will be saved.")
84+
with ui.row():
85+
ui.button(
86+
"Stop",
87+
color="red",
88+
on_click=lambda: confirm_dialog.submit("Stop"),
89+
)
90+
ui.button("No", on_click=lambda: confirm_dialog.submit("No")).mark(
91+
marker_tags.INDEX_SERVICE_CARD_STOP_CONFIRM_DIALOG_NO_BUTTON
92+
)
93+
94+
click_result = await confirm_dialog
95+
96+
if click_result != "Stop":
97+
return
98+
99+
await httpx.AsyncClient(timeout=10).get(
100+
f"http://localhost:{DEFAULT_FASTAPI_PORT}/service/{node_id}:stop"
101+
)
102+
103+
ui.notify(
104+
f"Submitted stop request for {node_id}. Please give the service some time to stop!"
105+
)
99106

100107
ui.button(
101108
"Stop service", icon="stop", color="orange", on_click=display_confirm_dialog

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/frontend/routes/marker_tags.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66
INDEX_SERVICE_CARD: Final[str] = "index-service-card"
77
INDEX_SERVICE_CARD_DETAILS_BUTTON: Final[str] = "index-service-card-details-button"
88
INDEX_SERVICE_CARD_STOP_BUTTON: Final[str] = "index-service-card-stop-button"
9+
INDEX_SERVICE_CARD_STOP_CONFIRM_DIALOG: Final[
10+
str
11+
] = "index-service-card-stop-confirm-dialog"
12+
INDEX_SERVICE_CARD_STOP_CONFIRM_DIALOG_NO_BUTTON: Final[
13+
str
14+
] = "index-service-card-stop-confirm-dialog-no-button"

0 commit comments

Comments
 (0)