You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2024/03/01 19:20:46 UTC

(camel-karavan) branch main updated: Fix #1156

This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git


The following commit(s) were added to refs/heads/main by this push:
     new 9aff5cbf Fix #1156
9aff5cbf is described below

commit 9aff5cbf5245ec303250b7b6f04476417f2d3fce
Author: Marat Gubaidullin <ma...@talismancloud.io>
AuthorDate: Fri Mar 1 14:20:33 2024 -0500

    Fix #1156
---
 .../property/property/ComponentPropertyField.tsx        | 14 ++++++++++++--
 .../src/designer/property/property/DslPropertyField.tsx | 16 +++++++++-------
 .../src/main/webui/src/designer/utils/CamelUi.tsx       | 17 ++++++++++++++++-
 .../webui/src/project/trace/RunnerInfoTraceMessage.tsx  |  6 +-----
 .../property/property/ComponentPropertyField.tsx        | 14 ++++++++++++--
 .../src/designer/property/property/DslPropertyField.tsx | 16 +++++++++-------
 karavan-designer/src/designer/utils/CamelUi.tsx         | 17 ++++++++++++++++-
 .../property/property/ComponentPropertyField.tsx        | 14 ++++++++++++--
 .../src/designer/property/property/DslPropertyField.tsx | 16 +++++++++-------
 karavan-space/src/designer/utils/CamelUi.tsx            | 17 ++++++++++++++++-
 10 files changed, 112 insertions(+), 35 deletions(-)

diff --git a/karavan-app/src/main/webui/src/designer/property/property/ComponentPropertyField.tsx b/karavan-app/src/main/webui/src/designer/property/property/ComponentPropertyField.tsx
index 3f13cb1e..925ab18b 100644
--- a/karavan-app/src/main/webui/src/designer/property/property/ComponentPropertyField.tsx
+++ b/karavan-app/src/main/webui/src/designer/property/property/ComponentPropertyField.tsx
@@ -70,7 +70,7 @@ export function ComponentPropertyField(props: Props) {
 
     const {onParametersChange, getInternalComponentName} = usePropertiesHook();
 
-    const [integration] = useIntegrationStore((state) => [state.integration], shallow)
+    const [integration, files] = useIntegrationStore((state) => [state.integration, state.files], shallow)
     const [dark, setSelectedStep, beans] = useDesignerStore((s) =>
         [s.dark, s.setSelectedStep, s.beans], shallow)
 
@@ -150,12 +150,22 @@ export function ComponentPropertyField(props: Props) {
         }
     }
 
+    function checkUri(startsWith: string): boolean {
+        if (props.element && props.element.dslName === 'ToDefinition' && property.name === 'name') {
+            const uri: string = (props.element as ToDefinition).uri || '';
+            return uri.startsWith(startsWith);
+        } else {
+            return false;
+        }
+    }
+
     function getInternalUriSelect(property: ComponentProperty, value: any) {
         const selectOptions: JSX.Element[] = [];
         const componentName = getInternalComponentName(property.name, props.element);
         const internalUris = CamelUi.getInternalRouteUris(integration, componentName, false);
-        const uris: string [] = [];
+        let uris: string[] = CamelUi.getInternalUris(files, checkUri('direct'), checkUri('seda'));
         uris.push(...internalUris);
+        uris = [...new Set(uris.map(e => e.includes(":") ? e.split(":")?.at(1) || "" : e))]
         if (value && value.length > 0 && !uris.includes(value)) {
             uris.unshift(value);
         }
diff --git a/karavan-app/src/main/webui/src/designer/property/property/DslPropertyField.tsx b/karavan-app/src/main/webui/src/designer/property/property/DslPropertyField.tsx
index 43986796..a17dc88d 100644
--- a/karavan-app/src/main/webui/src/designer/property/property/DslPropertyField.tsx
+++ b/karavan-app/src/main/webui/src/designer/property/property/DslPropertyField.tsx
@@ -51,7 +51,7 @@ import {CamelDefinitionApiExt} from "karavan-core/lib/api/CamelDefinitionApiExt"
 import {ExpressionField} from "./ExpressionField";
 import {CamelUi, RouteToCreate} from "../../utils/CamelUi";
 import {ComponentPropertyField} from "./ComponentPropertyField";
-import {CamelElement} from "karavan-core/lib/model/IntegrationDefinition";
+import {CamelElement, IntegrationFile} from "karavan-core/lib/model/IntegrationDefinition";
 import {KameletPropertyField} from "./KameletPropertyField";
 import PlusIcon from "@patternfly/react-icons/dist/esm/icons/plus-icon";
 import {ObjectField} from "./ObjectField";
@@ -77,6 +77,7 @@ import {BeanProperties} from "./BeanProperties";
 import {PropertyPlaceholderDropdown} from "./PropertyPlaceholderDropdown";
 import {VariablesDropdown} from "./VariablesDropdown";
 import {ROUTE, GLOBAL} from "karavan-core/lib/api/VariableUtil";
+import {getIntegrations} from "../../../topology/TopologyApi";
 
 interface Props {
     property: PropertyMeta,
@@ -92,7 +93,7 @@ interface Props {
 
 export function DslPropertyField(props: Props) {
 
-    const [integration, setIntegration, addVariable] = useIntegrationStore((s) => [s.integration, s.setIntegration, s.addVariable], shallow)
+    const [integration, setIntegration, addVariable, files] = useIntegrationStore((s) => [s.integration, s.setIntegration, s.addVariable, s.files], shallow)
     const [dark, setSelectedStep] = useDesignerStore((s) => [s.dark, s.setSelectedStep], shallow)
 
     const [isShowAdvanced, setIsShowAdvanced] = useState<string[]>([]);
@@ -107,7 +108,9 @@ export function DslPropertyField(props: Props) {
     const [variableType, setVariableType] = useState<'global:' | 'route:' | ''>('');
     const [checkChanges, setCheckChanges] = useState<boolean>(false);
 
-    useEffect(() => setTextVariable(value), [])
+    useEffect(() => {
+        setTextVariable(value)
+    }, [])
 
     useEffect(() => {
         if (checkChanges) {
@@ -687,10 +690,9 @@ export function DslPropertyField(props: Props) {
 
     function getInternalUriSelect(property: PropertyMeta, value: any) {
         const selectOptions: JSX.Element[] = [];
-        const urls = CamelUi.getInternalRouteUris(integration, "direct");
-        urls.push(...CamelUi.getInternalRouteUris(integration, "seda"));
-        if (urls && urls.length > 0) {
-            selectOptions.push(...urls.map((value: string) =>
+        const uris: string[] = CamelUi.getInternalUris(files, true, true);
+        if (uris && uris.length > 0) {
+            selectOptions.push(...uris.map((value: string) =>
                 <SelectOption key={value} value={value.trim()}/>));
         }
         return (
diff --git a/karavan-app/src/main/webui/src/designer/utils/CamelUi.tsx b/karavan-app/src/main/webui/src/designer/utils/CamelUi.tsx
index 28718e59..8caf309f 100644
--- a/karavan-app/src/main/webui/src/designer/utils/CamelUi.tsx
+++ b/karavan-app/src/main/webui/src/designer/utils/CamelUi.tsx
@@ -27,7 +27,7 @@ import {
     RouteDefinition,
     ToDefinition
 } from "karavan-core/lib/model/CamelDefinition";
-import {CamelElement, Integration} from "karavan-core/lib/model/IntegrationDefinition";
+import {CamelElement, Integration, IntegrationFile} from "karavan-core/lib/model/IntegrationDefinition";
 import {
     ActivemqIcon, ApiIcon,
     AwsIcon,
@@ -92,6 +92,7 @@ import {
 } from "../icons/EipIcons";
 import React from "react";
 import {TopologyUtils} from "karavan-core/lib/api/TopologyUtils";
+import {getIntegrations} from "../../topology/TopologyApi";
 
 const StepElements: string[] = [
     "AggregateDefinition",
@@ -342,6 +343,20 @@ export class CamelUi {
         return result;
     }
 
+    static getInternalUris = (files: IntegrationFile[], direct: boolean, seda: boolean) => {
+        const urls: string[] = [];
+        const integrations = getIntegrations(files);
+        integrations.forEach(i => {
+            if (direct) {
+                urls.push(...CamelUi.getInternalRouteUris(i, "direct"))
+            }
+            if (seda) {
+                urls.push(...CamelUi.getInternalRouteUris(i, "seda"));
+            }
+        })
+        return urls;
+    }
+
     static getElementTitle = (element: CamelElement): string => {
         if (element.dslName === 'RouteDefinition') {
             const routeId = (element as RouteDefinition).id
diff --git a/karavan-app/src/main/webui/src/project/trace/RunnerInfoTraceMessage.tsx b/karavan-app/src/main/webui/src/project/trace/RunnerInfoTraceMessage.tsx
index 7eae1020..1ddabfdc 100644
--- a/karavan-app/src/main/webui/src/project/trace/RunnerInfoTraceMessage.tsx
+++ b/karavan-app/src/main/webui/src/project/trace/RunnerInfoTraceMessage.tsx
@@ -53,10 +53,6 @@ export function RunnerInfoTraceMessage (props: Props) {
     const body = props.trace?.message?.body?.value;
     const variable = variables.filter(v => v.key === variableName)?.at(0);
 
-    useEffect(()=> {
-        console.log(variableName)
-    }, [variableName])
-
     function getBody() {
         return (
             <CodeBlock title="Body">
@@ -150,7 +146,7 @@ export function RunnerInfoTraceMessage (props: Props) {
             </Tabs>
             {tab === 'variables' && variables.length > 0 &&
                 <>
-                <Tabs activeKey={variableName} onSelect={(event, eventKey) => setVariableName(eventKey)}>
+                <Tabs key={variableName} activeKey={variableName} onSelect={(event, eventKey) => setVariableName(eventKey)}>
                     {variables.map(v => (<Tab eventKey={v.key} title={<TabTitleText>{v.key}</TabTitleText>}/>))}
                 </Tabs>
                 {getVariableType()}
diff --git a/karavan-designer/src/designer/property/property/ComponentPropertyField.tsx b/karavan-designer/src/designer/property/property/ComponentPropertyField.tsx
index 3f13cb1e..925ab18b 100644
--- a/karavan-designer/src/designer/property/property/ComponentPropertyField.tsx
+++ b/karavan-designer/src/designer/property/property/ComponentPropertyField.tsx
@@ -70,7 +70,7 @@ export function ComponentPropertyField(props: Props) {
 
     const {onParametersChange, getInternalComponentName} = usePropertiesHook();
 
-    const [integration] = useIntegrationStore((state) => [state.integration], shallow)
+    const [integration, files] = useIntegrationStore((state) => [state.integration, state.files], shallow)
     const [dark, setSelectedStep, beans] = useDesignerStore((s) =>
         [s.dark, s.setSelectedStep, s.beans], shallow)
 
@@ -150,12 +150,22 @@ export function ComponentPropertyField(props: Props) {
         }
     }
 
+    function checkUri(startsWith: string): boolean {
+        if (props.element && props.element.dslName === 'ToDefinition' && property.name === 'name') {
+            const uri: string = (props.element as ToDefinition).uri || '';
+            return uri.startsWith(startsWith);
+        } else {
+            return false;
+        }
+    }
+
     function getInternalUriSelect(property: ComponentProperty, value: any) {
         const selectOptions: JSX.Element[] = [];
         const componentName = getInternalComponentName(property.name, props.element);
         const internalUris = CamelUi.getInternalRouteUris(integration, componentName, false);
-        const uris: string [] = [];
+        let uris: string[] = CamelUi.getInternalUris(files, checkUri('direct'), checkUri('seda'));
         uris.push(...internalUris);
+        uris = [...new Set(uris.map(e => e.includes(":") ? e.split(":")?.at(1) || "" : e))]
         if (value && value.length > 0 && !uris.includes(value)) {
             uris.unshift(value);
         }
diff --git a/karavan-designer/src/designer/property/property/DslPropertyField.tsx b/karavan-designer/src/designer/property/property/DslPropertyField.tsx
index 43986796..a17dc88d 100644
--- a/karavan-designer/src/designer/property/property/DslPropertyField.tsx
+++ b/karavan-designer/src/designer/property/property/DslPropertyField.tsx
@@ -51,7 +51,7 @@ import {CamelDefinitionApiExt} from "karavan-core/lib/api/CamelDefinitionApiExt"
 import {ExpressionField} from "./ExpressionField";
 import {CamelUi, RouteToCreate} from "../../utils/CamelUi";
 import {ComponentPropertyField} from "./ComponentPropertyField";
-import {CamelElement} from "karavan-core/lib/model/IntegrationDefinition";
+import {CamelElement, IntegrationFile} from "karavan-core/lib/model/IntegrationDefinition";
 import {KameletPropertyField} from "./KameletPropertyField";
 import PlusIcon from "@patternfly/react-icons/dist/esm/icons/plus-icon";
 import {ObjectField} from "./ObjectField";
@@ -77,6 +77,7 @@ import {BeanProperties} from "./BeanProperties";
 import {PropertyPlaceholderDropdown} from "./PropertyPlaceholderDropdown";
 import {VariablesDropdown} from "./VariablesDropdown";
 import {ROUTE, GLOBAL} from "karavan-core/lib/api/VariableUtil";
+import {getIntegrations} from "../../../topology/TopologyApi";
 
 interface Props {
     property: PropertyMeta,
@@ -92,7 +93,7 @@ interface Props {
 
 export function DslPropertyField(props: Props) {
 
-    const [integration, setIntegration, addVariable] = useIntegrationStore((s) => [s.integration, s.setIntegration, s.addVariable], shallow)
+    const [integration, setIntegration, addVariable, files] = useIntegrationStore((s) => [s.integration, s.setIntegration, s.addVariable, s.files], shallow)
     const [dark, setSelectedStep] = useDesignerStore((s) => [s.dark, s.setSelectedStep], shallow)
 
     const [isShowAdvanced, setIsShowAdvanced] = useState<string[]>([]);
@@ -107,7 +108,9 @@ export function DslPropertyField(props: Props) {
     const [variableType, setVariableType] = useState<'global:' | 'route:' | ''>('');
     const [checkChanges, setCheckChanges] = useState<boolean>(false);
 
-    useEffect(() => setTextVariable(value), [])
+    useEffect(() => {
+        setTextVariable(value)
+    }, [])
 
     useEffect(() => {
         if (checkChanges) {
@@ -687,10 +690,9 @@ export function DslPropertyField(props: Props) {
 
     function getInternalUriSelect(property: PropertyMeta, value: any) {
         const selectOptions: JSX.Element[] = [];
-        const urls = CamelUi.getInternalRouteUris(integration, "direct");
-        urls.push(...CamelUi.getInternalRouteUris(integration, "seda"));
-        if (urls && urls.length > 0) {
-            selectOptions.push(...urls.map((value: string) =>
+        const uris: string[] = CamelUi.getInternalUris(files, true, true);
+        if (uris && uris.length > 0) {
+            selectOptions.push(...uris.map((value: string) =>
                 <SelectOption key={value} value={value.trim()}/>));
         }
         return (
diff --git a/karavan-designer/src/designer/utils/CamelUi.tsx b/karavan-designer/src/designer/utils/CamelUi.tsx
index 28718e59..8caf309f 100644
--- a/karavan-designer/src/designer/utils/CamelUi.tsx
+++ b/karavan-designer/src/designer/utils/CamelUi.tsx
@@ -27,7 +27,7 @@ import {
     RouteDefinition,
     ToDefinition
 } from "karavan-core/lib/model/CamelDefinition";
-import {CamelElement, Integration} from "karavan-core/lib/model/IntegrationDefinition";
+import {CamelElement, Integration, IntegrationFile} from "karavan-core/lib/model/IntegrationDefinition";
 import {
     ActivemqIcon, ApiIcon,
     AwsIcon,
@@ -92,6 +92,7 @@ import {
 } from "../icons/EipIcons";
 import React from "react";
 import {TopologyUtils} from "karavan-core/lib/api/TopologyUtils";
+import {getIntegrations} from "../../topology/TopologyApi";
 
 const StepElements: string[] = [
     "AggregateDefinition",
@@ -342,6 +343,20 @@ export class CamelUi {
         return result;
     }
 
+    static getInternalUris = (files: IntegrationFile[], direct: boolean, seda: boolean) => {
+        const urls: string[] = [];
+        const integrations = getIntegrations(files);
+        integrations.forEach(i => {
+            if (direct) {
+                urls.push(...CamelUi.getInternalRouteUris(i, "direct"))
+            }
+            if (seda) {
+                urls.push(...CamelUi.getInternalRouteUris(i, "seda"));
+            }
+        })
+        return urls;
+    }
+
     static getElementTitle = (element: CamelElement): string => {
         if (element.dslName === 'RouteDefinition') {
             const routeId = (element as RouteDefinition).id
diff --git a/karavan-space/src/designer/property/property/ComponentPropertyField.tsx b/karavan-space/src/designer/property/property/ComponentPropertyField.tsx
index 3f13cb1e..925ab18b 100644
--- a/karavan-space/src/designer/property/property/ComponentPropertyField.tsx
+++ b/karavan-space/src/designer/property/property/ComponentPropertyField.tsx
@@ -70,7 +70,7 @@ export function ComponentPropertyField(props: Props) {
 
     const {onParametersChange, getInternalComponentName} = usePropertiesHook();
 
-    const [integration] = useIntegrationStore((state) => [state.integration], shallow)
+    const [integration, files] = useIntegrationStore((state) => [state.integration, state.files], shallow)
     const [dark, setSelectedStep, beans] = useDesignerStore((s) =>
         [s.dark, s.setSelectedStep, s.beans], shallow)
 
@@ -150,12 +150,22 @@ export function ComponentPropertyField(props: Props) {
         }
     }
 
+    function checkUri(startsWith: string): boolean {
+        if (props.element && props.element.dslName === 'ToDefinition' && property.name === 'name') {
+            const uri: string = (props.element as ToDefinition).uri || '';
+            return uri.startsWith(startsWith);
+        } else {
+            return false;
+        }
+    }
+
     function getInternalUriSelect(property: ComponentProperty, value: any) {
         const selectOptions: JSX.Element[] = [];
         const componentName = getInternalComponentName(property.name, props.element);
         const internalUris = CamelUi.getInternalRouteUris(integration, componentName, false);
-        const uris: string [] = [];
+        let uris: string[] = CamelUi.getInternalUris(files, checkUri('direct'), checkUri('seda'));
         uris.push(...internalUris);
+        uris = [...new Set(uris.map(e => e.includes(":") ? e.split(":")?.at(1) || "" : e))]
         if (value && value.length > 0 && !uris.includes(value)) {
             uris.unshift(value);
         }
diff --git a/karavan-space/src/designer/property/property/DslPropertyField.tsx b/karavan-space/src/designer/property/property/DslPropertyField.tsx
index 43986796..a17dc88d 100644
--- a/karavan-space/src/designer/property/property/DslPropertyField.tsx
+++ b/karavan-space/src/designer/property/property/DslPropertyField.tsx
@@ -51,7 +51,7 @@ import {CamelDefinitionApiExt} from "karavan-core/lib/api/CamelDefinitionApiExt"
 import {ExpressionField} from "./ExpressionField";
 import {CamelUi, RouteToCreate} from "../../utils/CamelUi";
 import {ComponentPropertyField} from "./ComponentPropertyField";
-import {CamelElement} from "karavan-core/lib/model/IntegrationDefinition";
+import {CamelElement, IntegrationFile} from "karavan-core/lib/model/IntegrationDefinition";
 import {KameletPropertyField} from "./KameletPropertyField";
 import PlusIcon from "@patternfly/react-icons/dist/esm/icons/plus-icon";
 import {ObjectField} from "./ObjectField";
@@ -77,6 +77,7 @@ import {BeanProperties} from "./BeanProperties";
 import {PropertyPlaceholderDropdown} from "./PropertyPlaceholderDropdown";
 import {VariablesDropdown} from "./VariablesDropdown";
 import {ROUTE, GLOBAL} from "karavan-core/lib/api/VariableUtil";
+import {getIntegrations} from "../../../topology/TopologyApi";
 
 interface Props {
     property: PropertyMeta,
@@ -92,7 +93,7 @@ interface Props {
 
 export function DslPropertyField(props: Props) {
 
-    const [integration, setIntegration, addVariable] = useIntegrationStore((s) => [s.integration, s.setIntegration, s.addVariable], shallow)
+    const [integration, setIntegration, addVariable, files] = useIntegrationStore((s) => [s.integration, s.setIntegration, s.addVariable, s.files], shallow)
     const [dark, setSelectedStep] = useDesignerStore((s) => [s.dark, s.setSelectedStep], shallow)
 
     const [isShowAdvanced, setIsShowAdvanced] = useState<string[]>([]);
@@ -107,7 +108,9 @@ export function DslPropertyField(props: Props) {
     const [variableType, setVariableType] = useState<'global:' | 'route:' | ''>('');
     const [checkChanges, setCheckChanges] = useState<boolean>(false);
 
-    useEffect(() => setTextVariable(value), [])
+    useEffect(() => {
+        setTextVariable(value)
+    }, [])
 
     useEffect(() => {
         if (checkChanges) {
@@ -687,10 +690,9 @@ export function DslPropertyField(props: Props) {
 
     function getInternalUriSelect(property: PropertyMeta, value: any) {
         const selectOptions: JSX.Element[] = [];
-        const urls = CamelUi.getInternalRouteUris(integration, "direct");
-        urls.push(...CamelUi.getInternalRouteUris(integration, "seda"));
-        if (urls && urls.length > 0) {
-            selectOptions.push(...urls.map((value: string) =>
+        const uris: string[] = CamelUi.getInternalUris(files, true, true);
+        if (uris && uris.length > 0) {
+            selectOptions.push(...uris.map((value: string) =>
                 <SelectOption key={value} value={value.trim()}/>));
         }
         return (
diff --git a/karavan-space/src/designer/utils/CamelUi.tsx b/karavan-space/src/designer/utils/CamelUi.tsx
index 28718e59..8caf309f 100644
--- a/karavan-space/src/designer/utils/CamelUi.tsx
+++ b/karavan-space/src/designer/utils/CamelUi.tsx
@@ -27,7 +27,7 @@ import {
     RouteDefinition,
     ToDefinition
 } from "karavan-core/lib/model/CamelDefinition";
-import {CamelElement, Integration} from "karavan-core/lib/model/IntegrationDefinition";
+import {CamelElement, Integration, IntegrationFile} from "karavan-core/lib/model/IntegrationDefinition";
 import {
     ActivemqIcon, ApiIcon,
     AwsIcon,
@@ -92,6 +92,7 @@ import {
 } from "../icons/EipIcons";
 import React from "react";
 import {TopologyUtils} from "karavan-core/lib/api/TopologyUtils";
+import {getIntegrations} from "../../topology/TopologyApi";
 
 const StepElements: string[] = [
     "AggregateDefinition",
@@ -342,6 +343,20 @@ export class CamelUi {
         return result;
     }
 
+    static getInternalUris = (files: IntegrationFile[], direct: boolean, seda: boolean) => {
+        const urls: string[] = [];
+        const integrations = getIntegrations(files);
+        integrations.forEach(i => {
+            if (direct) {
+                urls.push(...CamelUi.getInternalRouteUris(i, "direct"))
+            }
+            if (seda) {
+                urls.push(...CamelUi.getInternalRouteUris(i, "seda"));
+            }
+        })
+        return urls;
+    }
+
     static getElementTitle = (element: CamelElement): string => {
         if (element.dslName === 'RouteDefinition') {
             const routeId = (element as RouteDefinition).id