From 8d8ddd98b6de354e6b2cf2ebac5e17c5c2a86f8f Mon Sep 17 00:00:00 2001 From: Tadayoshi Sato Date: Thu, 2 Nov 2023 19:16:27 +0900 Subject: [PATCH] fix(camel): apply options from preferences Fix #409 --- .../src/plugins/camel/CamelPreferences.tsx | 55 ------------------- .../camel/camel-preferences-service.test.ts | 5 -- .../camel/camel-preferences-service.ts | 12 +--- .../route-diagram/visualization-service.ts | 14 ++--- 4 files changed, 10 insertions(+), 76 deletions(-) diff --git a/packages/hawtio/src/plugins/camel/CamelPreferences.tsx b/packages/hawtio/src/plugins/camel/CamelPreferences.tsx index a68cf7e5..3754264e 100644 --- a/packages/hawtio/src/plugins/camel/CamelPreferences.tsx +++ b/packages/hawtio/src/plugins/camel/CamelPreferences.tsx @@ -27,46 +27,6 @@ export const CamelPreferences: React.FunctionComponent = () => {
- - } - > - - - - } - > - - - } - > - - { onChange={updateCheckboxValueFor('showInflightCounter')} /> - - } - > - -
diff --git a/packages/hawtio/src/plugins/camel/camel-preferences-service.test.ts b/packages/hawtio/src/plugins/camel/camel-preferences-service.test.ts index 029a5db5..6463cf0f 100644 --- a/packages/hawtio/src/plugins/camel/camel-preferences-service.test.ts +++ b/packages/hawtio/src/plugins/camel/camel-preferences-service.test.ts @@ -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 = { ignoreIdForLabel: true, maximumTraceOrDebugBodyLength: 134234, - hideOptionUnusedValue: true, } localStorage.setItem(STORAGE_KEY_CAMEL_PREFERENCES, savedString) diff --git a/packages/hawtio/src/plugins/camel/camel-preferences-service.ts b/packages/hawtio/src/plugins/camel/camel-preferences-service.ts index 107b66c7..37578359 100644 --- a/packages/hawtio/src/plugins/camel/camel-preferences-service.ts +++ b/packages/hawtio/src/plugins/camel/camel-preferences-service.ts @@ -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 = { @@ -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' diff --git a/packages/hawtio/src/plugins/camel/route-diagram/visualization-service.ts b/packages/hawtio/src/plugins/camel/route-diagram/visualization-service.ts index 84328074..2f432145 100644 --- a/packages/hawtio/src/plugins/camel/route-diagram/visualization-service.ts +++ b/packages/hawtio/src/plugins/camel/route-diagram/visualization-service.ts @@ -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 @@ -30,7 +31,6 @@ class VisualizationService { dagreGraph: dagre.graphlib.Graph nodeWidth = 250 nodeHeight = 80 - defaultMaximumLabelWidth = 34 edgeType = 'smoothstep' margin = { left: 25, @@ -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, '') @@ -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 :) @@ -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)