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

[Backport 2.14] Refactored code to account for notifications server features API change #956

Open
wants to merge 1 commit into
base: 2.14
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ class ConfigureActions extends React.Component {
let channels = [];
let index = 0;
const getChannels = async () => {
const config_types = await this.props.notificationService.getServerFeatures();
const serverFeatures = await this.props.notificationService.getServerFeatures();
const configTypes = Object.keys(serverFeatures.availableChannels);
const getChannelsQuery = {
from_index: index,
max_items: MAX_CHANNELS_RESULT_SIZE,
config_type: config_types,
config_type: configTypes,
sort_field: 'name',
sort_order: 'asc',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ const TriggerNotifications = ({
let channels = [];
let index = 0;
const getChannels = async () => {
const config_types = await notificationService.getServerFeatures();
const serverFeatures = await notificationService.getServerFeatures();
const configTypes = Object.keys(serverFeatures.availableChannels);
const getChannelsQuery = {
from_index: index,
max_items: MAX_CHANNELS_RESULT_SIZE,
config_type: config_types,
config_type: configTypes,
sort_field: 'name',
sort_order: 'asc',
};
Expand Down
12 changes: 8 additions & 4 deletions public/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { HttpFetchQuery, HttpSetup } from '../../../../src/core/public';
import { ChannelItemType } from './models/interfaces';
import { ChannelItemType, NotificationServerFeatures } from './models/interfaces';
import { configListToChannels, configToChannel } from './utils/helper';

interface ConfigsResponse {
Expand All @@ -26,15 +26,19 @@ export default class NotificationService {
this.httpClient = httpClient;
}

getServerFeatures = async (): Promise<Array<String>> => {
getServerFeatures = async (): Promise<NotificationServerFeatures> => {
try {
const response = await this.httpClient.get(
NODE_API.GET_AVAILABLE_FEATURES
);
return response.allowed_config_type_list as Array<String>;
return response as NotificationServerFeatures;
} catch (error) {
console.error('error fetching available features', error);
return [];
return {
availableChannels: {},
availableConfigTypes: [],
tooltipSupport: false
};
}
};

Expand Down
6 changes: 6 additions & 0 deletions public/services/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ export interface ChannelItemType extends ConfigType {
};
};
}

export interface NotificationServerFeatures {
availableChannels: Partial<typeof CHANNEL_TYPE>;
availableConfigTypes: string[]; // available backend config types
tooltipSupport: boolean; // if true, IAM role for SNS is optional and helper text should be available
}
Loading