Skip to content

Commit

Permalink
fix: Split Discover to only display if no current connection (#188)
Browse files Browse the repository at this point in the history
* Splits the Discover plugin into 2:
 * Discover Core: preferences and header menu (always active)
 * Discover: page dashboad component (only active if no current connection)

* discover-core
 * Moves preferences to this plugin
 * Moves header menu to this plugin
 * Adds as a new plugin, always active
 * By not including a plugin-path, the plugin will not be listed in the
   nav sidebar

* discover
 * Dashboard only active if the connect-server does not contain a current
   connection
  • Loading branch information
phantomjinx committed Oct 21, 2024
1 parent bddcb0e commit c8453a0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/online-shell/src/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ReactDOM from 'react-dom/client'
import { discover } from './discover'
import { reportWebVitals } from './reportWebVitals'
import { HAWTIO_ONLINE_VERSION } from './constants'
import { discoverCore } from './discover-core'

configManager.addProductInfo('Hawtio Online', HAWTIO_ONLINE_VERSION)

Expand All @@ -38,7 +39,10 @@ springboot()

// Register kubernetes & management - only then complete hawtio bootstrap
isMgmtApiRegistered().then(() => {
// Register discover plugin
// Register discover-core plugin
discoverCore()

// Register discover UI plugin
discover()

// Bootstrap Hawtio
Expand Down
4 changes: 4 additions & 0 deletions packages/online-shell/src/discover-core/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Logger } from '@hawtio/react'

export const pluginName = 'hawtio-online-discover-core'
export const log = Logger.get(pluginName)
26 changes: 26 additions & 0 deletions packages/online-shell/src/discover-core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { hawtio, HawtioPlugin, preferencesRegistry } from '@hawtio/react'
import { HeaderMenuDropDown } from './HeaderMenuDropDown'
import { DiscoverPreferences } from './DiscoverPreferences'

const pluginId = 'discover-core'
const pluginTitle = 'Discover'

/*
* Discover core plugin, always enabled, provides:
* - preferences for managing the polling of pods in master
* - the universal header menu listing all the pods
*
* No plugin-path since it is not required to display a
* link in the nav-bar to display a main component
*/

export const discoverCore: HawtioPlugin = () => {
hawtio.addPlugin({
id: pluginId,
title: pluginTitle,
headerItems: [{ component: HeaderMenuDropDown, universal: true }],
isActive: async () => true,
})

preferencesRegistry.add(pluginId, pluginTitle, DiscoverPreferences)
}
13 changes: 6 additions & 7 deletions packages/online-shell/src/discover/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { hawtio, HawtioPlugin, preferencesRegistry } from '@hawtio/react'
import { hawtio, HawtioPlugin, connectService } from '@hawtio/react'
import { pluginPath } from './globals'
import { Discover } from './Discover'
import { HeaderMenuDropDown } from './HeaderMenuDropDown'
import { DiscoverPreferences } from './DiscoverPreferences'

const pluginId = 'discover'
const pluginTitle = 'Discover'
Expand All @@ -13,9 +11,10 @@ export const discover: HawtioPlugin = () => {
title: pluginTitle,
path: pluginPath,
component: Discover,
headerItems: [{ component: HeaderMenuDropDown, universal: true }],
isActive: async () => true,
isActive: async () => {
// Only active is there is NO current connection
const connection = await connectService.getCurrentConnection()
return !connection
},
})

preferencesRegistry.add(pluginId, pluginTitle, DiscoverPreferences)
}

0 comments on commit c8453a0

Please sign in to comment.