diff --git a/apps/jetstream/src/app/components/platform-event-monitor/PlatformEventMonitor.tsx b/apps/jetstream/src/app/components/platform-event-monitor/PlatformEventMonitor.tsx index 7edfefcac..124b35fed 100644 --- a/apps/jetstream/src/app/components/platform-event-monitor/PlatformEventMonitor.tsx +++ b/apps/jetstream/src/app/components/platform-event-monitor/PlatformEventMonitor.tsx @@ -1,6 +1,6 @@ import { css } from '@emotion/react'; import { TITLES } from '@jetstream/shared/constants'; -import { useTitle } from '@jetstream/shared/ui-utils'; +import { useNonInitialEffect, useTitle } from '@jetstream/shared/ui-utils'; import { SplitWrapper as Split } from '@jetstream/splitjs'; import { ListItem, ListItemGroup, SalesforceOrgUi } from '@jetstream/types'; import { AutoFullHeightContainer } from '@jetstream/ui'; @@ -46,6 +46,10 @@ export const PlatformEventMonitor: FunctionComponent }; }, []); + useNonInitialEffect(() => { + setSelectedPublishEvent(null); + }, [selectedOrg]); + useEffect(() => { const subscriptionEvents: ListItemGroup[] = [ { @@ -123,7 +127,7 @@ export const PlatformEventMonitor: FunctionComponent const hasErrorOrNoEvents = !hasPlatformEvents || platformEventFetchError; return ( - + {hasErrorOrNoEvents && ( { - logger.warn('[PLATFORM EVENT][ERROR] unsubscribing'); - fireToast({ type: 'error', message: `Error subscribing to event: ${message.subscription}. ${message.error}` }); - setMessagesByChannel((item) => { - return Object.keys(item) - .filter((key) => key !== message.subscription) - .reduce((output: MessagesByChannel, key) => { - output[key] = item[key]; - return output; - }, {}); - }); + logger.warn('[PLATFORM EVENT][ERROR]', message); + if (message.subscription) { + fireToast({ type: 'error', message: `Error subscribing to event: ${message.subscription}. ${message.error}` }); + setMessagesByChannel((item) => { + return Object.keys(item) + .filter((key) => key !== message.subscription) + .reduce((output: MessagesByChannel, key) => { + output[key] = item[key]; + return output; + }, {}); + }); + } else if (message.channel === '/meta/handshake') { + fireToast({ type: 'error', message: `Error subscribing to event: ${message.failure?.reason || 'Unknown reason'}.` }); + } else { + fireToast({ type: 'error', message: `There was an unknown error subscribing to the event` }); + } }, []); const subscribe = useCallback(