Skip to content

Commit

Permalink
fix: CurrentContext/Namespace widgets stuck Loading in Popup windows
Browse files Browse the repository at this point in the history
  • Loading branch information
starpit committed Jan 13, 2023
1 parent 4de36e3 commit 481c652
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
21 changes: 18 additions & 3 deletions plugins/plugin-kubectl/components/src/CurrentContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -56,6 +66,7 @@ Events.eventBus.once('/tab/new', () => (ready = true))

export default class CurrentContext extends React.PureComponent<Props, State> {
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)

Expand Down Expand Up @@ -163,6 +174,10 @@ export default class CurrentContext extends React.PureComponent<Props, State> {
})
}

private async reportCurrentContextFromCommandComplete(evt: CommandCompleteEvent) {
this.reportCurrentContext(evt.tab)
}

private async reportCurrentContext(idx?: Tab | number | string) {
if (this.unmounted) {
return
Expand Down Expand Up @@ -303,7 +318,7 @@ export default class CurrentContext extends React.PureComponent<Props, State> {
}
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))
}
Expand All @@ -313,7 +328,7 @@ export default class CurrentContext extends React.PureComponent<Props, State> {
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))
}

Expand Down
11 changes: 8 additions & 3 deletions plugins/plugin-kubectl/components/src/CurrentNamespace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

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

export default class CurrentNamespace extends React.PureComponent<Props, State> {
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) {
Expand Down Expand Up @@ -69,6 +70,10 @@ export default class CurrentNamespace extends React.PureComponent<Props, State>
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
Expand Down Expand Up @@ -172,7 +177,7 @@ export default class CurrentNamespace extends React.PureComponent<Props, State>
}
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))
}

Expand All @@ -192,7 +197,7 @@ export default class CurrentNamespace extends React.PureComponent<Props, State>
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))
}

Expand Down

0 comments on commit 481c652

Please sign in to comment.