Skip to content

Commit 0fad04a

Browse files
FredLL-AvaigaFred Lefévère-Laoide
andauthored
set default behavior (#2544)
change name resolves #2344 Co-authored-by: Fred Lefévère-Laoide <Fred.Lefevere-Laoide@Taipy.io>
1 parent 0336c92 commit 0fad04a

File tree

10 files changed

+41
-42
lines changed

10 files changed

+41
-42
lines changed

frontend/taipy-gui/base/src/app.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class TaipyApp {
4040
_cookieHandler: CookieHandler | undefined;
4141
variableData: DataManager | undefined;
4242
functionData: DataManager | undefined;
43-
appId: string;
43+
guiAddr: string;
4444
clientId: string;
4545
context: string;
4646
metadata: Record<string, unknown>;
@@ -63,7 +63,7 @@ export class TaipyApp {
6363
this.clientId = "";
6464
this.context = "";
6565
this.metadata = {};
66-
this.appId = "";
66+
this.guiAddr = "";
6767
this.routes = undefined;
6868
this.path = path;
6969
this.socket = socket;
@@ -168,7 +168,7 @@ export class TaipyApp {
168168
init() {
169169
this.clientId = "";
170170
this.context = "";
171-
this.appId = "";
171+
this.guiAddr = "";
172172
this.routes = undefined;
173173
const id = getLocalStorageValue(TAIPY_CLIENT_ID, "");
174174
this.sendWsMessage("ID", TAIPY_CLIENT_ID, id);
@@ -180,7 +180,7 @@ export class TaipyApp {
180180
}
181181

182182
initApp() {
183-
this.sendWsMessage("AID", "connect", "");
183+
this.sendWsMessage("GA", "connect", "");
184184
this.sendWsMessage("GR", "", "");
185185
}
186186

frontend/taipy-gui/base/src/packaging/taipy-gui-base.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export type WsMessageType =
7373
| "ACK"
7474
| "GMC"
7575
| "GDT"
76-
| "AID"
76+
| "GA"
7777
| "GR"
7878
| "FV"
7979
| "BC"
@@ -125,7 +125,7 @@ export declare class TaipyApp {
125125
_cookieHandler: CookieHandler | undefined;
126126
variableData: DataManager | undefined;
127127
functionData: DataManager | undefined;
128-
appId: string;
128+
guiAddr: string;
129129
clientId: string;
130130
context: string;
131131
metadata: Record<string, unknown>;

frontend/taipy-gui/base/src/socket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { TaipyApp } from "./app";
55
export const initSocket = (socket: Socket, taipyApp: TaipyApp) => {
66
socket.on("connect", () => {
77
taipyApp.onWsMessageEvent("connect", null);
8-
if (taipyApp.clientId === "" || taipyApp.appId === "") {
8+
if (taipyApp.clientId === "" || taipyApp.guiAddr === "") {
99
taipyApp.init();
1010
}
1111
});
1212
// Send a request to get App ID to verify that the app has not been reloaded
1313
socket.io.on("reconnect", () => {
1414
taipyApp.onWsMessageEvent("reconnect", null);
1515
console.log("WebSocket reconnected");
16-
taipyApp.sendWsMessage("AID", "reconnect", taipyApp.appId);
16+
taipyApp.sendWsMessage("GA", "reconnect", taipyApp.guiAddr);
1717
});
1818
// try to reconnect on connect_error
1919
socket.on("connect_error", (err) => {

frontend/taipy-gui/base/src/wsAdapter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export class TaipyWsAdapter extends WsAdapter {
2525
initWsMessageTypes: string[];
2626
constructor() {
2727
super();
28-
this.supportedMessageTypes = ["MU", "ID", "GMC", "GDT", "AID", "GR", "AL", "ACK"];
29-
this.initWsMessageTypes = ["ID", "AID", "GMC"];
28+
this.supportedMessageTypes = ["MU", "ID", "GMC", "GDT", "GA", "GR", "AL", "ACK"];
29+
this.initWsMessageTypes = ["ID", "GA", "GMC"];
3030
}
3131
handleWsMessage(message: WsMessage, taipyApp: TaipyApp): boolean {
3232
if (message.type) {
@@ -86,13 +86,13 @@ export class TaipyWsAdapter extends WsAdapter {
8686
taipyApp.functionData = new DataManager(functionData);
8787
taipyApp.onInitEvent();
8888
}
89-
} else if (message.type === "AID") {
89+
} else if (message.type === "GA") {
9090
const payload = message.payload as Record<string, unknown>;
9191
if (payload.name === "reconnect") {
9292
taipyApp.init();
9393
return true;
9494
}
95-
taipyApp.appId = payload.id as string;
95+
taipyApp.guiAddr = payload.id as string;
9696
} else if (message.type === "GR") {
9797
const payload = message.payload as [string, string][];
9898
taipyApp.routes = payload;
@@ -114,7 +114,7 @@ export class TaipyWsAdapter extends WsAdapter {
114114
if (
115115
this.initWsMessageTypes.includes(message.type) &&
116116
taipyApp.clientId !== "" &&
117-
taipyApp.appId !== "" &&
117+
taipyApp.guiAddr !== "" &&
118118
taipyApp.context !== "" &&
119119
taipyApp.routes !== undefined
120120
) {

frontend/taipy-gui/src/context/taipyReducers.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { getBaseURL, TIMEZONE_CLIENT } from "../utils";
2424
import { parseData } from "../utils/dataFormat";
2525
import { MenuProps } from "../utils/lov";
2626
import { changeFavicon, getLocalStorageValue, IdMessage, storeClientId } from "./utils";
27-
import { lightenPayload, sendWsMessage, TAIPY_APP_ID, TAIPY_CLIENT_ID, WsMessage } from "./wsUtils";
27+
import { lightenPayload, sendWsMessage, TAIPY_GUI_ADDR, TAIPY_CLIENT_ID, WsMessage } from "./wsUtils";
2828

2929
export enum Types {
3030
SocketConnected = "SOCKET_CONNECTED",
@@ -242,8 +242,8 @@ export const messageToAction = (message: WsMessage) => {
242242
changeFavicon((message.payload as Record<string, string>)?.value);
243243
} else if (message.type == "BC") {
244244
stackBroadcast((message as NamePayload).name, (message as NamePayload).payload.value);
245-
} else if (message.type == "AID") {
246-
checkAppId((message.payload as Record<string, string>).id);
245+
} else if (message.type == "GA") {
246+
checkGuiAddr((message.payload as Record<string, string>).id);
247247
}
248248
}
249249
return {} as TaipyBaseAction;
@@ -288,16 +288,19 @@ const initializeBroadcastManagement = (dispatch: Dispatch<TaipyBaseAction>) => {
288288
}, broadcast_timeout);
289289
};
290290

291-
// App id
292-
const checkAppId = (appId: string) => {
293-
if (!appId) {
291+
// Gui Address
292+
const checkGuiAddr = (guiAddr: string) => {
293+
if (!guiAddr) {
294294
return;
295295
}
296-
appId = `${appId}`;
297-
const localAppId = getLocalStorageValue(TAIPY_APP_ID, "");
298-
if (!localAppId || localAppId !== appId) {
299-
localStorage && localStorage.setItem(TAIPY_APP_ID, appId);
300-
localAppId && window.location.assign(getBaseURL());
296+
guiAddr = `${guiAddr}`;
297+
const localGuiAddr = getLocalStorageValue(TAIPY_GUI_ADDR, "");
298+
if (!localGuiAddr || localGuiAddr !== guiAddr) {
299+
localStorage && localStorage.setItem(TAIPY_GUI_ADDR, guiAddr);
300+
if (localGuiAddr) {
301+
console.info("Taipy GUI address changed, reloading the page");
302+
window.location.assign(getBaseURL());
303+
}
301304
}
302305
};
303306

@@ -311,7 +314,7 @@ export const initializeWebSocket = (socket: Socket | undefined, dispatch: Dispat
311314
const id = getLocalStorageValue(TAIPY_CLIENT_ID, "");
312315
const payload: Record<string, unknown> = { id };
313316
if (lastReasonServer) {
314-
payload["app_id"] = Number(getLocalStorageValue(TAIPY_APP_ID, ""));
317+
payload["gui_addr"] = Number(getLocalStorageValue(TAIPY_GUI_ADDR, ""));
315318
}
316319
sendWsMessage(socket, "ID", TAIPY_CLIENT_ID, payload, id, undefined, false, () => {
317320
dispatch({ type: Types.SocketConnected });

frontend/taipy-gui/src/context/wsUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Socket } from "socket.io-client";
22
import { nanoid } from 'nanoid'
33

44
export const TAIPY_CLIENT_ID = "TaipyClientId";
5-
export const TAIPY_APP_ID = "TaipyAppId";
5+
export const TAIPY_GUI_ADDR = "TaipyGuiAddr";
66

77
export type WsMessageType =
88
| "A"
@@ -20,7 +20,7 @@ export type WsMessageType =
2020
| "ACK"
2121
| "GMC"
2222
| "GDT"
23-
| "AID"
23+
| "GA"
2424
| "GR"
2525
| "FV"
2626
| "BC"

taipy/gui/_default_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
# Default config loaded by app.py
4343
default_config: Config = {
4444
"allow_unsafe_werkzeug": False,
45-
"app_id": False,
4645
"async_mode": "gevent",
4746
"change_delay": None,
4847
"chart_dark_template": None,

taipy/gui/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
ConfigParameter = t.Literal[
3232
"allow_unsafe_werkzeug",
33-
"app_id",
3433
"async_mode",
3534
"change_delay",
3635
"chart_dark_template",
@@ -105,7 +104,6 @@
105104
"Config",
106105
{
107106
"allow_unsafe_werkzeug": bool,
108-
"app_id": t.Optional[bool],
109107
"async_mode": str,
110108
"change_delay": t.Optional[int],
111109
"chart_dark_template": t.Optional[t.Dict[str, t.Any]],

taipy/gui/gui.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,9 @@ def _manage_message(self, msg_type: _WsType, message: dict) -> None:
704704
payload.get("id", "") if isinstance(payload, dict) else str(payload)
705705
)
706706
client_id = res[0] if res[1] else None
707-
if self._config.config.get("app_id", False):
708-
front_app_id = payload.get("app_id", None) if isinstance(payload, dict) else None
709-
if front_app_id is not None:
710-
self.__handle_ws_app_id({"name": message.get("name"), "payload": front_app_id})
707+
front_gui_addr = payload.get("gui_addr", None) if isinstance(payload, dict) else None
708+
if front_gui_addr is not None:
709+
self.__handle_ws_gui_addr({"name": message.get("name"), "payload": front_gui_addr})
711710
expected_client_id = client_id or message.get(Gui.__ARG_CLIENT_ID)
712711
self.__set_client_id_in_context(expected_client_id)
713712
g.ws_client_id = expected_client_id
@@ -732,8 +731,8 @@ def _manage_message(self, msg_type: _WsType, message: dict) -> None:
732731
self.__handle_ws_get_module_context(payload)
733732
elif msg_type == _WsType.GET_DATA_TREE.value:
734733
self.__handle_ws_get_data_tree()
735-
elif msg_type == _WsType.APP_ID.value:
736-
self.__handle_ws_app_id(message)
734+
elif msg_type == _WsType.GUI_ADDR.value:
735+
self.__handle_ws_gui_addr(message)
737736
elif msg_type == _WsType.GET_ROUTES.value:
738737
self.__handle_ws_get_routes()
739738
elif msg_type == _WsType.LOCAL_STORAGE.value:
@@ -1341,18 +1340,18 @@ def __handle_ws_get_data_tree(self):
13411340
send_back_only=True,
13421341
)
13431342

1344-
def __handle_ws_app_id(self, message: t.Any):
1343+
def __handle_ws_gui_addr(self, message: t.Any):
13451344
if not isinstance(message, dict):
13461345
return
13471346
name = message.get("name", "")
13481347
payload = message.get("payload", "")
1349-
app_id = id(self)
1350-
if payload == app_id:
1348+
gui_addr = id(self)
1349+
if payload == gui_addr:
13511350
return
13521351
self.__send_ws(
13531352
{
1354-
"type": _WsType.APP_ID.value,
1355-
"payload": {"name": name, "id": app_id},
1353+
"type": _WsType.GUI_ADDR.value,
1354+
"payload": {"name": name, "id": gui_addr},
13561355
},
13571356
send_back_only=True,
13581357
)

taipy/gui/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class _WsType(Enum):
4343
BLOCK = "BL"
4444
NAVIGATE = "NA"
4545
CLIENT_ID = "ID"
46-
APP_ID = "AID"
46+
GUI_ADDR = "GA"
4747
MULTIPLE_MESSAGE = "MS"
4848
DOWNLOAD_FILE = "DF"
4949
PARTIAL = "PR"

0 commit comments

Comments
 (0)