From 51b55ea3ee710188fae718795a21759fe0a7e8e6 Mon Sep 17 00:00:00 2001 From: Riya <69919272+riysaxen-amzn@users.noreply.github.com> Date: Fri, 26 Apr 2024 18:53:49 -0700 Subject: [PATCH] Backport/backport 192 to 2.x (#199) Signed-off-by: Riya Saxena --- .../MDSEnabledComponent/MDSEnabledComponent.tsx | 4 ++++ public/pages/Channels/Channels.tsx | 8 +++++++- .../Emails/components/tables/RecipientGroupsTable.tsx | 8 +++++++- public/pages/Emails/components/tables/SESSendersTable.tsx | 8 +++++++- public/pages/Emails/components/tables/SendersTable.tsx | 8 +++++++- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx b/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx index 75d0b9a7..79522bc1 100644 --- a/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx +++ b/public/components/MDSEnabledComponent/MDSEnabledComponent.tsx @@ -31,4 +31,8 @@ export function isDataSourceChanged(prevProps, currentProps) { return false; } +export function isDataSourceError(error) { + return (error.body && error.body.message && error.body.message.includes("Data Source Error")); +} + diff --git a/public/pages/Channels/Channels.tsx b/public/pages/Channels/Channels.tsx index df6afc58..f472761a 100644 --- a/public/pages/Channels/Channels.tsx +++ b/public/pages/Channels/Channels.tsx @@ -39,7 +39,10 @@ import { ChannelActions } from './components/ChannelActions'; import { ChannelControls } from './components/ChannelControls'; import { ChannelFiltersType } from './types'; import { DataSourceMenuProperties } from '../../services/DataSourceMenuContext'; -import MDSEnabledComponent, { isDataSourceChanged } from '../../components/MDSEnabledComponent/MDSEnabledComponent'; +import MDSEnabledComponent, { + isDataSourceChanged, + isDataSourceError, +} from '../../components/MDSEnabledComponent/MDSEnabledComponent'; interface ChannelsProps extends RouteComponentProps, DataSourceMenuProperties { notificationService: NotificationService; @@ -158,6 +161,9 @@ export class Channels extends MDSEnabledComponent ); this.setState({ items: channels.items, total: channels.total }); } catch (error) { + if (isDataSourceError(error)) { + this.setState({ items: [], total: 0 }); + } this.context.notifications.toasts.addDanger( getErrorMessage(error, 'There was a problem loading channels.') ); diff --git a/public/pages/Emails/components/tables/RecipientGroupsTable.tsx b/public/pages/Emails/components/tables/RecipientGroupsTable.tsx index b23b7c7c..50205e04 100644 --- a/public/pages/Emails/components/tables/RecipientGroupsTable.tsx +++ b/public/pages/Emails/components/tables/RecipientGroupsTable.tsx @@ -34,7 +34,10 @@ import { getErrorMessage } from '../../../../utils/helpers'; import { DetailsListModal } from '../../../Channels/components/modals/DetailsListModal'; import { DEFAULT_PAGE_SIZE_OPTIONS } from '../../../Notifications/utils/constants'; import { DeleteRecipientGroupModal } from '../modals/DeleteRecipientGroupModal'; -import { isDataSourceChanged } from '../../../../components/MDSEnabledComponent/MDSEnabledComponent'; +import { + isDataSourceError, + isDataSourceChanged, +} from '../../../../components/MDSEnabledComponent/MDSEnabledComponent'; interface RecipientGroupsTableProps { coreContext: CoreStart; @@ -166,6 +169,9 @@ export class RecipientGroupsTable extends Component< total: recipientGroups.total, }); } catch (error) { + if (isDataSourceError(error)) { + this.setState({ items: [], total: 0 }); + } this.props.coreContext.notifications.toasts.addDanger( getErrorMessage(error, 'There was a problem loading recipient groups.') ); diff --git a/public/pages/Emails/components/tables/SESSendersTable.tsx b/public/pages/Emails/components/tables/SESSendersTable.tsx index 7500d2e4..bf749009 100644 --- a/public/pages/Emails/components/tables/SESSendersTable.tsx +++ b/public/pages/Emails/components/tables/SESSendersTable.tsx @@ -32,7 +32,10 @@ import { ROUTES } from '../../../../utils/constants'; import { getErrorMessage } from '../../../../utils/helpers'; import { DEFAULT_PAGE_SIZE_OPTIONS } from '../../../Notifications/utils/constants'; import { DeleteSenderModal } from '../modals/DeleteSenderModal'; -import { isDataSourceChanged } from '../../../../components/MDSEnabledComponent/MDSEnabledComponent'; +import { + isDataSourceError, + isDataSourceChanged, +} from '../../../../components/MDSEnabledComponent/MDSEnabledComponent'; interface SESSendersTableProps { coreContext: CoreStart; @@ -130,6 +133,9 @@ export class SESSendersTable extends Component< ); this.setState({ items: senders.items, total: senders.total }); } catch (error) { + if (isDataSourceError(error)) { + this.setState({ items: [], total: 0 }); + } this.props.coreContext.notifications.toasts.addDanger( getErrorMessage(error, 'There was a problem loading SES senders.') ); diff --git a/public/pages/Emails/components/tables/SendersTable.tsx b/public/pages/Emails/components/tables/SendersTable.tsx index 32f38c57..ebbf5d9d 100644 --- a/public/pages/Emails/components/tables/SendersTable.tsx +++ b/public/pages/Emails/components/tables/SendersTable.tsx @@ -32,7 +32,10 @@ import { SendersTableControls, SendersTableControlsFilterType, } from './SendersTableControls'; -import { isDataSourceChanged } from '../../../../components/MDSEnabledComponent/MDSEnabledComponent'; +import { + isDataSourceError, + isDataSourceChanged, +} from '../../../../components/MDSEnabledComponent/MDSEnabledComponent'; interface SendersTableProps { coreContext: CoreStart; @@ -151,6 +154,9 @@ export class SendersTable extends Component< ); this.setState({ items: senders.items, total: senders.total }); } catch (error) { + if (isDataSourceError(error)) { + this.setState({ items: [], total: 0 }); + } this.props.coreContext.notifications.toasts.addDanger( getErrorMessage(error, 'There was a problem loading SMTP senders.') );