@@ -46,6 +46,8 @@ enum GlobalWritesActionTypes {
4646 UnmanagingNamespaceStarted = 'global-writes/UnmanagingNamespaceStarted' ,
4747 UnmanagingNamespaceFinished = 'global-writes/UnmanagingNamespaceFinished' ,
4848 UnmanagingNamespaceErrored = 'global-writes/UnmanagingNamespaceErrored' ,
49+
50+ PluginTitleVisibilityChanged = 'global-writes/PluginTitleVisibilityChanged' ,
4951}
5052
5153type ManagedNamespaceFetchedAction = {
@@ -115,6 +117,11 @@ type UnmanagingNamespaceErroredAction = {
115117 type : GlobalWritesActionTypes . UnmanagingNamespaceErrored ;
116118} ;
117119
120+ type PluginTitleVisibilityChangedAction = {
121+ type : GlobalWritesActionTypes . PluginTitleVisibilityChanged ;
122+ isVisible : boolean ;
123+ } ;
124+
118125export enum ShardingStatuses {
119126 /**
120127 * Initial status, no information available yet.
@@ -193,6 +200,7 @@ export type RootState = {
193200 namespace : string ;
194201 managedNamespace ?: ManagedNamespace ;
195202 shardZones : ShardZoneData [ ] ;
203+ isPluginTitleVisible : boolean ;
196204} & (
197205 | {
198206 status : ShardingStatuses . NOT_READY ;
@@ -245,6 +253,7 @@ const initialState: RootState = {
245253 namespace : '' ,
246254 status : ShardingStatuses . NOT_READY ,
247255 shardZones : [ ] ,
256+ isPluginTitleVisible : true ,
248257} ;
249258
250259const reducer : Reducer < RootState , Action > = ( state = initialState , action ) => {
@@ -472,6 +481,19 @@ const reducer: Reducer<RootState, Action> = (state = initialState, action) => {
472481 } ;
473482 }
474483
484+ if (
485+ isAction < PluginTitleVisibilityChangedAction > (
486+ action ,
487+ GlobalWritesActionTypes . PluginTitleVisibilityChanged
488+ )
489+ ) {
490+ if ( state . isPluginTitleVisible === action . isVisible ) return state ;
491+ return {
492+ ...state ,
493+ isPluginTitleVisible : action . isVisible ,
494+ } ;
495+ }
496+
475497 return state ;
476498} ;
477499
@@ -646,7 +668,11 @@ const pollForShardKey = (): GlobalWritesThunkAction<
646668 NextPollingTimeoutSetAction
647669> => {
648670 return ( dispatch , getState ) => {
649- if ( getState ( ) . pollingTimeout ) {
671+ const { pollingTimeout, isPluginTitleVisible } = getState ( ) ;
672+ if (
673+ ! isPluginTitleVisible || // user is not in the Collection Workspace
674+ pollingTimeout // prevent double polling
675+ ) {
650676 return ;
651677 }
652678 const timeout = setTimeout (
@@ -753,6 +779,30 @@ export const fetchShardingZones = (): GlobalWritesThunkAction<
753779 } ;
754780} ;
755781
782+ export const setPluginTitleVisibility = (
783+ isVisible : boolean
784+ ) : GlobalWritesThunkAction < void , PluginTitleVisibilityChangedAction > => {
785+ return ( dispatch , getState ) => {
786+ const {
787+ status,
788+ pollingTimeout,
789+ isPluginTitleVisible : previousIsVisible ,
790+ } = getState ( ) ;
791+ dispatch ( {
792+ type : GlobalWritesActionTypes . PluginTitleVisibilityChanged ,
793+ isVisible,
794+ } ) ;
795+ if (
796+ isVisible &&
797+ ! previousIsVisible &&
798+ status === ShardingStatuses . SHARDING &&
799+ ! pollingTimeout
800+ ) {
801+ dispatch ( pollForShardKey ( ) ) ;
802+ }
803+ } ;
804+ } ;
805+
756806export const unmanageNamespace = ( ) : GlobalWritesThunkAction <
757807 Promise < void > ,
758808 | UnmanagingNamespaceStartedAction
0 commit comments