Skip to content

Commit

Permalink
root page decouple (#1443)
Browse files Browse the repository at this point in the history
* root page decouple

* fix resource_handler id
  • Loading branch information
dinhlongviolin1 authored Jun 25, 2024
1 parent 8a444b6 commit 013faf9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/taipy-gui/base/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class TaipyApp {
if (!path || path === "") {
path = window.location.pathname.slice(1);
}
sendWsMessage(this.socket, "GMC", "get_module_context", { path: path }, this.clientId);
sendWsMessage(this.socket, "GMC", "get_module_context", { path: path || "/" }, this.clientId);
}

trigger(actionName: string, triggerId: string, payload: Record<string, unknown> = {}) {
Expand Down
4 changes: 2 additions & 2 deletions taipy/gui/custom/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class ResourceHandler(ABC):
User can implement this class to provide custom resources for the custom pages
"""

id: str = ""
rh_id: str = ""

def __init__(self) -> None:
_ExternalResourceHandlerManager().register(self)

def get_id(self) -> str:
return self.id if id != "" else str(id(self))
return self.rh_id if self.rh_id != "" else str(id(self))

@abstractmethod
def get_resources(self, path: str, taipy_resource_path: str) -> t.Any:
Expand Down
9 changes: 7 additions & 2 deletions taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,10 +1111,13 @@ def __request_var_update(self, payload: t.Any):

def __handle_ws_get_module_context(self, payload: t.Any):
if isinstance(payload, dict):
page_path = str(payload.get("path"))
if page_path in {"/", ""}:
page_path = Gui.__root_page_name
# Get Module Context
if mc := self._get_page_context(str(payload.get("path"))):
if mc := self._get_page_context(page_path):
self._bind_custom_page_variables(
self._get_page(str(payload.get("path")))._renderer, self._get_client_id()
self._get_page(page_path)._renderer, self._get_client_id()
)
self.__send_ws(
{
Expand Down Expand Up @@ -2149,6 +2152,8 @@ def _get_page(self, page_name: str):

def _bind_custom_page_variables(self, page: CustomPage, client_id: t.Optional[str]):
"""Handle the bindings of custom page variables"""
if not isinstance(page, CustomPage):
return
with self.get_flask_app().app_context() if has_app_context() else contextlib.nullcontext(): # type: ignore[attr-defined]
self.__set_client_id_in_context(client_id)
with self._set_locals_context(page._get_module_name()):
Expand Down

0 comments on commit 013faf9

Please sign in to comment.