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/02/01 22:38:31 UTC
(camel-karavan) 02/05: Web app #1094
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
commit 39aaee32fcda6048d4ed6e03f90fd18f63beddb4
Author: Marat Gubaidullin <ma...@talismancloud.io>
AuthorDate: Thu Feb 1 16:58:01 2024 -0500
Web app #1094
---
.../src/main/webui/src/designer/DesignerStore.ts | 15 ++++++-
.../main/webui/src/designer/KaravanDesigner.tsx | 7 +++-
.../property/property/ComponentPropertyField.tsx | 6 +--
.../src/main/webui/src/project/FileEditor.tsx | 14 +++++--
.../src/main/webui/src/util/CodeUtils.ts | 46 ++++++++++++++++++++++
.../src/main/webui/src/util/StringUtils.ts | 25 ------------
6 files changed, 77 insertions(+), 36 deletions(-)
diff --git a/karavan-web/karavan-app/src/main/webui/src/designer/DesignerStore.ts b/karavan-web/karavan-app/src/main/webui/src/designer/DesignerStore.ts
index fe198a7f..8a836e5f 100644
--- a/karavan-web/karavan-app/src/main/webui/src/designer/DesignerStore.ts
+++ b/karavan-web/karavan-app/src/main/webui/src/designer/DesignerStore.ts
@@ -19,6 +19,7 @@ import {CamelElement, Integration} from "karavan-core/lib/model/IntegrationDefin
import {DslPosition, EventBus} from "./utils/EventBus";
import {createWithEqualityFn} from "zustand/traditional";
import {shallow} from "zustand/shallow";
+import {RegistryBeanDefinition} from "karavan-core/src/core/model/CamelDefinition";
interface IntegrationState {
integration: Integration;
@@ -169,7 +170,8 @@ type DesignerState = {
top: number,
left: number,
moveElements: [string | undefined, string | undefined],
- propertyPlaceholders: string[];
+ propertyPlaceholders: string[],
+ beans: RegistryBeanDefinition[]
}
const designerState: DesignerState = {
@@ -188,7 +190,8 @@ const designerState: DesignerState = {
top: 0,
left: 0,
moveElements: [undefined, undefined],
- propertyPlaceholders: []
+ propertyPlaceholders: [],
+ beans: []
};
type DesignerAction = {
@@ -206,6 +209,7 @@ type DesignerAction = {
setNotification: (notificationBadge: boolean, notificationMessage: [string, string]) => void;
setMoveElements: (moveElements: [string | undefined, string | undefined]) => void;
setPropertyPlaceholders: (propertyPlaceholders: string[]) => void;
+ setBeans: (beans: RegistryBeanDefinition[]) => void;
}
export const useDesignerStore = createWithEqualityFn<DesignerState & DesignerAction>((set) => ({
@@ -268,4 +272,11 @@ export const useDesignerStore = createWithEqualityFn<DesignerState & DesignerAct
return state;
})
},
+ setBeans: (beans: RegistryBeanDefinition[]) => {
+ set((state: DesignerState) => {
+ state.beans.length = 0;
+ state.beans.push(...beans);
+ return state;
+ })
+ },
}), shallow)
\ No newline at end of file
diff --git a/karavan-web/karavan-app/src/main/webui/src/designer/KaravanDesigner.tsx b/karavan-web/karavan-app/src/main/webui/src/designer/KaravanDesigner.tsx
index 7f201e4c..11bf8b6c 100644
--- a/karavan-web/karavan-app/src/main/webui/src/designer/KaravanDesigner.tsx
+++ b/karavan-web/karavan-app/src/main/webui/src/designer/KaravanDesigner.tsx
@@ -41,6 +41,7 @@ import {BeansDesigner} from "./beans/BeansDesigner";
import {CodeEditor} from "./editor/CodeEditor";
import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
import {KameletDesigner} from "./kamelet/KameletDesigner";
+import {RegistryBeanDefinition} from "karavan-core/lib/model/CamelDefinition";
interface Props {
onSave: (filename: string, yaml: string, propertyOnly: boolean) => void
@@ -54,14 +55,15 @@ interface Props {
showCodeTab: boolean
tab?: "routes" | "rest" | "beans"
propertyPlaceholders: string[]
+ beans: RegistryBeanDefinition[]
}
export function KaravanDesigner(props: Props) {
const [tab, setTab] = useState<string>('routes');
- const [setDark, hideLogDSL, setHideLogDSL, setSelectedStep, reset, badge, message, setPropertyPlaceholders] =
+ const [setDark, hideLogDSL, setHideLogDSL, setSelectedStep, reset, badge, message, setPropertyPlaceholders, setBeans] =
useDesignerStore((s) =>
- [s.setDark, s.hideLogDSL, s.setHideLogDSL, s.setSelectedStep, s.reset, s.notificationBadge, s.notificationMessage, s.setPropertyPlaceholders], shallow)
+ [s.setDark, s.hideLogDSL, s.setHideLogDSL, s.setSelectedStep, s.reset, s.notificationBadge, s.notificationMessage, s.setPropertyPlaceholders, s.setBeans], shallow)
const [integration, setIntegration] = useIntegrationStore((s) =>
[s.integration, s.setIntegration], shallow)
@@ -87,6 +89,7 @@ export function KaravanDesigner(props: Props) {
reset();
setDark(props.dark);
setPropertyPlaceholders(props.propertyPlaceholders)
+ setBeans(props.beans)
setHideLogDSL(props.hideLogDSL === true);
return () => {
sub?.unsubscribe();
diff --git a/karavan-web/karavan-app/src/main/webui/src/designer/property/property/ComponentPropertyField.tsx b/karavan-web/karavan-app/src/main/webui/src/designer/property/property/ComponentPropertyField.tsx
index 402aaf8b..1287c18a 100644
--- a/karavan-web/karavan-app/src/main/webui/src/designer/property/property/ComponentPropertyField.tsx
+++ b/karavan-web/karavan-app/src/main/webui/src/designer/property/property/ComponentPropertyField.tsx
@@ -71,8 +71,8 @@ export function ComponentPropertyField(props: Props) {
const {onParametersChange, getInternalComponentName} = usePropertiesHook();
const [integration] = useIntegrationStore((state) => [state.integration], shallow)
- const [dark, setSelectedStep, propertyPlaceholders] = useDesignerStore((s) =>
- [s.dark, s.setSelectedStep, s.propertyPlaceholders], shallow)
+ const [dark, setSelectedStep, beans] = useDesignerStore((s) =>
+ [s.dark, s.setSelectedStep, s.beans], shallow)
const [selectStatus, setSelectStatus] = useState<Map<string, boolean>>(new Map<string, boolean>());
const [showEditor, setShowEditor] = useState<boolean>(false);
@@ -82,7 +82,6 @@ export function ComponentPropertyField(props: Props) {
const [id, setId] = useState<string>(prefix + "-" + props.property.name);
const ref = useRef<any>(null);
- const [isOpenPlaceholdersDropdown, setOpenPlaceholdersDropdown] = useState<boolean>(false);
function parametersChanged(parameter: string, value: string | number | boolean | any, pathParameter?: boolean, newRoute?: RouteToCreate) {
@@ -100,7 +99,6 @@ export function ComponentPropertyField(props: Props) {
function getSelectBean(property: ComponentProperty, value: any) {
const selectOptions: JSX.Element[] = [];
- const beans = CamelUi.getBeans(integration);
if (beans) {
selectOptions.push(<SelectOption key={0} value={"Select..."} isPlaceholder/>);
selectOptions.push(...beans.map((bean) => <SelectOption key={bean.name} value={beanPrefix + bean.name}
diff --git a/karavan-web/karavan-app/src/main/webui/src/project/FileEditor.tsx b/karavan-web/karavan-app/src/main/webui/src/project/FileEditor.tsx
index e5bece48..c3282166 100644
--- a/karavan-web/karavan-app/src/main/webui/src/project/FileEditor.tsx
+++ b/karavan-web/karavan-app/src/main/webui/src/project/FileEditor.tsx
@@ -23,8 +23,8 @@ import {useFilesStore, useFileStore} from "../api/ProjectStore";
import {KaravanDesigner} from "../designer/KaravanDesigner";
import {ProjectService} from "../api/ProjectService";
import {shallow} from "zustand/shallow";
-import {KaravanApi} from "../api/KaravanApi";
-import {getPropertyCode, getPropertyPlaceholders} from "../util/StringUtils";
+import {CodeUtils} from "../util/CodeUtils";
+import {RegistryBeanDefinition} from "karavan-core/src/core/model/CamelDefinition";
interface Props {
projectId: string
@@ -41,14 +41,21 @@ export function FileEditor (props: Props) {
const [file, designerTab] = useFileStore((s) => [s.file, s.designerTab], shallow )
const [files] = useFilesStore((s) => [s.files], shallow);
const [propertyPlaceholders, setPropertyPlaceholders] = useState<string[]>([]);
+ const [beans, setBeans] = useState<RegistryBeanDefinition[]>([]);
useEffect(() => {
- const pp = getPropertyPlaceholders(files);
+ const pp = CodeUtils.getPropertyPlaceholders(files);
setPropertyPlaceholders(prevState => {
prevState.length = 0;
prevState.push(...pp);
return prevState;
})
+ const bs = CodeUtils.getBeans(files);
+ setBeans(prevState => {
+ prevState.length = 0;
+ prevState.push(...bs);
+ return prevState;
+ })
}, []);
function save (name: string, code: string) {
@@ -86,6 +93,7 @@ export function FileEditor (props: Props) {
onGetCustomCode={onGetCustomCode}
propertyPlaceholders={propertyPlaceholders}
onSavePropertyPlaceholder={onSavePropertyPlaceholder}
+ beans={beans}
/>
)
}
diff --git a/karavan-web/karavan-app/src/main/webui/src/util/CodeUtils.ts b/karavan-web/karavan-app/src/main/webui/src/util/CodeUtils.ts
new file mode 100644
index 00000000..3962ad18
--- /dev/null
+++ b/karavan-web/karavan-app/src/main/webui/src/util/CodeUtils.ts
@@ -0,0 +1,46 @@
+import {ProjectFile} from "../api/ProjectModels";
+import {RegistryBeanDefinition} from "karavan-core/lib/model/CamelDefinition";
+import {Integration} from "karavan-core/lib/model/IntegrationDefinition";
+import {CamelDefinitionYaml} from "karavan-core/lib/api/CamelDefinitionYaml";
+import {CamelUi} from "../designer/utils/CamelUi";
+
+export class CodeUtils {
+
+ static getBeans(files: ProjectFile[]): RegistryBeanDefinition[] {
+ const result: RegistryBeanDefinition[] = [];
+ CodeUtils.getIntegrations(files).forEach(integration => {
+ const beans = CamelUi.getBeans(integration);
+ result.push(...beans);
+ })
+ return result;
+ }
+
+ static getIntegrations(files: ProjectFile[]): Integration[] {
+ return files
+ .filter(f => f.name.endsWith('.camel.yaml'))
+ .map(f => CamelDefinitionYaml.yamlToIntegration(f.name, f.code));
+ }
+
+ static getPropertyPlaceholders(files: ProjectFile[]): string[] {
+ const result: string[] = []
+ const code = CodeUtils.getPropertyCode(files);
+ if (code) {
+ const lines = code.split('\n').map((line) => line.trim());
+ lines
+ .filter(line => !line.startsWith("camel.") && !line.startsWith("jkube.") && !line.startsWith("jib."))
+ .filter(line => line !== undefined && line !== null && line.length > 0)
+ .forEach(line => {
+ const parts = line.split("=");
+ if (parts.length > 0) {
+ result.push(parts[0]);
+ }
+ })
+ }
+ return result;
+ }
+
+ static getPropertyCode(files: ProjectFile[]) {
+ const file = files.filter(f => f.name === 'application.properties')?.at(0);
+ return file?.code;
+ }
+}
\ No newline at end of file
diff --git a/karavan-web/karavan-app/src/main/webui/src/util/StringUtils.ts b/karavan-web/karavan-app/src/main/webui/src/util/StringUtils.ts
index 026dc7a1..2a149781 100644
--- a/karavan-web/karavan-app/src/main/webui/src/util/StringUtils.ts
+++ b/karavan-web/karavan-app/src/main/webui/src/util/StringUtils.ts
@@ -1,28 +1,3 @@
-import {ProjectFile} from "../api/ProjectModels";
-
export function isEmpty(str: string) {
return !str?.trim();
}
-
-export function getPropertyPlaceholders(files: ProjectFile[]): string[] {
- const result: string[] = []
- const code = getPropertyCode(files);
- if (code) {
- const lines = code.split('\n').map((line) => line.trim());
- lines
- .filter(line => !line.startsWith("camel.") && !line.startsWith("jkube.") && !line.startsWith("jib."))
- .filter(line => line !== undefined && line !== null && line.length > 0)
- .forEach(line => {
- const parts = line.split("=");
- if (parts.length > 0) {
- result.push(parts[0]);
- }
- })
- }
- return result;
-}
-
-export function getPropertyCode(files: ProjectFile[]) {
- const file = files.filter(f => f.name === 'application.properties')?.at(0);
- return file?.code;
-}
\ No newline at end of file