From 9f93295419e99fc2036d8dd7897f82625fd0f81f Mon Sep 17 00:00:00 2001 From: Riya <69919272+riysaxen-amzn@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:08:49 -0700 Subject: [PATCH 1/4] Fix broken osd functional test repo (#189) * moved constants to common folder Signed-off-by: Riya Saxena * fix broken osd functionaltest Repo Signed-off-by: Riya Saxena * fixing the UT's Signed-off-by: Riya Saxena * fixing the UT's Signed-off-by: Riya Saxena --------- Signed-off-by: Riya Saxena Signed-off-by: Riya <69919272+riysaxen-amzn@users.noreply.github.com> (cherry picked from commit e59708146ddb77b350a9b79a465af3bd5725892b) --- common/constants.ts | 23 +++++++++++++++++ models/interfaces.ts | 4 ++- public/pages/Channels/Channels.tsx | 4 ++- .../Channels/components/ChannelControls.tsx | 2 +- .../details/ChannelSettingsDetails.tsx | 2 +- public/pages/CreateChannel/CreateChannel.tsx | 3 +-- public/pages/Main/Main.tsx | 5 ++-- public/services/NotificationService.ts | 2 +- public/utils/constants.ts | 25 ------------------- server/routes/configRoutes.ts | 23 +++++++++++++++++ test/mocks/serviceMock.ts | 2 +- 11 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 common/constants.ts diff --git a/common/constants.ts b/common/constants.ts new file mode 100644 index 00000000..f9bb6cd4 --- /dev/null +++ b/common/constants.ts @@ -0,0 +1,23 @@ +export const BACKEND_CHANNEL_TYPE = Object.freeze({ + SLACK: 'slack', + EMAIL: 'email', + CHIME: 'chime', + MICROSOFT_TEAMS: 'microsoft_teams', + CUSTOM_WEBHOOK: 'webhook', + SNS: 'sns', +}); +export const CHANNEL_TYPE = Object.freeze({ + [BACKEND_CHANNEL_TYPE.SLACK]: 'Slack', + [BACKEND_CHANNEL_TYPE.EMAIL]: 'Email', + [BACKEND_CHANNEL_TYPE.CHIME]: 'Chime', + [BACKEND_CHANNEL_TYPE.MICROSOFT_TEAMS]: 'Microsoft Teams', + [BACKEND_CHANNEL_TYPE.CUSTOM_WEBHOOK]: 'Custom webhook', + [BACKEND_CHANNEL_TYPE.SNS]: 'Amazon SNS', +}) as { + slack: string; + email: string; + chime: string; + microsoft_teams: string; + webhook: string; + sns: string; +}; diff --git a/models/interfaces.ts b/models/interfaces.ts index dbe196f1..0860f46e 100644 --- a/models/interfaces.ts +++ b/models/interfaces.ts @@ -6,9 +6,11 @@ import { Direction } from '@elastic/eui'; import { WebhookMethodType } from '../public/pages/Channels/types'; import { - CHANNEL_TYPE, ENCRYPTION_TYPE, } from '../public/utils/constants'; +import { + CHANNEL_TYPE, +} from '../common/constants'; export interface ChannelStatus { config_id: string; diff --git a/public/pages/Channels/Channels.tsx b/public/pages/Channels/Channels.tsx index 1e3ca6bd..ff679122 100644 --- a/public/pages/Channels/Channels.tsx +++ b/public/pages/Channels/Channels.tsx @@ -28,9 +28,11 @@ import { CoreServicesContext } from '../../components/coreServices'; import { NotificationService } from '../../services'; import { BREADCRUMBS, - CHANNEL_TYPE, ROUTES, } from '../../utils/constants'; +import { + CHANNEL_TYPE, +} from '../../../common/constants'; import { getErrorMessage } from '../../utils/helpers'; import { DEFAULT_PAGE_SIZE_OPTIONS } from '../Notifications/utils/constants'; import { ChannelActions } from './components/ChannelActions'; diff --git a/public/pages/Channels/components/ChannelControls.tsx b/public/pages/Channels/components/ChannelControls.tsx index 7537ca55..1405a3a6 100644 --- a/public/pages/Channels/components/ChannelControls.tsx +++ b/public/pages/Channels/components/ChannelControls.tsx @@ -16,7 +16,7 @@ import _ from 'lodash'; import React, { useContext, useEffect, useState } from 'react'; import { CHANNEL_TYPE, -} from '../../../../public/utils/constants'; +} from '../../../../common/constants'; import { MainContext } from '../../Main/Main'; import { ChannelFiltersType } from '../types'; diff --git a/public/pages/Channels/components/details/ChannelSettingsDetails.tsx b/public/pages/Channels/components/details/ChannelSettingsDetails.tsx index 2444b116..69df4f57 100644 --- a/public/pages/Channels/components/details/ChannelSettingsDetails.tsx +++ b/public/pages/Channels/components/details/ChannelSettingsDetails.tsx @@ -7,7 +7,7 @@ import { EuiLink } from '@elastic/eui'; import React from 'react'; import { ChannelItemType } from '../../../../../models/interfaces'; import { ModalConsumer } from '../../../../components/Modal'; -import { BACKEND_CHANNEL_TYPE, CHANNEL_TYPE } from '../../../../utils/constants'; +import { BACKEND_CHANNEL_TYPE, CHANNEL_TYPE } from '../../../../../common/constants'; import { deconstructEmailObject, deconstructWebhookObject, diff --git a/public/pages/CreateChannel/CreateChannel.tsx b/public/pages/CreateChannel/CreateChannel.tsx index e2686c89..69595a8d 100644 --- a/public/pages/CreateChannel/CreateChannel.tsx +++ b/public/pages/CreateChannel/CreateChannel.tsx @@ -25,12 +25,11 @@ import { ContentPanel } from '../../components/ContentPanel'; import { CoreServicesContext } from '../../components/coreServices'; import { ServicesContext } from '../../services'; import { - BACKEND_CHANNEL_TYPE, BREADCRUMBS, - CHANNEL_TYPE, CUSTOM_WEBHOOK_ENDPOINT_TYPE, ROUTES, } from '../../utils/constants'; +import {BACKEND_CHANNEL_TYPE,CHANNEL_TYPE } from '../../../common/constants' import { getErrorMessage } from '../../utils/helpers'; import { HeaderItemType, WebhookHttpType, WebhookMethodType } from '../Channels/types'; import { MainContext } from '../Main/Main'; diff --git a/public/pages/Main/Main.tsx b/public/pages/Main/Main.tsx index e6a8b7cd..6e9b4925 100644 --- a/public/pages/Main/Main.tsx +++ b/public/pages/Main/Main.tsx @@ -11,7 +11,8 @@ import { CoreServicesConsumer } from '../../components/coreServices'; import { ModalProvider, ModalRoot } from '../../components/Modal'; import { BrowserServices } from '../../models/interfaces'; import { ServicesConsumer, ServicesContext } from '../../services/services'; -import { CHANNEL_TYPE, ROUTES } from '../../utils/constants'; +import { ROUTES } from '../../utils/constants'; +import { CHANNEL_TYPE } from '../../../common/constants'; import { Channels } from '../Channels/Channels'; import { ChannelDetails } from '../Channels/components/details/ChannelDetails'; import { CreateChannel } from '../CreateChannel/CreateChannel'; @@ -78,7 +79,7 @@ export default class Main extends Component { 'ses_account', 'email_group', ], - tooltipSupport: serverFeatures.tooltipSupport, + tooltipSupport: false, }); } } diff --git a/public/services/NotificationService.ts b/public/services/NotificationService.ts index f9e166da..f673275b 100644 --- a/public/services/NotificationService.ts +++ b/public/services/NotificationService.ts @@ -14,7 +14,7 @@ import { SenderType, SESSenderItemType, } from '../../models/interfaces'; -import { CHANNEL_TYPE } from '../utils/constants'; +import { CHANNEL_TYPE } from '../../common/constants'; import { configListToChannels, configListToRecipientGroups, diff --git a/public/utils/constants.ts b/public/utils/constants.ts index 81691978..c130f423 100644 --- a/public/utils/constants.ts +++ b/public/utils/constants.ts @@ -48,31 +48,6 @@ export const BREADCRUMBS = Object.freeze({ EDIT_RECIPIENT_GROUP: { text: 'Edit recipient group' }, }); -export const BACKEND_CHANNEL_TYPE = Object.freeze({ - SLACK: 'slack', - EMAIL: 'email', - CHIME: 'chime', - MICROSOFT_TEAMS: 'microsoft_teams', - CUSTOM_WEBHOOK: 'webhook', - SNS: 'sns', -}); - -export const CHANNEL_TYPE = Object.freeze({ - [BACKEND_CHANNEL_TYPE.SLACK]: 'Slack', - [BACKEND_CHANNEL_TYPE.EMAIL]: 'Email', - [BACKEND_CHANNEL_TYPE.CHIME]: 'Chime', - [BACKEND_CHANNEL_TYPE.MICROSOFT_TEAMS]: 'Microsoft Teams', - [BACKEND_CHANNEL_TYPE.CUSTOM_WEBHOOK]: 'Custom webhook', - [BACKEND_CHANNEL_TYPE.SNS]: 'Amazon SNS', -}) as { - slack: string; - email: string; - chime: string; - microsoft_teams: string; - webhook: string; - sns: string; -}; - export const ENCRYPTION_TYPE = Object.freeze({ ssl: 'SSL/TLS', start_tls: 'STARTTLS', diff --git a/server/routes/configRoutes.ts b/server/routes/configRoutes.ts index 5942399c..df2956d9 100644 --- a/server/routes/configRoutes.ts +++ b/server/routes/configRoutes.ts @@ -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 '../../common/constants'; export function configRoutes(router: IRouter) { router.get( @@ -210,7 +212,28 @@ export function configRoutes(router: IRouter) { const resp = await client.callAsCurrentUser( 'notifications.getServerFeatures' ); +<<<<<<< HEAD return response.ok({ body: resp }); +======= + const config_type_list = resp.allowed_config_type_list as Array< + keyof typeof CHANNEL_TYPE + >; + const channelTypes: Partial = {}; + + 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 }); +>>>>>>> e597081 (Fix broken osd functional test repo (#189)) } catch (error) { return response.custom({ statusCode: error.statusCode || 500, diff --git a/test/mocks/serviceMock.ts b/test/mocks/serviceMock.ts index 24972dc1..21b937e6 100644 --- a/test/mocks/serviceMock.ts +++ b/test/mocks/serviceMock.ts @@ -6,7 +6,7 @@ import { CoreStart } from 'opensearch-dashboards/public'; import { MainState } from '../../public/pages/Main/Main'; import { NotificationService } from '../../public/services'; -import { CHANNEL_TYPE } from '../../public/utils/constants'; +import { CHANNEL_TYPE } from '../../common/constants'; import httpClientMock from './httpClientMock'; const coreServicesMock = ({ From b0cf0ec2bc9db45f57540d1dd00eb2cda726f470 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Thu, 25 Apr 2024 10:45:19 -0700 Subject: [PATCH 2/4] fix merge conflict Signed-off-by: Riya Saxena --- server/routes/configRoutes.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/routes/configRoutes.ts b/server/routes/configRoutes.ts index df2956d9..fc1caf1e 100644 --- a/server/routes/configRoutes.ts +++ b/server/routes/configRoutes.ts @@ -212,9 +212,6 @@ export function configRoutes(router: IRouter) { const resp = await client.callAsCurrentUser( 'notifications.getServerFeatures' ); -<<<<<<< HEAD - return response.ok({ body: resp }); -======= const config_type_list = resp.allowed_config_type_list as Array< keyof typeof CHANNEL_TYPE >; @@ -233,7 +230,6 @@ export function configRoutes(router: IRouter) { _.get(response, ['plugin_features', 'tooltip_support']) === 'true', }; return response.ok({ body: availableFeature }); ->>>>>>> e597081 (Fix broken osd functional test repo (#189)) } catch (error) { return response.custom({ statusCode: error.statusCode || 500, From fcaa9ea9566acd6ebfd3993e4a2ece1231a383e2 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Thu, 25 Apr 2024 11:00:21 -0700 Subject: [PATCH 3/4] revert configRoutes changes Signed-off-by: Riya Saxena --- server/routes/configRoutes.ts | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/server/routes/configRoutes.ts b/server/routes/configRoutes.ts index fc1caf1e..6e87fb0c 100644 --- a/server/routes/configRoutes.ts +++ b/server/routes/configRoutes.ts @@ -198,7 +198,7 @@ export function configRoutes(router: IRouter) { } ); - router.get( +router.get( { path: NODE_API.GET_AVAILABLE_FEATURES, validate: false, @@ -212,24 +212,7 @@ export function configRoutes(router: IRouter) { const resp = await client.callAsCurrentUser( 'notifications.getServerFeatures' ); - const config_type_list = resp.allowed_config_type_list as Array< - keyof typeof CHANNEL_TYPE - >; - const channelTypes: Partial = {}; - - 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 }); + return response.ok({ body: resp }); } catch (error) { return response.custom({ statusCode: error.statusCode || 500, From 475f9dca34a48d718233109c889e5583dee9c2e9 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Thu, 25 Apr 2024 11:02:08 -0700 Subject: [PATCH 4/4] revert configRoutes changes Signed-off-by: Riya Saxena --- server/routes/configRoutes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/routes/configRoutes.ts b/server/routes/configRoutes.ts index 6e87fb0c..5cb30ee6 100644 --- a/server/routes/configRoutes.ts +++ b/server/routes/configRoutes.ts @@ -198,7 +198,7 @@ export function configRoutes(router: IRouter) { } ); -router.get( + router.get( { path: NODE_API.GET_AVAILABLE_FEATURES, validate: false,