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/15 14:52:46 UTC

(camel-karavan) branch main updated: Open Incorrect camel yaml

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 2dba88fb Open Incorrect camel yaml
2dba88fb is described below

commit 2dba88fb29ba364abaa58c091d0735d6140dd9dc
Author: Marat Gubaidullin <ma...@talismancloud.io>
AuthorDate: Fri Mar 15 10:52:39 2024 -0400

    Open Incorrect camel yaml
---
 .../src/main/webui/src/editor/FileEditor.tsx       | 17 +++++-
 karavan-designer/public/example/demo.camel.yaml    |  2 +
 karavan-designer/src/designer/KaravanDesigner.tsx  | 62 ++++++++++------------
 karavan-space/src/designer/KaravanDesigner.tsx     | 62 ++++++++++------------
 4 files changed, 72 insertions(+), 71 deletions(-)

diff --git a/karavan-app/src/main/webui/src/editor/FileEditor.tsx b/karavan-app/src/main/webui/src/editor/FileEditor.tsx
index 2812d005..6dd240c3 100644
--- a/karavan-app/src/main/webui/src/editor/FileEditor.tsx
+++ b/karavan-app/src/main/webui/src/editor/FileEditor.tsx
@@ -21,6 +21,7 @@ import {shallow} from "zustand/shallow";
 import {CamelDefinitionYaml} from "karavan-core/lib/api/CamelDefinitionYaml";
 import {DesignerEditor} from "./DesignerEditor";
 import {CodeEditor} from "./CodeEditor";
+import {EventBus} from "../designer/utils/EventBus";
 
 interface Props {
     projectId: string
@@ -36,7 +37,21 @@ export function FileEditor(props: Props) {
 
     const [file] = useFileStore((s) => [s.file], shallow)
 
-    const isCamelYaml = file !== undefined && file.name.endsWith(".camel.yaml");
+    function yamlIsCamel(): boolean {
+        if (file && file.name.endsWith(".camel.yaml")) {
+            try {
+                const i = CamelDefinitionYaml.yamlToIntegration(file.name, file?.code);
+            } catch (e: any) {
+                console.log(e)
+                EventBus.sendAlert(' ' + e?.name, '' + e?.message, 'danger');
+                return false;
+            }
+            return true;
+        }
+        return false;
+    }
+
+    const isCamelYaml = yamlIsCamel();
     const isKameletYaml = file !== undefined && file.name.endsWith(".kamelet.yaml");
     const isIntegration = isCamelYaml && file?.code && CamelDefinitionYaml.yamlIsIntegration(file.code);
     const showDesigner = (isCamelYaml && isIntegration) || isKameletYaml;
diff --git a/karavan-designer/public/example/demo.camel.yaml b/karavan-designer/public/example/demo.camel.yaml
index b751e86b..facfc3d1 100644
--- a/karavan-designer/public/example/demo.camel.yaml
+++ b/karavan-designer/public/example/demo.camel.yaml
@@ -59,3 +59,5 @@
                       Beer battle: ${jq(variable:beer1,.name)}
                       (${variable.alc1}%) is weaker than
                       ${jq(variable:beer2,.name)} (${variable.alc2}%)
+            otherwise:
+              id: otherwise-03ac
\ No newline at end of file
diff --git a/karavan-designer/src/designer/KaravanDesigner.tsx b/karavan-designer/src/designer/KaravanDesigner.tsx
index 8e49e054..36b65118 100644
--- a/karavan-designer/src/designer/KaravanDesigner.tsx
+++ b/karavan-designer/src/designer/KaravanDesigner.tsx
@@ -73,30 +73,35 @@ export function KaravanDesigner(props: Props) {
     useEffect(() => {
         const sub = EventBus.onIntegrationUpdate()?.subscribe((update: IntegrationUpdate) =>
             save(update.integration, update.propertyOnly));
-        InfrastructureAPI.setOnSaveCustomCode(props.onSaveCustomCode);
-        InfrastructureAPI.setOnGetCustomCode(props.onGetCustomCode);
-        InfrastructureAPI.setOnSave(props.onSave);
-        InfrastructureAPI.setOnSavePropertyPlaceholder(props.onSavePropertyPlaceholder);
-        InfrastructureAPI.setOnInternalConsumerClick(props.onInternalConsumerClick);
+        try {
+            InfrastructureAPI.setOnSaveCustomCode(props.onSaveCustomCode);
+            InfrastructureAPI.setOnGetCustomCode(props.onGetCustomCode);
+            InfrastructureAPI.setOnSave(props.onSave);
+            InfrastructureAPI.setOnSavePropertyPlaceholder(props.onSavePropertyPlaceholder);
+            InfrastructureAPI.setOnInternalConsumerClick(props.onInternalConsumerClick);
 
-        setSelectedStep(undefined);
-        const i = makeIntegration(props.yaml, props.filename);
-        setIntegration(i, false);
-        let designerTab = i.kind === 'Kamelet' ? 'kamelet' : props.tab;
-        if (designerTab === undefined) {
-            const counts = CamelUi.getFlowCounts(i);
-            designerTab = (counts.get('routes') || 0) > 0 ? 'routes' : designerTab;
-            designerTab = (counts.get('rest') || 0) > 0 ? 'rest' : designerTab;
-            designerTab = (counts.get('beans') || 0) > 0 ? 'beans' : designerTab;
+            setSelectedStep(undefined);
+            const i = makeIntegration(props.yaml, props.filename);
+            setIntegration(i, false);
+            let designerTab = i.kind === 'Kamelet' ? 'kamelet' : props.tab;
+            if (designerTab === undefined) {
+                const counts = CamelUi.getFlowCounts(i);
+                designerTab = (counts.get('routes') || 0) > 0 ? 'routes' : designerTab;
+                designerTab = (counts.get('rest') || 0) > 0 ? 'rest' : designerTab;
+                designerTab = (counts.get('beans') || 0) > 0 ? 'beans' : designerTab;
+            }
+            setTab(designerTab || 'routes')
+            reset();
+            setDark(props.dark);
+            setPropertyPlaceholders(props.propertyPlaceholders)
+            setVariables(VariableUtil.findVariables(props.files))
+            setBeans(props.beans)
+            resetFiles(props.files)
+            setHideLogDSL(props.hideLogDSL === true);
+        } catch (e: any) {
+            console.log(e)
+            EventBus.sendAlert(' ' + e?.name, '' + e?.message, 'danger');
         }
-        setTab(designerTab || 'routes')
-        reset();
-        setDark(props.dark);
-        setPropertyPlaceholders(props.propertyPlaceholders)
-        setVariables(VariableUtil.findVariables(props.files))
-        setBeans(props.beans)
-        resetFiles(props.files)
-        setHideLogDSL(props.hideLogDSL === true);
         return () => {
             sub?.unsubscribe();
             setSelectedStep(undefined);
@@ -169,19 +174,6 @@ export function KaravanDesigner(props: Props) {
                     <Tab eventKey='beans' title={getTab("Beans", "Beans Configuration", "beans")}></Tab>
                     {props.showCodeTab && <Tab eventKey='code' title={getTab("YAML", "YAML Code", "code", true)}></Tab>}
                 </Tabs>
-                {/*{tab === 'routes' && <Tooltip content={"Hide Log elements"}>*/}
-                {/*    <Switch*/}
-                {/*        isReversed*/}
-                {/*        isChecked={hideLogDSL}*/}
-                {/*        onChange={(_, checked) => {*/}
-                {/*            setHideLogDSL(checked)*/}
-                {/*        }}*/}
-                {/*        aria-label={"Hide Log"}*/}
-                {/*        id="hideLogDSL"*/}
-                {/*        name="hideLogDSL"*/}
-                {/*        className={"hide-log"}*/}
-                {/*    />*/}
-                {/*</Tooltip>}*/}
             </div>
             {tab === 'kamelet' && <KameletDesigner/>}
             {tab === 'routes' && <RouteDesigner/>}
diff --git a/karavan-space/src/designer/KaravanDesigner.tsx b/karavan-space/src/designer/KaravanDesigner.tsx
index 8e49e054..36b65118 100644
--- a/karavan-space/src/designer/KaravanDesigner.tsx
+++ b/karavan-space/src/designer/KaravanDesigner.tsx
@@ -73,30 +73,35 @@ export function KaravanDesigner(props: Props) {
     useEffect(() => {
         const sub = EventBus.onIntegrationUpdate()?.subscribe((update: IntegrationUpdate) =>
             save(update.integration, update.propertyOnly));
-        InfrastructureAPI.setOnSaveCustomCode(props.onSaveCustomCode);
-        InfrastructureAPI.setOnGetCustomCode(props.onGetCustomCode);
-        InfrastructureAPI.setOnSave(props.onSave);
-        InfrastructureAPI.setOnSavePropertyPlaceholder(props.onSavePropertyPlaceholder);
-        InfrastructureAPI.setOnInternalConsumerClick(props.onInternalConsumerClick);
+        try {
+            InfrastructureAPI.setOnSaveCustomCode(props.onSaveCustomCode);
+            InfrastructureAPI.setOnGetCustomCode(props.onGetCustomCode);
+            InfrastructureAPI.setOnSave(props.onSave);
+            InfrastructureAPI.setOnSavePropertyPlaceholder(props.onSavePropertyPlaceholder);
+            InfrastructureAPI.setOnInternalConsumerClick(props.onInternalConsumerClick);
 
-        setSelectedStep(undefined);
-        const i = makeIntegration(props.yaml, props.filename);
-        setIntegration(i, false);
-        let designerTab = i.kind === 'Kamelet' ? 'kamelet' : props.tab;
-        if (designerTab === undefined) {
-            const counts = CamelUi.getFlowCounts(i);
-            designerTab = (counts.get('routes') || 0) > 0 ? 'routes' : designerTab;
-            designerTab = (counts.get('rest') || 0) > 0 ? 'rest' : designerTab;
-            designerTab = (counts.get('beans') || 0) > 0 ? 'beans' : designerTab;
+            setSelectedStep(undefined);
+            const i = makeIntegration(props.yaml, props.filename);
+            setIntegration(i, false);
+            let designerTab = i.kind === 'Kamelet' ? 'kamelet' : props.tab;
+            if (designerTab === undefined) {
+                const counts = CamelUi.getFlowCounts(i);
+                designerTab = (counts.get('routes') || 0) > 0 ? 'routes' : designerTab;
+                designerTab = (counts.get('rest') || 0) > 0 ? 'rest' : designerTab;
+                designerTab = (counts.get('beans') || 0) > 0 ? 'beans' : designerTab;
+            }
+            setTab(designerTab || 'routes')
+            reset();
+            setDark(props.dark);
+            setPropertyPlaceholders(props.propertyPlaceholders)
+            setVariables(VariableUtil.findVariables(props.files))
+            setBeans(props.beans)
+            resetFiles(props.files)
+            setHideLogDSL(props.hideLogDSL === true);
+        } catch (e: any) {
+            console.log(e)
+            EventBus.sendAlert(' ' + e?.name, '' + e?.message, 'danger');
         }
-        setTab(designerTab || 'routes')
-        reset();
-        setDark(props.dark);
-        setPropertyPlaceholders(props.propertyPlaceholders)
-        setVariables(VariableUtil.findVariables(props.files))
-        setBeans(props.beans)
-        resetFiles(props.files)
-        setHideLogDSL(props.hideLogDSL === true);
         return () => {
             sub?.unsubscribe();
             setSelectedStep(undefined);
@@ -169,19 +174,6 @@ export function KaravanDesigner(props: Props) {
                     <Tab eventKey='beans' title={getTab("Beans", "Beans Configuration", "beans")}></Tab>
                     {props.showCodeTab && <Tab eventKey='code' title={getTab("YAML", "YAML Code", "code", true)}></Tab>}
                 </Tabs>
-                {/*{tab === 'routes' && <Tooltip content={"Hide Log elements"}>*/}
-                {/*    <Switch*/}
-                {/*        isReversed*/}
-                {/*        isChecked={hideLogDSL}*/}
-                {/*        onChange={(_, checked) => {*/}
-                {/*            setHideLogDSL(checked)*/}
-                {/*        }}*/}
-                {/*        aria-label={"Hide Log"}*/}
-                {/*        id="hideLogDSL"*/}
-                {/*        name="hideLogDSL"*/}
-                {/*        className={"hide-log"}*/}
-                {/*    />*/}
-                {/*</Tooltip>}*/}
             </div>
             {tab === 'kamelet' && <KameletDesigner/>}
             {tab === 'routes' && <RouteDesigner/>}