Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved enrichment of server features to server side #181

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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<
amsiglan marked this conversation as resolved.
Show resolved Hide resolved
keyof typeof CHANNEL_TYPE
>;
const channelTypes: Partial<typeof CHANNEL_TYPE> = {};
amsiglan marked this conversation as resolved.
Show resolved Hide resolved

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
Loading