From f92121652cca2c9ab06e73ccdf59aa843e2a0431 Mon Sep 17 00:00:00 2001 From: Riya <69919272+riysaxen-amzn@users.noreply.github.com> Date: Wed, 26 Jun 2024 10:49:23 -0700 Subject: [PATCH] bug fix for duplicate notification channels (#981) * bug fix for duplicate notification channels Signed-off-by: Riya Saxena * bug fix for UI dropdown Signed-off-by: Riya Saxena --------- Signed-off-by: Riya Saxena (cherry picked from commit 738295f12c9fc1564f43941574eece8d3cebcfeb) --- .../CreateTrigger/components/Action/Action.js | 2 +- public/pages/CreateTrigger/utils/helper.js | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/public/pages/CreateTrigger/components/Action/Action.js b/public/pages/CreateTrigger/components/Action/Action.js index 8a1d1292a..4de237542 100644 --- a/public/pages/CreateTrigger/components/Action/Action.js +++ b/public/pages/CreateTrigger/components/Action/Action.js @@ -158,7 +158,7 @@ const Action = ({ ), - rowHeight: 45, + rowHeight: 30, isLoading: !flyoutMode && loadingDestinations, }} /> diff --git a/public/pages/CreateTrigger/utils/helper.js b/public/pages/CreateTrigger/utils/helper.js index a7bd698f8..b8f95a6a5 100644 --- a/public/pages/CreateTrigger/utils/helper.js +++ b/public/pages/CreateTrigger/utils/helper.js @@ -18,14 +18,30 @@ import { import moment from 'moment'; import { formikToTrigger } from '../containers/CreateTrigger/utils/formikToTrigger'; -export const getChannelOptions = (channels) => - channels.map((channel) => ({ - key: channel.type, - label: channel.type, - options: channels - .filter((local_channel) => local_channel.type === channel.type) - .map((option) => ({ key: option.value, ...option })), - })); +export const getChannelOptions = (channels) => { + const channelMap = {}; + + // Iterate over channels to group options by channel type + channels.forEach(channel => { + if (!channelMap[channel.type]) { + channelMap[channel.type] = { + key: channel.type, + label: channel.type, + options: [] + }; + } + // Add the option to the corresponding channel type + channelMap[channel.type].options.push({ + key: channel.value, + ...channel + }); + }); + + // Convert the channelMap object to an array of values + const channelOptions = Object.values(channelMap); + + return channelOptions; +}; // Custom Webhooks for Destinations used `custom_webhook` for the type whereas Notification Channels use 'webhook' // This conversion ensures Notifications' nomenclature is used for the labeling for consistency