diff --git a/common/constants.ts b/common/constants.ts new file mode 100644 index 00000000..2efda6a2 --- /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; + }; \ No newline at end of file diff --git a/models/interfaces.ts b/models/interfaces.ts index dbe196f1..2197f38c 100644 --- a/models/interfaces.ts +++ b/models/interfaces.ts @@ -7,8 +7,8 @@ import { Direction } from '@elastic/eui'; import { WebhookMethodType } from '../public/pages/Channels/types'; import { CHANNEL_TYPE, - ENCRYPTION_TYPE, -} from '../public/utils/constants'; +} from '../common/constants'; +import {ENCRYPTION_TYPE} from '../public/utils/constants' export interface ChannelStatus { config_id: string; diff --git a/public/pages/Channels/Channels.tsx b/public/pages/Channels/Channels.tsx index 1e3ca6bd..64a25484 100644 --- a/public/pages/Channels/Channels.tsx +++ b/public/pages/Channels/Channels.tsx @@ -28,9 +28,9 @@ 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'; @@ -107,6 +107,7 @@ export class Channels extends Component { } async componentDidMount() { + console.log("in channle this.context", this.context ) this.context.chrome.setBreadcrumbs([ BREADCRUMBS.NOTIFICATIONS, BREADCRUMBS.CHANNELS, diff --git a/public/pages/Channels/components/ChannelControls.tsx b/public/pages/Channels/components/ChannelControls.tsx index 7537ca55..262e011e 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'; @@ -28,12 +28,14 @@ interface ChannelControlsProps { export const ChannelControls = (props: ChannelControlsProps) => { const mainStateContext = useContext(MainContext)!; + const [isStatePopoverOpen, setIsStatePopoverOpen] = useState(false); const [stateItems, setStateItems] = useState([ { field: 'true', display: 'Active', checked: 'off' }, { field: 'false', display: 'Muted', checked: 'off' }, ]); const [isTypePopoverOpen, setIsTypePopoverOpen] = useState(false); + const [typeItems, setTypeItems] = useState( Object.entries(mainStateContext.availableChannels).map(([key, value]) => ({ field: key, @@ -41,6 +43,7 @@ export const ChannelControls = (props: ChannelControlsProps) => { checked: 'off', })) ); + console.log("typeItems", typeItems) useEffect(() => { const newItems = typeItems.filter( 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..787253d5 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'; diff --git a/public/utils/constants.ts b/public/utils/constants.ts index 81691978..78ca01f9 100644 --- a/public/utils/constants.ts +++ b/public/utils/constants.ts @@ -48,30 +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', diff --git a/server/routes/configRoutes.ts b/server/routes/configRoutes.ts index 8da26cf2..ef8c712a 100644 --- a/server/routes/configRoutes.ts +++ b/server/routes/configRoutes.ts @@ -11,7 +11,7 @@ import { import { NODE_API } from '../../common'; import { joinRequestParams } from '../utils/helper'; import _ from 'lodash'; -import { CHANNEL_TYPE } from '../../public/utils/constants'; +import { CHANNEL_TYPE } from '../../common/constants'; export function configRoutes(router: IRouter) { router.get( @@ -212,17 +212,20 @@ 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[],