diff --git a/src/Handlers/WebSocketMessageHandler.js b/src/Handlers/WebSocketMessageHandler.js index 7a83c9d..f70bbf6 100644 --- a/src/Handlers/WebSocketMessageHandler.js +++ b/src/Handlers/WebSocketMessageHandler.js @@ -46,6 +46,7 @@ export const ReceivedMessagesCommands = { OneNotificationDeleted: 43, AdminAreaManageCheckedForAvailableCategories: 44, AdminAreaManageLogManagerServerConnectionAdded: 45, + AdminAreaManageLogManagerServerConnectionRemoved: 46, }; // commands sent to the backend server @@ -76,6 +77,7 @@ export const SentMessagesCommands = { DeleteOneNotification: 25, AdminAreaManageCheckWhichCategoriesAreAvailable: 26, AdminAreaManageAddLogManagerServerConnection: 27, + AdminAreaManageDeleteLogManagerServerConnection: 28, }; /* @@ -766,24 +768,9 @@ export function handleWebSocketMessage( });*/ break; case ReceivedMessagesCommands.DeletedUserApiKey: - /*userProfileContext.setUserProfile((user) => ({ - ...user, - ApiKeys: user.ApiKeys.filter((apiKey) => apiKey.Id !== body), - })); */ - userProfileContext.setApiKeys((arr) => arr.filter((apiKey) => apiKey.Id !== body) ); - - /*setUser((user) => { - const updatedUser = { ...user }; - - updatedUser.ApiKeys = updatedUser.ApiKeys.filter( - (apiKey) => apiKey.Id !== body - ); - - return updatedUser; - }); */ break; case ReceivedMessagesCommands.NewApiKeyUsageCount: userProfileContext.setApiKeys((arr) => { @@ -798,36 +785,6 @@ export function handleWebSocketMessage( return newArr; }); - - /*userProfileContext.setUserProfile((user) => { - const updatedUser = { ...user }; - - const arrIndex = updatedUser.ApiKeys.findIndex( - (apiKey) => apiKey.Id === body.Id - ); - - if (arrIndex !== -1) { - updatedUser.ApiKeys[arrIndex].UsageCount = body.UsageCount; - updatedUser.ApiKeys[arrIndex].LastUsed = body.LastUsed; - } - - return updatedUser; - }); */ - - /*setUser((user) => { - const updatedUser = { ...user }; - - const arrIndex = updatedUser.ApiKeys.findIndex( - (apiKey) => apiKey.Id === body.Id - ); - - if (arrIndex !== -1) { - updatedUser.ApiKeys[arrIndex].UsageCount = body.UsageCount; - updatedUser.ApiKeys[arrIndex].LastUsed = body.LastUsed; - } - - return updatedUser; - }); */ break; case ReceivedMessagesCommands.InstallingPythonPackages: notificationApi["info"]({ @@ -987,10 +944,14 @@ export function handleWebSocketMessage( } break; case ReceivedMessagesCommands.AdminAreaManageLogManagerServerConnectionAdded: - console.log("b", body); - consolesContext.setConnectedLogManagerServers((arr) => [...arr, body]); break; + case ReceivedMessagesCommands.AdminAreaManageLogManagerServerConnectionRemoved: + consolesContext.setConnectedLogManagerServers((arr) => + arr.filter((c) => c.Id !== body) + ); + break; + default: console.error("unknown command", cmd); break; diff --git a/src/Pages/AdminArea/Manage/index.js b/src/Pages/AdminArea/Manage/index.js index 5dd2705..d391a54 100644 --- a/src/Pages/AdminArea/Manage/index.js +++ b/src/Pages/AdminArea/Manage/index.js @@ -92,7 +92,7 @@ function LogManagerServersTable({ t, webSocketContext, appContext }) { cancelText={t("common.button.cancel")} onConfirm={() => webSocketContext.SendSocketMessage( - SentMessagesCommands.DeleteUserApiKey, + SentMessagesCommands.AdminAreaManageDeleteLogManagerServerConnection, { Id: record.key } ) } @@ -108,10 +108,13 @@ function LogManagerServersTable({ t, webSocketContext, appContext }) { const getTableItems = () => { let items = []; - consolesContext.connectedLogManagerServers.forEach((connection, index) => { + consolesContext.connectedLogManagerServers.sort( + (a, b) => new Date(b.CreatedAt) - new Date(a.CreatedAt) + ); + + consolesContext.connectedLogManagerServers.forEach((connection) => { items.push({ - key: index, - id: connection.Id, + key: connection.Id, displayName: connection.DisplayName, address: connection.Address, createdAt: FormatDatetime(connection.CreatedAt), diff --git a/src/utils.js b/src/utils.js index deaae54..033968a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -142,6 +142,8 @@ export const Constants = { "admin_area.manage.check_which_categories_are_available", ADD_LOG_MANAGER_SERVER_CONNECTION: "admin_area.manage.add_log_manager_server_connection", + REMOVE_LOG_MANAGER_SERVER_CONNECTION: + "admin_area.manage.remove_log_manager_server_connection", }, }, USER_PROFILE: {