Skip to content

Commit

Permalink
fix(camel): apply options from preferences
Browse files Browse the repository at this point in the history
Fix #409
  • Loading branch information
tadayosi committed Nov 2, 2023
1 parent 040b5b3 commit f5f5cb7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 76 deletions.
55 changes: 0 additions & 55 deletions packages/hawtio/src/plugins/camel/CamelPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,6 @@ export const CamelPreferences: React.FunctionComponent = () => {
<CardBody>
<Form isHorizontal>
<FormSection>
<FormGroup
hasNoPaddingTop
label='Hide option documentation'
fieldId='camel-form-hide-option-documentation'
labelIcon={
<TooltipHelpIcon tooltip='Whether to hide documentation in the properties view and Camel route editor' />
}
>
<Checkbox
id='camel-form-hide-option-documentation-input'
isChecked={options.hideOptionDocumentation}
onChange={updateCheckboxValueFor('hideOptionDocumentation')}
/>
</FormGroup>
<FormGroup
hasNoPaddingTop
label='Hide default options values'
fieldId='camel-form-hide-default-option-values'
labelIcon={
<TooltipHelpIcon tooltip='Whether to hide options that are using a default value in the properties view' />
}
>
<Checkbox
id='camel-form-hide-default-option-values-input'
isChecked={options.hideOptionDefaultValue}
onChange={updateCheckboxValueFor('hideOptionDefaultValue')}
/>
</FormGroup>
<FormGroup
hasNoPaddingTop
label='Hide unused options values'
fieldId='camel-form-hide-unused-option-values'
labelIcon={<TooltipHelpIcon tooltip='Whether to hide unused/empty options in the properties view' />}
>
<Checkbox
id='camel-form-hide-unused-option-values-input'
isChecked={options.hideOptionUnusedValue}
onChange={updateCheckboxValueFor('hideOptionUnusedValue')}
/>
</FormGroup>
<FormGroup
hasNoPaddingTop
label='Include trace / debug streams'
Expand Down Expand Up @@ -137,21 +97,6 @@ export const CamelPreferences: React.FunctionComponent = () => {
onChange={updateCheckboxValueFor('showInflightCounter')}
/>
</FormGroup>
<FormGroup
hasNoPaddingTop
label='Route metric maximum seconds'
fieldId='camel-form-route-metric-maximum-seconds'
labelIcon={
<TooltipHelpIcon tooltip='The maximum value in seconds used by the route metrics duration and histogram charts' />
}
>
<TextInput
id='camel-form-route-metric-maximum-seconds-input'
type='number'
value={options.routeMetricMaximumSeconds}
onChange={updateNumberValueFor('routeMetricMaximumSeconds')}
/>
</FormGroup>
</FormSection>
</Form>
</CardBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,11 @@ describe('camel-preferences-service', () => {
traceOrDebugIncludeStreams: false,
maximumLabelWidth: 34,
maximumTraceOrDebugBodyLength: 134234,
routeMetricMaximumSeconds: 10,
hideOptionDocumentation: true,
hideOptionDefaultValue: false,
hideOptionUnusedValue: true,
key: true,
})
const expected: Partial<CamelOptions> = {
ignoreIdForLabel: true,
maximumTraceOrDebugBodyLength: 134234,
hideOptionUnusedValue: true,
}
localStorage.setItem(STORAGE_KEY_CAMEL_PREFERENCES, savedString)

Expand Down
12 changes: 3 additions & 9 deletions packages/hawtio/src/plugins/camel/camel-preferences-service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
export type CamelOptions = {
// Route diagram
ignoreIdForLabel: boolean
showInflightCounter: boolean
showInflightCounter: boolean // TODO: Not used yet
maximumLabelWidth: number
// Trace / debug
maximumTraceOrDebugBodyLength: number
traceOrDebugIncludeStreams: boolean
routeMetricMaximumSeconds: number
hideOptionDocumentation: boolean
hideOptionDefaultValue: boolean
hideOptionUnusedValue: boolean
}

export const DEFAULT_OPTIONS: CamelOptions = {
Expand All @@ -16,10 +14,6 @@ export const DEFAULT_OPTIONS: CamelOptions = {
maximumLabelWidth: 34,
maximumTraceOrDebugBodyLength: 5000,
traceOrDebugIncludeStreams: false,
routeMetricMaximumSeconds: 10,
hideOptionDocumentation: false,
hideOptionDefaultValue: false,
hideOptionUnusedValue: false,
} as const

export const STORAGE_KEY_CAMEL_PREFERENCES = 'camel.preferences'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parseXML } from '@hawtiosrc/util/xml'
import dagre from 'dagre'
import { ReactNode } from 'react'
import { Edge, MarkerType, Node, Position } from 'reactflow'
import { camelPreferencesService } from '../camel-preferences-service'

export type CamelNodeData = {
id: string
Expand All @@ -30,7 +31,6 @@ class VisualizationService {
dagreGraph: dagre.graphlib.Graph
nodeWidth = 250
nodeHeight = 80
defaultMaximumLabelWidth = 34
edgeType = 'smoothstep'
margin = {
left: 25,
Expand Down Expand Up @@ -102,7 +102,7 @@ class VisualizationService {

const allRoutes = doc.getElementsByTagName('route')

for (const route of allRoutes) {
for (const route of Array.from(allRoutes)) {
const routeId = route.id
if (!selectedRouteId || !routeId || selectedRouteId === routeId) {
this.addRouteXmlChildren(node, route, nodes, edges, routeId, '')
Expand Down Expand Up @@ -160,7 +160,7 @@ class VisualizationService {
* routeIdx defines an id for each node in the route so
*/
let routeIdx = -1
for (const route of parent.children) {
for (const route of Array.from(parent.children)) {
const id: string = nodeDatas.length + ''
routeIdx++
// from acts as a parent even though its a previous sibling :)
Expand All @@ -180,22 +180,22 @@ class VisualizationService {
if (uri) {
tooltip += ' ' + uri
}
const { ignoreIdForLabel, maximumLabelWidth } = camelPreferencesService.loadOptions()
const elementID = route.getAttribute('id')
let labelSummary = label
if (elementID) {
const customId = route.getAttribute('customId')
if (!customId || customId === 'false') {
if (ignoreIdForLabel || !customId || customId === 'false') {
labelSummary = 'id: ' + elementID
} else {
label = elementID
}
}
// lets check if we need to trim the label
const labelLimit = this.defaultMaximumLabelWidth
const length = label.length
if (length > labelLimit) {
if (length > maximumLabelWidth) {
labelSummary = label + '\n\n' + labelSummary
label = label.substring(0, labelLimit) + '..'
label = label.substring(0, maximumLabelWidth) + '..'
}
const imageUrl = routesService.getIcon(node, nodeSettings)

Expand Down

0 comments on commit f5f5cb7

Please sign in to comment.