Skip to content

Commit c239ded

Browse files
authored
refactored code to account for notifications server features API change (#916)
Signed-off-by: Amardeepsingh Siglani <[email protected]>
1 parent f2fe1fe commit c239ded

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

public/pages/CreateTrigger/containers/ConfigureActions/ConfigureActions.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,12 @@ class ConfigureActions extends React.Component {
121121
let channels = [];
122122
let index = 0;
123123
const getChannels = async () => {
124-
const config_types = await this.props.notificationService.getServerFeatures();
124+
const serverFeatures = await this.props.notificationService.getServerFeatures();
125+
const configTypes = Object.keys(serverFeatures.availableChannels);
125126
const getChannelsQuery = {
126127
from_index: index,
127128
max_items: MAX_CHANNELS_RESULT_SIZE,
128-
config_type: config_types,
129+
config_type: configTypes,
129130
sort_field: 'name',
130131
sort_order: 'asc',
131132
};

public/pages/CreateTrigger/containers/DefineCompositeLevelTrigger/TriggerNotifications.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ const TriggerNotifications = ({
5151
let channels = [];
5252
let index = 0;
5353
const getChannels = async () => {
54-
const config_types = await notificationService.getServerFeatures();
54+
const serverFeatures = await notificationService.getServerFeatures();
55+
const configTypes = Object.keys(serverFeatures.availableChannels);
5556
const getChannelsQuery = {
5657
from_index: index,
5758
max_items: MAX_CHANNELS_RESULT_SIZE,
58-
config_type: config_types,
59+
config_type: configTypes,
5960
sort_field: 'name',
6061
sort_order: 'asc',
6162
};

public/services/NotificationService.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { HttpFetchQuery, HttpSetup } from '../../../../src/core/public';
7-
import { ChannelItemType } from './models/interfaces';
7+
import { ChannelItemType, NotificationServerFeatures } from './models/interfaces';
88
import { configListToChannels, configToChannel } from './utils/helper';
99

1010
interface ConfigsResponse {
@@ -26,15 +26,19 @@ export default class NotificationService {
2626
this.httpClient = httpClient;
2727
}
2828

29-
getServerFeatures = async (): Promise<Array<String>> => {
29+
getServerFeatures = async (): Promise<NotificationServerFeatures> => {
3030
try {
3131
const response = await this.httpClient.get(
3232
NODE_API.GET_AVAILABLE_FEATURES
3333
);
34-
return response.allowed_config_type_list as Array<String>;
34+
return response as NotificationServerFeatures;
3535
} catch (error) {
3636
console.error('error fetching available features', error);
37-
return [];
37+
return {
38+
availableChannels: {},
39+
availableConfigTypes: [],
40+
tooltipSupport: false
41+
};
3842
}
3943
};
4044

public/services/models/interfaces.ts

+6
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ export interface ChannelItemType extends ConfigType {
3737
};
3838
};
3939
}
40+
41+
export interface NotificationServerFeatures {
42+
availableChannels: Partial<typeof CHANNEL_TYPE>;
43+
availableConfigTypes: string[]; // available backend config types
44+
tooltipSupport: boolean; // if true, IAM role for SNS is optional and helper text should be available
45+
}

0 commit comments

Comments
 (0)