From a044069ab1e48c56023b423a89e849a1a98a7ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fred=20Lef=C3=A9v=C3=A8re-Laoide?= Date: Wed, 18 Dec 2024 17:02:06 +0100 Subject: [PATCH] #2152 on submission change called twice with same status (#2353) #2305 normalize components height resolves #2152 #2305 --- .../public/stylekit/controls/button.css | 4 + .../stylekit/controls/file_download.css | 3 + .../stylekit/controls/file_selector.css | 3 + .../public/stylekit/controls/selector.css | 2 +- .../public/stylekit/controls/slider.css | 1 + .../public/stylekit/controls/status.css | 1 + .../public/stylekit/controls/toggle.css | 3 + taipy/gui_core/_context.py | 99 +++++++++---------- 8 files changed, 64 insertions(+), 52 deletions(-) diff --git a/frontend/taipy-gui/public/stylekit/controls/button.css b/frontend/taipy-gui/public/stylekit/controls/button.css index 9bf4d9a171..f2b1e56a6e 100644 --- a/frontend/taipy-gui/public/stylekit/controls/button.css +++ b/frontend/taipy-gui/public/stylekit/controls/button.css @@ -21,6 +21,10 @@ MODIFIER CLASSES **************************************************/ +.taipy-button { + margin: 4px 0; +} + /* fullwidth : */ .taipy-button.fullwidth { display: flex; diff --git a/frontend/taipy-gui/public/stylekit/controls/file_download.css b/frontend/taipy-gui/public/stylekit/controls/file_download.css index 54085e4b4c..903818c918 100644 --- a/frontend/taipy-gui/public/stylekit/controls/file_download.css +++ b/frontend/taipy-gui/public/stylekit/controls/file_download.css @@ -20,6 +20,9 @@ /************************************************* MODIFIER CLASSES **************************************************/ +.taipy-file-download>button { + margin: 4px 0; +} /* fullwidth : */ .taipy-file-download.fullwidth button { diff --git a/frontend/taipy-gui/public/stylekit/controls/file_selector.css b/frontend/taipy-gui/public/stylekit/controls/file_selector.css index 08515985d8..d99757cdb8 100644 --- a/frontend/taipy-gui/public/stylekit/controls/file_selector.css +++ b/frontend/taipy-gui/public/stylekit/controls/file_selector.css @@ -20,6 +20,9 @@ /************************************************* MODIFIER CLASSES **************************************************/ +.taipy-file-selector .MuiButtonBase-root { + margin: 4px 0; +} /* fullwidth : */ .taipy-file-selector.fullwidth [role='button'] { diff --git a/frontend/taipy-gui/public/stylekit/controls/selector.css b/frontend/taipy-gui/public/stylekit/controls/selector.css index 0e56ecdc7d..cdb929aca4 100644 --- a/frontend/taipy-gui/public/stylekit/controls/selector.css +++ b/frontend/taipy-gui/public/stylekit/controls/selector.css @@ -22,7 +22,7 @@ **************************************************/ .taipy-selector { - margin: 0; + margin: 4px 0; } diff --git a/frontend/taipy-gui/public/stylekit/controls/slider.css b/frontend/taipy-gui/public/stylekit/controls/slider.css index 4bba39e40a..e978642689 100644 --- a/frontend/taipy-gui/public/stylekit/controls/slider.css +++ b/frontend/taipy-gui/public/stylekit/controls/slider.css @@ -26,4 +26,5 @@ max-width: 100%; min-height: 48px; align-items: center; + margin: 4px 0; } diff --git a/frontend/taipy-gui/public/stylekit/controls/status.css b/frontend/taipy-gui/public/stylekit/controls/status.css index c0e1d73381..3643303e77 100644 --- a/frontend/taipy-gui/public/stylekit/controls/status.css +++ b/frontend/taipy-gui/public/stylekit/controls/status.css @@ -25,4 +25,5 @@ display: inline-flex; min-height: 48px; padding-top: 0.5em; + margin: 4px 0; } diff --git a/frontend/taipy-gui/public/stylekit/controls/toggle.css b/frontend/taipy-gui/public/stylekit/controls/toggle.css index 7ff2b1afe9..2a75e9ee5e 100644 --- a/frontend/taipy-gui/public/stylekit/controls/toggle.css +++ b/frontend/taipy-gui/public/stylekit/controls/toggle.css @@ -36,6 +36,9 @@ /************************************************* MODIFIER CLASSES **************************************************/ +.taipy-toggle { + margin: 4px 0; +} /* relative : Reset the theme toggle position to fit page flow */ .taipy-toggle.relative { diff --git a/taipy/gui_core/_context.py b/taipy/gui_core/_context.py index 82f8b7bdad..036b42b1c5 100644 --- a/taipy/gui_core/_context.py +++ b/taipy/gui_core/_context.py @@ -166,67 +166,64 @@ def submission_status_callback(self, submission_id: t.Optional[str] = None, even if not submission_id: return submission = None - new_status = None + new_status: t.Optional[SubmissionStatus] = None payload: t.Optional[t.Dict[str, t.Any]] = None client_id: t.Optional[str] = None + submission_name: t.Optional[str] = None try: - last_client_status = self.client_submission.get(submission_id) - if not last_client_status: + submission = t.cast(Submission, core_get(submission_id)) + if not submission or not submission.entity_id: return + new_status = submission.submission_status - client_id = last_client_status.client_id - - with self.gui._get_authorization(client_id): - if not is_readable(t.cast(SubmissionId, submission_id)): - return - submission = t.cast(Submission, core_get(submission_id)) - if not submission or not submission.entity_id: + with self.submissions_lock: + last_client_status = self.client_submission.get(submission_id) + if not last_client_status: return payload = {} - new_status = t.cast(SubmissionStatus, submission.submission_status) - - if client_id: - running_tasks = {} - # with self.gui._get_authorization(client_id): - for job in submission.jobs: - job = job if isinstance(job, Job) else t.cast(Job, core_get(job)) - running_tasks[job.task.id] = ( - SubmissionStatus.RUNNING.value - if job.is_running() - else SubmissionStatus.PENDING.value - if job.is_pending() - else None - ) - payload.update(tasks=running_tasks) - - if last_client_status.submission_status is not new_status: - # callback - submission_name = submission.properties.get("on_submission") - if submission_name: - self.gui.invoke_callback( - client_id, - submission_name, - [ - core_get(submission.id), - { - "submission_status": new_status.name, - "submittable_entity": core_get(submission.entity_id), - **(event.metadata if event else {}), - }, - ], - submission.properties.get("module_context"), + if last_client_status.submission_status is not new_status: + # callback + submission_name = submission.properties.get("on_submission") + + if new_status in ( + SubmissionStatus.COMPLETED, + SubmissionStatus.FAILED, + SubmissionStatus.CANCELED, + ): + self.client_submission.pop(submission_id, None) + else: + last_client_status.submission_status = new_status + + if client_id:= submission.properties.get("client_id"): + with self.gui._get_authorization(client_id): + if payload is not None: + running_tasks = {} + for job in submission.jobs: + job = job if isinstance(job, Job) else t.cast(Job, core_get(job)) + running_tasks[job.task.id] = ( + SubmissionStatus.RUNNING.value + if job.is_running() + else SubmissionStatus.PENDING.value + if job.is_pending() + else None ) + payload.update(tasks=running_tasks) - if new_status in ( - SubmissionStatus.COMPLETED, - SubmissionStatus.FAILED, - SubmissionStatus.CANCELED, - ): - with self.submissions_lock: - self.client_submission.pop(submission_id, None) - else: - last_client_status.submission_status = new_status + if submission_name: + self.gui.invoke_callback( + client_id, + submission_name, + [ + core_get(submission.id), + { + "submission_status": new_status.name if new_status else "None", + "submittable_entity": core_get(submission.entity_id), + **(event.metadata if event else {}), + }, + ], + submission.properties.get("module_context"), + ) except Exception as e: _warn(f"Submission ({submission_id}) is not available", e)