Skip to content

Commit 481c652

Browse files
committed
fix: CurrentContext/Namespace widgets stuck Loading in Popup windows
1 parent 4de36e3 commit 481c652

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

plugins/plugin-kubectl/components/src/CurrentContext.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@
1616

1717
import React from 'react'
1818

19-
import { Events, getCurrentTab, getTab, Tab, TabState, encodeComponent, pexecInCurrentTab, i18n } from '@kui-shell/core'
19+
import {
20+
Events,
21+
CommandCompleteEvent,
22+
getCurrentTab,
23+
getTab,
24+
Tab,
25+
TabState,
26+
encodeComponent,
27+
pexecInCurrentTab,
28+
i18n
29+
} from '@kui-shell/core'
2030
import { KubeContext } from '@kui-shell/plugin-kubectl'
2131

2232
import Select from '@kui-shell/plugin-client-common/mdist/components/spi/Select'
@@ -56,6 +66,7 @@ Events.eventBus.once('/tab/new', () => (ready = true))
5666

5767
export default class CurrentContext extends React.PureComponent<Props, State> {
5868
private readonly handler = this.reportCurrentContext.bind(this)
69+
private readonly handlerForCommandComplete = this.reportCurrentContextFromCommandComplete.bind(this)
5970
private readonly handlerForConfigChange = this.getCurrentContextFromChange.bind(this)
6071
private readonly handlerNotCallingKubectl = this.getCurrentContextFromTab.bind(this)
6172

@@ -163,6 +174,10 @@ export default class CurrentContext extends React.PureComponent<Props, State> {
163174
})
164175
}
165176

177+
private async reportCurrentContextFromCommandComplete(evt: CommandCompleteEvent) {
178+
this.reportCurrentContext(evt.tab)
179+
}
180+
166181
private async reportCurrentContext(idx?: Tab | number | string) {
167182
if (this.unmounted) {
168183
return
@@ -303,7 +318,7 @@ export default class CurrentContext extends React.PureComponent<Props, State> {
303318
}
304319
Events.eventBus.on('/tab/switch/request/done', this.handlerNotCallingKubectl)
305320

306-
Events.eventBus.onAnyCommandComplete(this.handler)
321+
Events.eventBus.onAnyCommandComplete(this.handlerForCommandComplete)
307322

308323
import('@kui-shell/plugin-kubectl').then(_ => _.onKubectlConfigChangeEvents(this.handlerForConfigChange))
309324
}
@@ -313,7 +328,7 @@ export default class CurrentContext extends React.PureComponent<Props, State> {
313328
this.unmounted = true
314329
Events.eventBus.off('/tab/new', this.handler)
315330
Events.eventBus.off('/tab/switch/request/done', this.handlerNotCallingKubectl)
316-
Events.eventBus.offAnyCommandComplete(this.handler)
331+
Events.eventBus.offAnyCommandComplete(this.handlerForCommandComplete)
317332
import('@kui-shell/plugin-kubectl').then(_ => _.offKubectlConfigChangeEvents(this.handlerForConfigChange))
318333
}
319334

plugins/plugin-kubectl/components/src/CurrentNamespace.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import TextWithIconWidget, {
2323
Options as TextWithIconWidgetOptions
2424
} from '@kui-shell/plugin-client-common/mdist/components/Client/StatusStripe/TextWithIconWidget'
2525

26-
import { Events, i18n, getTab, Tab, TabState, pexecInCurrentTab } from '@kui-shell/core'
26+
import { Events, CommandCompleteEvent, i18n, getTab, Tab, TabState, pexecInCurrentTab } from '@kui-shell/core'
2727

2828
import { KubeContext } from '@kui-shell/plugin-kubectl'
2929

@@ -42,6 +42,7 @@ const strings = i18n('plugin-kubectl')
4242

4343
export default class CurrentNamespace extends React.PureComponent<Props, State> {
4444
private readonly handler = this.reportCurrentNamespace.bind(this)
45+
private readonly handlerForCommandComplete = this.reportCurrentNamespaceFromCommandComplete.bind(this)
4546
private readonly handlerNotCallingKubectl = this.getCurrentNamespaceFromTab.bind(this)
4647

4748
public constructor(props: Props) {
@@ -69,6 +70,10 @@ export default class CurrentNamespace extends React.PureComponent<Props, State>
6970
return last && now - last < 250
7071
}
7172

73+
private async reportCurrentNamespaceFromCommandComplete(evt: CommandCompleteEvent) {
74+
this.reportCurrentNamespace(evt.tab)
75+
}
76+
7277
private async reportCurrentNamespace(idx?: Tab | number | string) {
7378
if (this.unmounted) {
7479
return
@@ -172,7 +177,7 @@ export default class CurrentNamespace extends React.PureComponent<Props, State>
172177
}
173178
Events.eventBus.on('/tab/switch/request/done', this.handlerNotCallingKubectl)
174179

175-
Events.eventBus.onAnyCommandComplete(this.handler)
180+
Events.eventBus.onAnyCommandComplete(this.handlerForCommandComplete)
176181
import('@kui-shell/plugin-kubectl').then(_ => _.onKubectlConfigChangeEvents(this.handler))
177182
}
178183

@@ -192,7 +197,7 @@ export default class CurrentNamespace extends React.PureComponent<Props, State>
192197
Events.eventBus.off('/tab/new', this.handler)
193198
Events.eventBus.off('/tab/switch/request/done', this.handlerNotCallingKubectl)
194199

195-
Events.eventBus.offAnyCommandComplete(this.handler)
200+
Events.eventBus.offAnyCommandComplete(this.handlerForCommandComplete)
196201
import('@kui-shell/plugin-kubectl').then(_ => _.offKubectlConfigChangeEvents(this.handler))
197202
}
198203

0 commit comments

Comments
 (0)