Skip to content

Commit

Permalink
feat(cloud-element-templates): provide property groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer committed Feb 1, 2022
1 parent 7dd4d0b commit b93a38a
Show file tree
Hide file tree
Showing 7 changed files with 666 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {
find,
forEach,
groupBy,
isString,
isUndefined
} from 'min-dash';
Expand Down Expand Up @@ -62,6 +65,11 @@ const IO_BINDING_TYPES = [
ZEEBE_OUTPUT_TYPE
];

const DEFAULT_CUSTOM_GROUP = {
id: 'ElementTemplates__CustomProperties',
label: 'Custom properties'
};


export function CustomProperties(props) {
const {
Expand All @@ -72,18 +80,64 @@ export function CustomProperties(props) {
const groups = [];

const {
id
id,
properties,
groups: propertyGroups
} = elementTemplate;

// (1) group properties by group id
const groupedProperties = groupByGroupId(properties);
const defaultProps = [];

forEach(groupedProperties, (properties, groupId) => {

const group = findCustomGroup(propertyGroups, groupId);

if (!group) {
return defaultProps.push(...properties);
}

addCustomGroup(groups, {
element,
id: `ElementTemplates__CustomProperties-${groupId}`,
label: group.label,
properties: properties,
templateId: `${id}-${groupId}`
});
});

// (2) add default custom props
if (defaultProps.length) {
addCustomGroup(groups, {
...DEFAULT_CUSTOM_GROUP,
element,
properties: defaultProps,
templateId: id
});
}

return groups;
}

function addCustomGroup(groups, props) {

const {
element,
id,
label,
properties,
templateId
} = props;

const customPropertiesGroup = {
id: 'ElementTemplates__CustomProperties',
label: 'Custom properties',
id,
label,
component: Group,
entries: []
};

elementTemplate.properties.forEach((property, index) => {
const entry = createCustomEntry(`custom-entry-${ id }-${ index }`, element, property);
properties.forEach((property, index) => {
const entry = createCustomEntry(`custom-entry-${ templateId }-${ index }`, element, property);

if (entry) {
customPropertiesGroup.entries.push(entry);
Expand All @@ -93,8 +147,6 @@ export function CustomProperties(props) {
if (customPropertiesGroup.entries.length) {
groups.push(customPropertiesGroup);
}

return groups;
}

function createCustomEntry(id, element, property) {
Expand Down Expand Up @@ -625,4 +677,12 @@ function isEmptyString(string) {

function matchesPattern(string, pattern) {
return new RegExp(pattern).test(string);
}

function groupByGroupId(properties) {
return groupBy(properties, 'group');
}

function findCustomGroup(groups, id) {
return find(groups, g => g.id === id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
</bpmn:serviceTask>
<bpmn:serviceTask id="Activity_1x04xy0" name="outdated" zeebe:modelerTemplate="io.camunda.connectors.RestConnector-outdated" zeebe:modelerTemplateVersion="1" />
<bpmn:serviceTask id="Activity_166ntf9" name="missing template" zeebe:modelerTemplate="io.camunda.connectors.RestConnector-missingTemplate" />
<bpmn:serviceTask id="Activity_1iof33f" name="groups" zeebe:modelerTemplate="io.camunda.connectors.RestConnector-groups" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0vvlc66">
Expand Down Expand Up @@ -68,6 +69,9 @@
<bpmndi:BPMNShape id="Activity_166ntf9_di" bpmnElement="Activity_166ntf9">
<dc:Bounds x="410" y="240" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1iof33f_di" bpmnElement="Activity_1iof33f">
<dc:Bounds x="550" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,92 @@
}
}
]
},
{
"name": "REST Connector (groups)",
"id": "io.camunda.connectors.RestConnector-groups",
"description": "A generic REST service.",
"appliesTo": [
"bpmn:ServiceTask"
],
"properties": [
{
"type": "Hidden",
"value": "http",
"binding": {
"type": "zeebe:taskDefinition:type"
}
},
{
"label": "REST Endpoint URL",
"description": "Specify the url of the REST API to talk to.",
"group": "headers",
"type": "String",
"binding": {
"type": "zeebe:taskHeader",
"key": "url"
},
"constraints": {
"notEmpty": true,
"pattern": {
"value": "^https?://.*",
"message": "Must be http(s) URL."
}
}
},
{
"label": "REST Method",
"description": "Specify the HTTP method to use.",
"group": "headers",
"type": "Dropdown",
"value": "get",
"choices": [
{ "name": "GET", "value": "get" },
{ "name": "POST", "value": "post" },
{ "name": "PATCH", "value": "patch" },
{ "name": "DELETE", "value": "delete" }
],
"binding": {
"type": "zeebe:taskHeader",
"key": "method"
}
},
{
"label": "Request Body",
"description": "Data to send to the endpoint.",
"value": "",
"group": "payload",
"type": "String",
"binding": {
"type": "zeebe:input",
"name": "body"
}
},
{
"label": "Result Variable",
"description": "Name of variable to store the response data in.",
"group": "mapping",
"value": "response",
"type": "String",
"binding": {
"type": "zeebe:output",
"source": "= body"
}
}
],
"groups": [
{
"id": "headers",
"label": "Request headers"
},
{
"id": "payload",
"label": "Request payload"
},
{
"id": "mapping",
"label": "Response mapping"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
[
{
"name": "REST Connector",
"id": "io.camunda.connectors.RestConnector-s1",
"description": "A generic REST service.",
"appliesTo": [
"bpmn:ServiceTask"
],
"properties": [
{
"type": "String",
"value": "http",
"binding": {
"type": "zeebe:taskDefinition:type"
}
},
{
"label": "REST Endpoint URL",
"description": "Specify the url of the REST API to talk to.",
"group": "headers",
"type": "String",
"binding": {
"type": "zeebe:taskHeader",
"key": "url"
},
"constraints": {
"notEmpty": true,
"pattern": {
"value": "^https?://.*",
"message": "Must be http(s) URL."
}
}
},
{
"label": "REST Method",
"description": "Specify the HTTP method to use.",
"group": "headers",
"type": "Dropdown",
"value": "get",
"choices": [
{ "name": "GET", "value": "get" },
{ "name": "POST", "value": "post" },
{ "name": "PATCH", "value": "patch" },
{ "name": "DELETE", "value": "delete" }
],
"binding": {
"type": "zeebe:taskHeader",
"key": "method"
}
},
{
"label": "Request Body",
"description": "Data to send to the endpoint.",
"value": "",
"group": "payload",
"type": "String",
"binding": {
"type": "zeebe:input",
"name": "body"
},
"constraints": {
"optional": true
}
},
{
"label": "Result Variable",
"description": "Name of variable to store the response data in.",
"group": "mapping",
"value": "response",
"type": "String",
"binding": {
"type": "zeebe:output",
"source": "= body"
},
"constraints": {
"optional": true
}
}
],
"groups": [
{
"id": "headers",
"label": "Request headers"
},
{
"id": "payload",
"label": "Request payload"
},
{
"id": "mapping",
"label": "Response mapping"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_165ah7c" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.13.0-nightly.20220113" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="1.3.0">
<bpmn:process id="Process_0vvlc66" isExecutable="true">
<bpmn:serviceTask id="ServiceTask_1" name="groups" zeebe:modelerTemplate="example.com.grouping">
<bpmn:extensionElements>
<zeebe:taskDefinition type="http" />
<zeebe:taskHeaders>
<zeebe:header key="method" value="get" />
<zeebe:header key="url" />
</zeebe:taskHeaders>
<zeebe:ioMapping>
<zeebe:input source="= invoiceDetails" target="body" />
<zeebe:output source="= body" target="response" />
</zeebe:ioMapping>
</bpmn:extensionElements>
</bpmn:serviceTask>
<bpmn:serviceTask id="ServiceTask_noDefault" name="no default" zeebe:modelerTemplate="example.com.grouping-noDefault" />
<bpmn:serviceTask id="ServiceTask_noGroups" name="no groups" zeebe:modelerTemplate="example.com.grouping-noGroups" />
<bpmn:serviceTask id="ServiceTask_nonExisting" name="non existing group" zeebe:modelerTemplate="example.com.grouping-nonExisting" />
<bpmn:serviceTask id="ServiceTask_noEntries" name="no entries" zeebe:modelerTemplate="example.com.grouping-noEntries" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0vvlc66">
<bpmndi:BPMNShape id="Activity_1328y3k_di" bpmnElement="ServiceTask_1">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_noDefault_di" bpmnElement="ServiceTask_noDefault">
<dc:Bounds x="270" y="190" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_noGroups_di" bpmnElement="ServiceTask_noGroups">
<dc:Bounds x="270" y="310" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_nonExisting_di" bpmnElement="ServiceTask_nonExisting">
<dc:Bounds x="270" y="420" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_noEntries_di" bpmnElement="ServiceTask_noEntries">
<dc:Bounds x="270" y="540" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Loading

0 comments on commit b93a38a

Please sign in to comment.