diff --git a/public/services/NotificationService.ts b/public/services/NotificationService.ts index f9e166da..5acd1dba 100644 --- a/public/services/NotificationService.ts +++ b/public/services/NotificationService.ts @@ -4,7 +4,6 @@ */ import { SortDirection } from '@elastic/eui'; -import _ from 'lodash'; import { HttpFetchQuery, HttpSetup } from '../../../../src/core/public'; import { NODE_API } from '../../common'; import { @@ -14,7 +13,6 @@ import { SenderType, SESSenderItemType, } from '../../models/interfaces'; -import { CHANNEL_TYPE } from '../utils/constants'; import { configListToChannels, configListToRecipientGroups, @@ -215,21 +213,8 @@ export default class NotificationService { const response = await this.httpClient.get( NODE_API.GET_AVAILABLE_FEATURES ); - const config_type_list = response.allowed_config_type_list as Array< - keyof typeof CHANNEL_TYPE - >; - const channelTypes: Partial = {}; - for (let i = 0; i < config_type_list.length; i++) { - const channel = config_type_list[i]; - if (!CHANNEL_TYPE[channel]) continue; - channelTypes[channel] = CHANNEL_TYPE[channel]; - } - return { - availableChannels: channelTypes, - availableConfigTypes: config_type_list as string[], - tooltipSupport: - _.get(response, ['plugin_features', 'tooltip_support']) === 'true', - }; + + return response; } catch (error) { console.error('error fetching available features', error); return null; diff --git a/server/routes/configRoutes.ts b/server/routes/configRoutes.ts index 5942399c..8da26cf2 100644 --- a/server/routes/configRoutes.ts +++ b/server/routes/configRoutes.ts @@ -10,6 +10,8 @@ import { } from '../../../../src/core/server'; import { NODE_API } from '../../common'; import { joinRequestParams } from '../utils/helper'; +import _ from 'lodash'; +import { CHANNEL_TYPE } from '../../public/utils/constants'; export function configRoutes(router: IRouter) { router.get( @@ -210,7 +212,24 @@ export function configRoutes(router: IRouter) { const resp = await client.callAsCurrentUser( 'notifications.getServerFeatures' ); - return response.ok({ body: resp }); + const config_type_list = resp.allowed_config_type_list as Array< + keyof typeof CHANNEL_TYPE + >; + const channelTypes: Partial = {}; + + for (let channel of config_type_list) { + if (CHANNEL_TYPE[channel]) { + channelTypes[channel] = CHANNEL_TYPE[channel] + } + } + + const availableFeature = { + availableChannels: channelTypes, + availableConfigTypes: config_type_list as string[], + tooltipSupport: + _.get(response, ['plugin_features', 'tooltip_support']) === 'true', + }; + return response.ok({ body: availableFeature }); } catch (error) { return response.custom({ statusCode: error.statusCode || 500,