Skip to content

Commit

Permalink
fix decouple metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhlongviolin1 committed Jun 25, 2024
1 parent 8a444b6 commit 57092cf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 3 additions & 1 deletion frontend/taipy-gui/base/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class TaipyApp {
appId: string;
clientId: string;
context: string;
metadata: Record<string, unknown>;
path: string | undefined;
routes: Route[] | undefined;
wsAdapters: WsAdapter[];
Expand All @@ -41,6 +42,7 @@ export class TaipyApp {
this.functionData = undefined;
this.clientId = "";
this.context = "";
this.metadata = {};
this.appId = "";
this.routes = undefined;
this.path = path;
Expand Down Expand Up @@ -175,7 +177,7 @@ export class TaipyApp {
}

getPageMetadata() {
return JSON.parse(localStorage.getItem("tp_cp_meta") || "{}");
return this.metadata;
}
}

Expand Down
1 change: 0 additions & 1 deletion frontend/taipy-gui/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export type { OnChangeHandler, OnInitHandler, ModuleData };

window.addEventListener("beforeunload", () => {
document.cookie = "tprh=;path=/;Max-Age=-99999999;";
localStorage.removeItem("tp_cp_meta");
});
6 changes: 3 additions & 3 deletions frontend/taipy-gui/base/src/wsAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export class TaipyWsAdapter extends WsAdapter {
taipyApp.clientId = id;
taipyApp.updateContext(taipyApp.path);
} else if (message.type === "GMC") {
const mc = (message.payload as Record<string, unknown>).data as string;
window.localStorage.setItem("ModuleContext", mc);
taipyApp.context = mc;
const payload = message.payload as Record<string, unknown>;
taipyApp.context = payload.context as string;
taipyApp.metadata = JSON.parse((payload.metadata as string) || "{}");
} else if (message.type === "GDT") {
const payload = message.payload as Record<string, ModuleData>;
const variableData = payload.variable;
Expand Down
6 changes: 1 addition & 5 deletions frontend/taipy-gui/src/components/Taipy/Navigate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Navigate = ({ to, params, tab, force }: NavigateProps) => {
const { dispatch, state } = useContext(TaipyContext);
const navigate = useNavigate();
const location = useLocation();
const SPECIAL_PARAMS = ["tp_reload_all", "tp_reload_same_route_only", "tprh", "tp_cp_meta"];
const SPECIAL_PARAMS = ["tp_reload_all", "tp_reload_same_route_only", "tprh"];

useEffect(() => {
if (to) {
Expand Down Expand Up @@ -65,10 +65,6 @@ const Navigate = ({ to, params, tab, force }: NavigateProps) => {
if (tprh !== undefined) {
// Add a session cookie for the resource handler id
document.cookie = `tprh=${tprh};path=/;`;
const meta = params?.tp_cp_meta;
if (meta !== undefined) {
localStorage.setItem("tp_cp_meta", meta);
}
navigate(0);
}
}
Expand Down
8 changes: 6 additions & 2 deletions taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,10 +1116,15 @@ def __handle_ws_get_module_context(self, payload: t.Any):
self._bind_custom_page_variables(
self._get_page(str(payload.get("path")))._renderer, self._get_client_id()
)
# get metadata if there is one
metadata: t.Dict[str, t.Any] = {}
page = self._get_page(str(payload.get("path")))
if hasattr(page._renderer, "_metadata"):
metadata = getattr(page._renderer, "_metadata", {})
self.__send_ws(
{
"type": _WsType.GET_MODULE_CONTEXT.value,
"payload": {"data": mc},
"payload": {"context": mc, "metadata": json.dumps(metadata, cls=_TaipyJsonEncoder)},
}
)

Expand Down Expand Up @@ -2178,7 +2183,6 @@ def __render_page(self, page_name: str) -> t.Any:
to=page_name,
params={
_Server._RESOURCE_HANDLER_ARG: pr._resource_handler.get_id(),
_Server._CUSTOM_PAGE_META_ARG: json.dumps(pr._metadata, cls=_TaipyJsonEncoder),
},
):
# Proactively handle the bindings of custom page variables
Expand Down
1 change: 0 additions & 1 deletion taipy/gui/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class _Server:
__OPENING_CURLY = r"\1&#x7B;"
__CLOSING_CURLY = r"&#x7D;\2"
_RESOURCE_HANDLER_ARG = "tprh"
_CUSTOM_PAGE_META_ARG = "tp_cp_meta"

def __init__(
self,
Expand Down

0 comments on commit 57092cf

Please sign in to comment.