Skip to content

Commit

Permalink
refactored code to account for notifications server features API chan…
Browse files Browse the repository at this point in the history
…ge (opensearch-project#916)

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
(cherry picked from commit c239ded)
  • Loading branch information
amsiglan authored and riysaxen-amzn committed Jun 6, 2024
1 parent 457c66c commit 58761a0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
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
}

0 comments on commit 58761a0

Please sign in to comment.