[IMP] bus: remove websocket connection lost toast
Before this commit, loosing the websocket connection would have resulted in a toast being displayed. This toast is seen as degrading the UX experience and is redundant with the already existing "Connection Lost" toast. This PR removes it. closes odoo/odoo#101501 X-original-commit: a26c8aa18ad6c4f52a4526e20d570ca1bc4123f2 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com> Signed-off-by: Stockbauer Matthieu (tsm) <tsm@odoo.com>
This commit is contained in:
@@ -1,17 +1,10 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { WEBSOCKET_CLOSE_CODES } from "@bus/workers/websocket_worker";
|
||||
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
import { registry } from '@web/core/registry';
|
||||
import { session } from '@web/session';
|
||||
|
||||
const { EventBus } = owl;
|
||||
const NO_POPUP_CLOSE_CODES = [
|
||||
WEBSOCKET_CLOSE_CODES.SESSION_EXPIRED,
|
||||
WEBSOCKET_CLOSE_CODES.KEEP_ALIVE_TIMEOUT,
|
||||
WEBSOCKET_CLOSE_CODES.TRY_LATER,
|
||||
];
|
||||
|
||||
/**
|
||||
* Communicate with a SharedWorker in order to provide a single websocket
|
||||
@@ -24,7 +17,7 @@ const NO_POPUP_CLOSE_CODES = [
|
||||
* @emits notification
|
||||
*/
|
||||
export const busService = {
|
||||
dependencies: ['localization', 'multi_tab', 'notification'],
|
||||
dependencies: ['localization', 'multi_tab'],
|
||||
|
||||
start(env, { multi_tab: multiTab }) {
|
||||
if (session.dbuuid && multiTab.getSharedValue('dbuuid') !== session.dbuuid) {
|
||||
@@ -36,7 +29,6 @@ export const busService = {
|
||||
const worker = new workerClass('/bus/websocket_worker_bundle', {
|
||||
name: 'SharedWorker' in window ? 'odoo:websocket_shared_worker' : 'odoo:websocket_worker',
|
||||
});
|
||||
let removeConnectionLostNotification;
|
||||
|
||||
/**
|
||||
* Send a message to the worker.
|
||||
@@ -65,17 +57,7 @@ export const busService = {
|
||||
function handleMessage(messageEv) {
|
||||
const { type } = messageEv.data;
|
||||
let { data } = messageEv.data;
|
||||
// Do not trigger the connection lost pop up if the reconnecting
|
||||
// event is caused by a session expired/keep_alive_timeout.
|
||||
if (type === 'reconnecting' && !NO_POPUP_CLOSE_CODES.includes(data.closeCode)) {
|
||||
removeConnectionLostNotification = env.services.notification.add(
|
||||
env._t("Websocket connection lost. Trying to reconnect..."),
|
||||
{ sticky: true },
|
||||
);
|
||||
} else if (type === 'reconnect' && removeConnectionLostNotification) {
|
||||
removeConnectionLostNotification();
|
||||
removeConnectionLostNotification = null;
|
||||
} else if (type === 'notification') {
|
||||
if (type === 'notification') {
|
||||
multiTab.setSharedValue('last_notification_id', data[data.length - 1].id);
|
||||
data = data.map(notification => notification.message);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,6 @@ const { registry } = require("@web/core/registry");
|
||||
const { session } = require('@web/session');
|
||||
const { makeDeferred, nextTick, patchWithCleanup } = require("@web/../tests/helpers/utils");
|
||||
const { makeTestEnv } = require('@web/../tests/helpers/mock_env');
|
||||
const { createWebClient } = require("@web/../tests/webclient/helpers");
|
||||
|
||||
const { afterNextRender } = owl.App;
|
||||
|
||||
QUnit.module('Bus', {
|
||||
beforeEach: function () {
|
||||
@@ -311,56 +308,6 @@ QUnit.module('Bus', {
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test('displays reconnect notification', async (assert) => {
|
||||
assert.expect(3);
|
||||
|
||||
let startPromise = Promise.resolve();
|
||||
patchWebsocketWorkerWithCleanup({
|
||||
async _start() {
|
||||
const originalStart = this._super;
|
||||
await startPromise;
|
||||
return originalStart(...arguments);
|
||||
},
|
||||
});
|
||||
const pyEnv = await startServer();
|
||||
await createWebClient({});
|
||||
// prevent websocket to connect and notification to disappear
|
||||
// before the assertion.
|
||||
startPromise = makeDeferred();
|
||||
await afterNextRender(() => pyEnv.simulateConnectionLost(WEBSOCKET_CLOSE_CODES.ABNORMAL_CLOSURE));
|
||||
|
||||
assert.containsOnce(document.body, '.o_notification');
|
||||
assert.strictEqual(
|
||||
document.querySelector('.o_notification .o_notification_content').textContent,
|
||||
'Websocket connection lost. Trying to reconnect...'
|
||||
);
|
||||
// Wait for the worker to reconnect, post a message and the
|
||||
// bus_service to receive it and remove the notification.
|
||||
await afterNextRender(() => startPromise.resolve());
|
||||
assert.containsNone(document.body, '.o_notification');
|
||||
});
|
||||
|
||||
QUnit.test('does not display connection lost popup when refreshing the session', async (assert) => {
|
||||
assert.expect(1);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
await createWebClient({});
|
||||
pyEnv.simulateConnectionLost(WEBSOCKET_CLOSE_CODES.SESSION_EXPIRED);
|
||||
await nextTick();
|
||||
assert.containsNone(document.body, '.o_notification');
|
||||
});
|
||||
|
||||
|
||||
QUnit.test('does not display connection lost popup when refreshing the connection upon keep_alive_timeout', async (assert) => {
|
||||
assert.expect(1);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
await createWebClient({});
|
||||
pyEnv.simulateConnectionLost(WEBSOCKET_CLOSE_CODES.KEEP_ALIVE_TIMEOUT);
|
||||
await nextTick();
|
||||
assert.containsNone(document.body, '.o_notification');
|
||||
});
|
||||
|
||||
QUnit.test('Last notification id is passed to the worker on service start', async function (assert) {
|
||||
const pyEnv = await startServer();
|
||||
let updateLastNotificationDeferred = makeDeferred();
|
||||
|
||||
Reference in New Issue
Block a user