From 404ff203edd37912a0a95c3be629de9aff70ab6b Mon Sep 17 00:00:00 2001 From: shadowusr Date: Mon, 9 Dec 2024 01:40:16 +0300 Subject: [PATCH] fix: fix review issues --- lib/gui/event-source.ts | 16 +++++++++------- .../modules/actions/gui-server-connection.ts | 1 - lib/static/modules/default-state.ts | 3 +-- .../modules/reducers/gui-server-connection.ts | 3 +-- lib/static/new-ui/app/gui.tsx | 2 +- lib/static/new-ui/components/InfoPanel/index.tsx | 8 +++++--- lib/static/new-ui/types/store.ts | 1 - 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/gui/event-source.ts b/lib/gui/event-source.ts index 5bf5ca3dc..b57165dc4 100644 --- a/lib/gui/event-source.ts +++ b/lib/gui/event-source.ts @@ -8,19 +8,21 @@ export class EventSource { this._connections = []; } + private _write(connection: Response, event: string, data?: unknown): void { + connection.write('event: ' + event + '\n'); + connection.write('data: ' + stringify(data) + '\n'); + connection.write('\n\n'); + } + addConnection(connection: Response): void { this._connections.push(connection); - connection.write('event: ' + ClientEvents.CONNECTED + '\n'); - connection.write('data: 1\n'); - connection.write('\n\n'); + this._write(connection, ClientEvents.CONNECTED, 1); } emit(event: string, data?: unknown): void { - this._connections.forEach(function(connection) { - connection.write('event: ' + event + '\n'); - connection.write('data: ' + stringify(data) + '\n'); - connection.write('\n\n'); + this._connections.forEach((connection) => { + this._write(connection, event, data); }); } } diff --git a/lib/static/modules/actions/gui-server-connection.ts b/lib/static/modules/actions/gui-server-connection.ts index 8e35938da..006cac96c 100644 --- a/lib/static/modules/actions/gui-server-connection.ts +++ b/lib/static/modules/actions/gui-server-connection.ts @@ -3,7 +3,6 @@ import actionNames from '@/static/modules/action-names'; type SetGuiServerConnectionStatusAction = Action; export const setGuiServerConnectionStatus = (payload: SetGuiServerConnectionStatusAction['payload']): SetGuiServerConnectionStatusAction => ({type: actionNames.SET_GUI_SERVER_CONNECTION_STATUS, payload}); diff --git a/lib/static/modules/default-state.ts b/lib/static/modules/default-state.ts index 373d0749e..e9652974e 100644 --- a/lib/static/modules/default-state.ts +++ b/lib/static/modules/default-state.ts @@ -128,8 +128,7 @@ export default Object.assign({config: configDefaults}, { currentDirection: SortDirection.Asc }, guiServerConnection: { - isConnected: false, - wasDisconnected: false + isConnected: false } }, ui: { diff --git a/lib/static/modules/reducers/gui-server-connection.ts b/lib/static/modules/reducers/gui-server-connection.ts index e7fec39f0..5dfd6f669 100644 --- a/lib/static/modules/reducers/gui-server-connection.ts +++ b/lib/static/modules/reducers/gui-server-connection.ts @@ -9,8 +9,7 @@ export default (state: State, action: SomeAction): State => { return applyStateUpdate(state, { app: { guiServerConnection: { - isConnected: action.payload.isConnected, - wasDisconnected: action.payload.wasDisconnected + isConnected: action.payload.isConnected } } }); diff --git a/lib/static/new-ui/app/gui.tsx b/lib/static/new-ui/app/gui.tsx index 791fc8f09..4583e9781 100644 --- a/lib/static/new-ui/app/gui.tsx +++ b/lib/static/new-ui/app/gui.tsx @@ -26,7 +26,7 @@ function Gui(): ReactNode { store.dispatch({type: actionNames.UPDATE_LOADING_TITLE, payload: 'Lost connection to Testplane UI server. Trying to reconnect'}); store.dispatch({type: actionNames.UPDATE_LOADING_VISIBILITY, payload: true}); - store.dispatch(setGuiServerConnectionStatus({isConnected: false, wasDisconnected: true})); + store.dispatch(setGuiServerConnectionStatus({isConnected: false})); }; eventSource.addEventListener(ClientEvents.BEGIN_SUITE, (e) => { diff --git a/lib/static/new-ui/components/InfoPanel/index.tsx b/lib/static/new-ui/components/InfoPanel/index.tsx index 614f88391..922490937 100644 --- a/lib/static/new-ui/components/InfoPanel/index.tsx +++ b/lib/static/new-ui/components/InfoPanel/index.tsx @@ -26,7 +26,7 @@ export function InfoPanel(): ReactNode { sections.push(To get the most out of Testplane UI, try to keep it updated to the latest version. Check out fresh releases on GitHub.} + description={To get the most out of Testplane UI, try to keep it updated to the latest version. Check out fresh releases on GitHub.} />); const timestamp = useSelector(state => state.timestamp); @@ -56,11 +56,13 @@ export function InfoPanel(): ReactNode { ); + const lastSection = sections.pop(); + return - {sections.slice(0, -1).map((section, index) => + {sections.map((section, index) => {section} )} - {sections[sections.length - 1]} + {lastSection} ; } diff --git a/lib/static/new-ui/types/store.ts b/lib/static/new-ui/types/store.ts index af56b5695..a31efac7f 100644 --- a/lib/static/new-ui/types/store.ts +++ b/lib/static/new-ui/types/store.ts @@ -269,7 +269,6 @@ export interface State { }; guiServerConnection: { isConnected: boolean; - wasDisconnected: boolean | undefined; }; }; ui: {