Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugins/plugin-kubectl): in browser clients, CurrentContext/Names… #7657

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions plugins/plugin-kubectl/components/src/CurrentContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
eventChannelUnsafe,
getCurrentTab,
getTab,
inBrowser,
Tab,
TabState,
encodeComponent,
Expand Down Expand Up @@ -66,6 +65,9 @@ function KubernetesIcon() {
)
}

export let ready = false
eventBus.once('/tab/new', () => (ready = true))

export default class CurrentContext extends React.PureComponent<Props, State> {
private readonly handler = this.reportCurrentContext.bind(this)
private readonly handlerForConfigChange = this.getCurrentContextFromChange.bind(this)
Expand Down Expand Up @@ -257,8 +259,8 @@ export default class CurrentContext extends React.PureComponent<Props, State> {
*
*/
public componentDidMount() {
if (inBrowser()) {
eventBus.on('/tab/new', this.handler)
if (!ready) {
eventBus.once('/tab/new', this.handler)
} else {
this.handler()
}
Expand All @@ -270,7 +272,7 @@ export default class CurrentContext extends React.PureComponent<Props, State> {

/** Bye! */
public componentWillUnmount() {
// eventBus.off('/tab/new', this.handler)
eventBus.off('/tab/new', this.handler)
eventBus.off('/tab/switch/request/done', this.handlerNotCallingKubectl)
eventBus.offAnyCommandComplete(this.handler)
offKubectlConfigChangeEvents(this.handlerForConfigChange)
Expand Down
16 changes: 4 additions & 12 deletions plugins/plugin-kubectl/components/src/CurrentNamespace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ import React from 'react'

import { Icons, ViewLevel, Select, TextWithIconWidget } from '@kui-shell/plugin-client-common'

import {
eventBus,
inBrowser,
i18n,
eventChannelUnsafe,
getTab,
Tab,
TabState,
pexecInCurrentTab
} from '@kui-shell/core'
import { eventBus, i18n, eventChannelUnsafe, getTab, Tab, TabState, pexecInCurrentTab } from '@kui-shell/core'

import {
kubectl,
Expand All @@ -38,6 +29,7 @@ import {
offKubectlConfigChangeEvents
} from '@kui-shell/plugin-kubectl'

import { ready } from './CurrentContext'
import { isInternalNamespace } from '@kui-shell/plugin-kubectl/heuristics'

interface Props {
Expand Down Expand Up @@ -138,8 +130,8 @@ export default class CurrentNamespace extends React.PureComponent<Props, State>
*
*/
public componentDidMount() {
if (inBrowser()) {
eventBus.on('/tab/new', this.handler)
if (!ready) {
eventBus.once('/tab/new', this.handler)
} else {
this.handler()
}
Expand Down