Skip to content

Commit

Permalink
Moved enrichment of server features to server side (#181)
Browse files Browse the repository at this point in the history
* moved enrichment of server features to server side

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

* simplified code

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>

---------

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
(cherry picked from commit 1fc2abe)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Apr 26, 2024
1 parent 577c1df commit 5f825d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
19 changes: 2 additions & 17 deletions public/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -14,7 +13,6 @@ import {
SenderType,
SESSenderItemType,
} from '../../models/interfaces';
import { CHANNEL_TYPE } from '../utils/constants';
import {
configListToChannels,
configListToRecipientGroups,
Expand Down Expand Up @@ -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<typeof CHANNEL_TYPE> = {};
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;
Expand Down
21 changes: 20 additions & 1 deletion server/routes/configRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<typeof CHANNEL_TYPE> = {};

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,
Expand Down

0 comments on commit 5f825d8

Please sign in to comment.