Skip to content

Commit

Permalink
Fix #511
Browse files Browse the repository at this point in the history
  • Loading branch information
mgubaidullin committed Dec 5, 2023
1 parent 1fa8176 commit 9db6f9b
Show file tree
Hide file tree
Showing 9 changed files with 1,811 additions and 1,702 deletions.
3,353 changes: 1,677 additions & 1,676 deletions karavan-core/src/core/model/CamelMetadata.ts

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions karavan-designer/public/example/demo.camel.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- routeConfiguration:
onException:
- onException:
id: onException-78ab
- route:
nodePrefixId: route-1e7
id: route-3f85
from:
uri: timer
id: from-cfa5
20 changes: 20 additions & 0 deletions karavan-designer/src/designer/route/property/DslPropertyField.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
.switch-placeholder {
margin: auto;
padding-right: 12px;
}
41 changes: 33 additions & 8 deletions karavan-designer/src/designer/route/property/DslPropertyField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
SelectOption
} from '@patternfly/react-core/deprecated';
import '../../karavan.css';
import './DslPropertyField.css';
import "@patternfly/patternfly/patternfly.css";
import HelpIcon from "@patternfly/react-icons/dist/js/icons/help-icon";
import DeleteIcon from "@patternfly/react-icons/dist/js/icons/times-circle-icon";
Expand Down Expand Up @@ -376,14 +377,39 @@ export function DslPropertyField(props: Props) {
}

function getSwitch(property: PropertyMeta, value: any) {
const isChecked = value !== undefined ? Boolean(value) : Boolean(property.defaultValue !== undefined && property.defaultValue === 'true');
const isValueBoolean = (value === true || value === false);
const isDisabled = value !== undefined && !isValueBoolean;
let isChecked = false;
if (value !== undefined && isValueBoolean) {
isChecked = Boolean(value);
} else if ((value === undefined || value.toString().length > 0) && property.defaultValue !== undefined) {
isChecked = property.defaultValue === 'true';
}
return (
<Switch
id={property.name} name={property.name}
value={value?.toString()}
aria-label={property.name}
isChecked={isChecked}
onChange={(_, v) => propertyChanged(property.name, v)}/>
<TextInputGroup className="input-group">
<InputGroupItem>
<Switch
isDisabled={isDisabled}
id={property.name + "-switch"}
name={property.name + "-switch"}
className="switch-placeholder"
value={value?.toString()}
aria-label={property.name}
isChecked={isChecked}
onChange={(_, v) => propertyChanged(property.name, v)}/>
</InputGroupItem>
{property.placeholder && <InputGroupItem isFill>
<TextInput
id={property.name + "-placeholder"}
name={property.name + "-placeholder"}
type="text"
aria-label="placeholder"
placeholder="Property placeholder"
value={!isValueBoolean ? value?.toString() : undefined}
onChange={(_, v) => propertyChanged(property.name, v)}
/>
</InputGroupItem>}
</TextInputGroup>
)
}

Expand Down Expand Up @@ -599,7 +625,6 @@ export function DslPropertyField(props: Props) {
}

function getMultiValueField(property: PropertyMeta, value: any) {
console.log(property)
return (
<div>
<TextInputGroup className="input-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private String generateModel(String classFullName, JsonObject obj, JsonObject de
attrs.add(" " + name + r + ": " + attributeType);
}
});

String s2 = String.join(";\n", attrs) + ((attrs.isEmpty()) ? "" : ";");
return String.format(readFileText(modelTemplate), className, s2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private String getMetadataCode(String className, Map<String, JsonObject> classPr
if (json != null) {
JsonObject model = new JsonObject(json).getJsonObject("model");
JsonObject props = new JsonObject(json).getJsonObject("properties");
List propsLowerCase = props.getMap().keySet().stream().map(s -> s.toLowerCase()).collect(Collectors.toList());
List<String> propsLowerCase = props.getMap().keySet().stream().map(String::toLowerCase).collect(Collectors.toList());

Comparator<String> comparator = Comparator.comparing(e -> {
if (propsLowerCase.contains(e.toLowerCase())) return propsLowerCase.indexOf(e.toLowerCase());
Expand All @@ -180,7 +180,7 @@ private String getMetadataCode(String className, Map<String, JsonObject> classPr
JsonObject p = props.getJsonObject(pname);
if ("inheritErrorHandler".equals(pname) && p == null) {
} else {

String typeInCatalog = getPropertyTypeInCatalog(stepName, pname);
PropertyMeta pm = getAttributeType(pname, new JsonObject((Map) v));
String displayName = p != null && p.containsKey("displayName") ? p.getString("displayName") : pname;
String desc = p != null && p.containsKey("description") ? p.getString("description") : pname;
Expand All @@ -191,10 +191,14 @@ private String getMetadataCode(String className, Map<String, JsonObject> classPr
defaultValue = defaultValue.length() == 1 && defaultValue.toCharArray()[0] == '\\' ? "\\\\" : defaultValue;
String labels = p != null && p.containsKey("label") ? p.getString("label") : "";
String javaType = getJavaType(p);
Boolean placeholder = Objects.equals(typeInCatalog, "string") && !Objects.equals(typeInCatalog, pm.type);
if (placeholder) {
System.out.println(name + " " + pname + " " + typeInCatalog);
}
if (name.equals("ProcessDefinition") && pname.equals("ref")) javaType = "org.apache.camel.Processor"; // exception for processor
code.append(String.format(
" new PropertyMeta('%s', '%s', \"%s\", '%s', '%s', '%s', %b, %b, %b, %b, '%s', '%s'),\n",
pname, displayName, desc, pm.type, en, defaultValue, required, secret, pm.isArray, (pm.isArray ? pm.type : pm.isObject), labels, javaType));
" new PropertyMeta('%s', '%s', \"%s\", '%s', '%s', '%s', %b, %b, %b, %b, '%s', '%s', %b),\n",
pname, displayName, desc, pm.type, en, defaultValue, required, secret, pm.isArray, (pm.isArray ? pm.type : pm.isObject), labels, javaType, placeholder));
}
});
code.append(" ]),\n");
Expand All @@ -204,6 +208,16 @@ private String getMetadataCode(String className, Map<String, JsonObject> classPr
return code.toString();
}

private String getPropertyTypeInCatalog(String model, String property) {
String json = getMetaModel(model);
if (json != null) {
JsonObject props = new JsonObject(json).getJsonObject("properties");
JsonObject values = props.getJsonObject(property);
return values != null ? values.getString("type") : null;
}
return null;
}

private String getJavaType(JsonObject p) {
if (p != null
&& p.containsKey("type")
Expand Down
5 changes: 3 additions & 2 deletions karavan-generator/src/main/resources/CamelMetadata.header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ export class PropertyMeta {
isObject: boolean = false
label: string = ''
javaType: string = ''

placeholder: boolean = false

constructor(name: string, displayName: string, description: string, type: string, enumVals: string,
defaultValue: string, required: boolean, secret: boolean, isArray: boolean, isObject: boolean,
label: string, javaType: string) {
label: string, javaType: string, placeholder: boolean) {
this.name = name;
this.displayName = displayName;
this.description = description;
Expand All @@ -67,6 +67,7 @@ export class PropertyMeta {
this.isObject = isObject;
this.label = label;
this.javaType = javaType;
this.placeholder = placeholder;
}
}

Expand Down
20 changes: 20 additions & 0 deletions karavan-space/src/designer/route/property/DslPropertyField.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
.switch-placeholder {
margin: auto;
padding-right: 12px;
}
41 changes: 33 additions & 8 deletions karavan-space/src/designer/route/property/DslPropertyField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
SelectOption
} from '@patternfly/react-core/deprecated';
import '../../karavan.css';
import './DslPropertyField.css';
import "@patternfly/patternfly/patternfly.css";
import HelpIcon from "@patternfly/react-icons/dist/js/icons/help-icon";
import DeleteIcon from "@patternfly/react-icons/dist/js/icons/times-circle-icon";
Expand Down Expand Up @@ -376,14 +377,39 @@ export function DslPropertyField(props: Props) {
}

function getSwitch(property: PropertyMeta, value: any) {
const isChecked = value !== undefined ? Boolean(value) : Boolean(property.defaultValue !== undefined && property.defaultValue === 'true');
const isValueBoolean = (value === true || value === false);
const isDisabled = value !== undefined && !isValueBoolean;
let isChecked = false;
if (value !== undefined && isValueBoolean) {
isChecked = Boolean(value);
} else if ((value === undefined || value.toString().length > 0) && property.defaultValue !== undefined) {
isChecked = property.defaultValue === 'true';
}
return (
<Switch
id={property.name} name={property.name}
value={value?.toString()}
aria-label={property.name}
isChecked={isChecked}
onChange={(_, v) => propertyChanged(property.name, v)}/>
<TextInputGroup className="input-group">
<InputGroupItem>
<Switch
isDisabled={isDisabled}
id={property.name + "-switch"}
name={property.name + "-switch"}
className="switch-placeholder"
value={value?.toString()}
aria-label={property.name}
isChecked={isChecked}
onChange={(_, v) => propertyChanged(property.name, v)}/>
</InputGroupItem>
{property.placeholder && <InputGroupItem isFill>
<TextInput
id={property.name + "-placeholder"}
name={property.name + "-placeholder"}
type="text"
aria-label="placeholder"
placeholder="Property placeholder"
value={!isValueBoolean ? value?.toString() : undefined}
onChange={(_, v) => propertyChanged(property.name, v)}
/>
</InputGroupItem>}
</TextInputGroup>
)
}

Expand Down Expand Up @@ -599,7 +625,6 @@ export function DslPropertyField(props: Props) {
}

function getMultiValueField(property: PropertyMeta, value: any) {
console.log(property)
return (
<div>
<TextInputGroup className="input-group">
Expand Down

0 comments on commit 9db6f9b

Please sign in to comment.