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

Draft: Setup for improving load times of Hawtio Online #801

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/hawtio/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './core'
export * from './help'
export * from './plugins'
export * from './preferences'
export * from './ui'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to export ui?


// Register Hawtio React component version
configManager.addProductInfo('Hawtio React', '__PACKAGE_VERSION_PLACEHOLDER__')
27 changes: 25 additions & 2 deletions packages/hawtio/src/plugins/camel/camel-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as camel3 from '@hawtio/camel-model-v3'
import * as camel4 from '@hawtio/camel-model-v4'
import { eventService } from '@hawtiosrc/core'
import { MBeanNode } from '@hawtiosrc/plugins/shared'
import { jolokiaService } from '@hawtiosrc/plugins/shared/jolokia-service'
Expand All @@ -23,6 +21,9 @@ import {
} from './globals'
import { ROUTE_OPERATIONS } from './routes-service'

let _camel3: CamelModel | null = null
let _camel4: CamelModel | null = null

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if we change them to Promise them can be const not let.

// TODO: Should be provided by @hawtio/camel-model package
export type CamelModel = {
apacheCamelModelVersion: string
Expand Down Expand Up @@ -325,6 +326,7 @@ export function hasProperties(node: MBeanNode): boolean {
}

export function getCamelVersions(): string[] {
const { camel4, camel3 } = fetchCamelModules()
return [camel3.apacheCamelModelVersion, camel4.apacheCamelModelVersion]
}

Expand All @@ -333,6 +335,7 @@ export function getCamelVersions(): string[] {
* the given node. Currently, it supports Camel v3 and v4.
*/
export function getCamelModel(node: MBeanNode): CamelModel {
const { camel4, camel3 } = fetchCamelModules()
if (isCamelVersionEQGT(node, 4, 0)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running I get an error that camel3 is null

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, rather they should be Promise so that they will never return null.

return camel4 as unknown as CamelModel
}
Expand Down Expand Up @@ -397,3 +400,23 @@ export function isCamelVersionEQGT(node: MBeanNode, major: number, minor: number

return compareVersions(camelVersion, major, minor) >= 0
}

const camelModelPromises = Promise.all([
import('@hawtio/camel-model-v3').then(c => {
_camel3 = c as unknown as CamelModel
}),
import('@hawtio/camel-model-v4').then(c => {
_camel4 = c as unknown as CamelModel
}),
])

function fetchCamelModules(): { camel3: CamelModel; camel4: CamelModel } {
if (!_camel3 || !_camel4) {
;(async () => await camelModelPromises)()
}

return {
camel3: _camel3!,
camel4: _camel4!,
}
}
5 changes: 5 additions & 0 deletions packages/hawtio/src/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './about'
export * from './icons'
export * from './login'
export * from './notification'
export * from './page'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are they needed? Note that it will change the Hawtio API we expose to external plugin authors. So generally it needs to be justified with a clear reason.

1 change: 1 addition & 0 deletions packages/hawtio/src/ui/page/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './HawtioPage'
export * from './HawtioLoadingPage'
Loading