diff --git a/plugins/plugin-kubectl/components/src/CurrentContext.tsx b/plugins/plugin-kubectl/components/src/CurrentContext.tsx index 97c1936bfda..3478d4e7e4e 100644 --- a/plugins/plugin-kubectl/components/src/CurrentContext.tsx +++ b/plugins/plugin-kubectl/components/src/CurrentContext.tsx @@ -16,7 +16,17 @@ import React from 'react' -import { Events, getCurrentTab, getTab, Tab, TabState, encodeComponent, pexecInCurrentTab, i18n } from '@kui-shell/core' +import { + Events, + CommandCompleteEvent, + getCurrentTab, + getTab, + Tab, + TabState, + encodeComponent, + pexecInCurrentTab, + i18n +} from '@kui-shell/core' import { KubeContext } from '@kui-shell/plugin-kubectl' import Select from '@kui-shell/plugin-client-common/mdist/components/spi/Select' @@ -56,6 +66,7 @@ Events.eventBus.once('/tab/new', () => (ready = true)) export default class CurrentContext extends React.PureComponent { private readonly handler = this.reportCurrentContext.bind(this) + private readonly handlerForCommandComplete = this.reportCurrentContextFromCommandComplete.bind(this) private readonly handlerForConfigChange = this.getCurrentContextFromChange.bind(this) private readonly handlerNotCallingKubectl = this.getCurrentContextFromTab.bind(this) @@ -163,6 +174,10 @@ export default class CurrentContext extends React.PureComponent { }) } + private async reportCurrentContextFromCommandComplete(evt: CommandCompleteEvent) { + this.reportCurrentContext(evt.tab) + } + private async reportCurrentContext(idx?: Tab | number | string) { if (this.unmounted) { return @@ -303,7 +318,7 @@ export default class CurrentContext extends React.PureComponent { } Events.eventBus.on('/tab/switch/request/done', this.handlerNotCallingKubectl) - Events.eventBus.onAnyCommandComplete(this.handler) + Events.eventBus.onAnyCommandComplete(this.handlerForCommandComplete) import('@kui-shell/plugin-kubectl').then(_ => _.onKubectlConfigChangeEvents(this.handlerForConfigChange)) } @@ -313,7 +328,7 @@ export default class CurrentContext extends React.PureComponent { this.unmounted = true Events.eventBus.off('/tab/new', this.handler) Events.eventBus.off('/tab/switch/request/done', this.handlerNotCallingKubectl) - Events.eventBus.offAnyCommandComplete(this.handler) + Events.eventBus.offAnyCommandComplete(this.handlerForCommandComplete) import('@kui-shell/plugin-kubectl').then(_ => _.offKubectlConfigChangeEvents(this.handlerForConfigChange)) } diff --git a/plugins/plugin-kubectl/components/src/CurrentNamespace.tsx b/plugins/plugin-kubectl/components/src/CurrentNamespace.tsx index 8c3ec060c94..469caba0374 100644 --- a/plugins/plugin-kubectl/components/src/CurrentNamespace.tsx +++ b/plugins/plugin-kubectl/components/src/CurrentNamespace.tsx @@ -23,7 +23,7 @@ import TextWithIconWidget, { Options as TextWithIconWidgetOptions } from '@kui-shell/plugin-client-common/mdist/components/Client/StatusStripe/TextWithIconWidget' -import { Events, i18n, getTab, Tab, TabState, pexecInCurrentTab } from '@kui-shell/core' +import { Events, CommandCompleteEvent, i18n, getTab, Tab, TabState, pexecInCurrentTab } from '@kui-shell/core' import { KubeContext } from '@kui-shell/plugin-kubectl' @@ -42,6 +42,7 @@ const strings = i18n('plugin-kubectl') export default class CurrentNamespace extends React.PureComponent { private readonly handler = this.reportCurrentNamespace.bind(this) + private readonly handlerForCommandComplete = this.reportCurrentNamespaceFromCommandComplete.bind(this) private readonly handlerNotCallingKubectl = this.getCurrentNamespaceFromTab.bind(this) public constructor(props: Props) { @@ -69,6 +70,10 @@ export default class CurrentNamespace extends React.PureComponent return last && now - last < 250 } + private async reportCurrentNamespaceFromCommandComplete(evt: CommandCompleteEvent) { + this.reportCurrentNamespace(evt.tab) + } + private async reportCurrentNamespace(idx?: Tab | number | string) { if (this.unmounted) { return @@ -172,7 +177,7 @@ export default class CurrentNamespace extends React.PureComponent } Events.eventBus.on('/tab/switch/request/done', this.handlerNotCallingKubectl) - Events.eventBus.onAnyCommandComplete(this.handler) + Events.eventBus.onAnyCommandComplete(this.handlerForCommandComplete) import('@kui-shell/plugin-kubectl').then(_ => _.onKubectlConfigChangeEvents(this.handler)) } @@ -192,7 +197,7 @@ export default class CurrentNamespace extends React.PureComponent Events.eventBus.off('/tab/new', this.handler) Events.eventBus.off('/tab/switch/request/done', this.handlerNotCallingKubectl) - Events.eventBus.offAnyCommandComplete(this.handler) + Events.eventBus.offAnyCommandComplete(this.handlerForCommandComplete) import('@kui-shell/plugin-kubectl').then(_ => _.offKubectlConfigChangeEvents(this.handler)) }