Skip to content

Commit 23c3974

Browse files
prakashpalanisamybarmac
authored andcommitted
feat: add hint for the process ID field in Camunda 7
Closes #1038
1 parent 90ae4bb commit 23c3974

File tree

7 files changed

+230
-3
lines changed

7 files changed

+230
-3
lines changed

src/provider/bpmn/properties/IdProps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313

1414
import {
1515
isIdValid
16-
} from '../utils/ValidationUtil';
16+
} from '../../../utils/ValidationUtil';
1717

1818

1919
/**

src/provider/bpmn/properties/ProcessProps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
import {
1212
isIdValid
13-
} from '../utils/ValidationUtil';
13+
} from '../../../utils/ValidationUtil';
1414

1515
/**
1616
* @typedef { import('@bpmn-io/properties-panel').EntryDefinition } Entry

src/provider/camunda-platform/CamundaPlatformPropertiesProvider.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
FormDataProps,
2121
FormProps,
2222
HistoryCleanupProps,
23+
IdProps,
2324
ImplementationProps,
2425
InitiatorProps,
2526
InMappingPropagationProps,
@@ -30,6 +31,7 @@ import {
3031
OutMappingPropagationProps,
3132
OutMappingProps,
3233
OutputProps,
34+
ProcessProps,
3335
ExecutionListenerProps,
3436
TaskListenerProps,
3537
ProcessVariablesProps,
@@ -162,7 +164,17 @@ function updateGeneralGroup(groups, element) {
162164

163165
const { entries } = generalGroup;
164166

165-
// (1) add version tag before executable (if existing)
167+
// (1) replace id with camunda id
168+
const idIndex = findIndex(entries, (entry) => entry.id === 'id');
169+
entries.splice(idIndex, 1, ...IdProps());
170+
171+
// (2) replace processId with camunda processId (if existing)
172+
const processIdIndex = findIndex(entries, (entry) => entry.id === 'processId');
173+
if (processIdIndex && processIdIndex >= 0) {
174+
entries.splice(processIdIndex, 1, ...ProcessProps({ element }));
175+
}
176+
177+
// (3) add version tag before executable (if existing)
166178
const executableEntry = findIndex(entries, (entry) => entry.id === 'isExecutable');
167179
const insertIndex = executableEntry >= 0 ? executableEntry : entries.length;
168180

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import {
2+
getBusinessObject,
3+
is
4+
} from 'bpmn-js/lib/util/ModelUtil';
5+
6+
import { TextFieldEntry, isTextFieldEntryEdited } from '@bpmn-io/properties-panel';
7+
8+
import { useCallback } from '@bpmn-io/properties-panel/preact/hooks';
9+
10+
import {
11+
useService
12+
} from '../../../hooks';
13+
14+
import {
15+
isIdValid
16+
} from '../../../utils/ValidationUtil';
17+
18+
19+
/**
20+
* @typedef { import('@bpmn-io/properties-panel').EntryDefinition } Entry
21+
*/
22+
23+
/**
24+
* @returns {Array<Entry>} entries
25+
*/
26+
export function IdProps() {
27+
return [
28+
{
29+
id: 'id',
30+
component: Id,
31+
isEdited: isTextFieldEntryEdited
32+
}
33+
];
34+
}
35+
36+
function Id(props) {
37+
const {
38+
element
39+
} = props;
40+
41+
const modeling = useService('modeling');
42+
const debounce = useService('debounceInput');
43+
const translate = useService('translate');
44+
45+
const setValue = (value, error) => {
46+
if (error) {
47+
return;
48+
}
49+
50+
modeling.updateProperties(element, {
51+
id: value
52+
});
53+
};
54+
55+
const getValue = useCallback((element) => {
56+
return getBusinessObject(element).id;
57+
}, [ element ]);
58+
59+
const validate = useCallback((value) => {
60+
const businessObject = getBusinessObject(element);
61+
62+
return isIdValid(businessObject, value, translate);
63+
}, [ element, translate ]);
64+
65+
const description = is(element, 'bpmn:Process') ?
66+
translate('This maps to the process definition key.')
67+
: null;
68+
69+
return TextFieldEntry({
70+
element,
71+
id: 'id',
72+
label: translate(is(element, 'bpmn:Participant') ? 'Participant ID' : 'ID'),
73+
getValue,
74+
setValue,
75+
debounce,
76+
validate,
77+
description
78+
});
79+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import { is } from 'bpmn-js/lib/util/ModelUtil';
2+
3+
import { TextFieldEntry, isTextFieldEntryEdited } from '@bpmn-io/properties-panel';
4+
5+
import { useCallback } from '@bpmn-io/properties-panel/preact/hooks';
6+
7+
import {
8+
useService
9+
} from '../../../hooks';
10+
11+
import {
12+
isIdValid
13+
} from '../../../utils/ValidationUtil';
14+
15+
/**
16+
* @typedef { import('@bpmn-io/properties-panel').EntryDefinition } Entry
17+
*/
18+
19+
/**
20+
* @returns {Array<Entry>} entries
21+
*/
22+
export function ProcessProps(props) {
23+
const {
24+
element
25+
} = props;
26+
27+
if (!hasProcessRef(element)) {
28+
return [];
29+
}
30+
31+
return [
32+
{
33+
id: 'processId',
34+
component: ProcessId,
35+
isEdited: isTextFieldEntryEdited
36+
},
37+
{
38+
id: 'processName',
39+
component: ProcessName,
40+
isEdited: isTextFieldEntryEdited
41+
}
42+
];
43+
}
44+
45+
function ProcessName(props) {
46+
const { element } = props;
47+
48+
const commandStack = useService('commandStack');
49+
const translate = useService('translate');
50+
const debounce = useService('debounceInput');
51+
const process = element.businessObject.get('processRef');
52+
53+
const getValue = () => {
54+
return process.get('name');
55+
};
56+
57+
const setValue = (value) => {
58+
commandStack.execute(
59+
'element.updateModdleProperties',
60+
{
61+
element,
62+
moddleElement: process,
63+
properties: {
64+
name: value
65+
}
66+
}
67+
);
68+
};
69+
70+
return TextFieldEntry({
71+
element,
72+
id: 'processName',
73+
label: translate('Process name'),
74+
getValue,
75+
setValue,
76+
debounce
77+
});
78+
}
79+
80+
function ProcessId(props) {
81+
const { element } = props;
82+
83+
const commandStack = useService('commandStack');
84+
const translate = useService('translate');
85+
const debounce = useService('debounceInput');
86+
const process = element.businessObject.get('processRef');
87+
88+
const getValue = () => {
89+
return process.get('id');
90+
};
91+
92+
const setValue = (value, error) => {
93+
if (error) {
94+
return;
95+
}
96+
97+
commandStack.execute(
98+
'element.updateModdleProperties',
99+
{
100+
element,
101+
moddleElement: process,
102+
properties: {
103+
id: value
104+
}
105+
}
106+
);
107+
};
108+
109+
const validate = useCallback((value) => {
110+
return isIdValid(process, value, translate);
111+
}, [ process, translate ]);
112+
113+
const description = is(element, 'bpmn:Participant') ?
114+
translate('This maps to the process definition key.')
115+
: null;
116+
117+
return TextFieldEntry({
118+
element,
119+
id: 'processId',
120+
label: translate('Process ID'),
121+
getValue,
122+
setValue,
123+
debounce,
124+
validate,
125+
description
126+
});
127+
}
128+
129+
130+
// helper ////////////////
131+
132+
function hasProcessRef(element) {
133+
return is(element, 'bpmn:Participant') && element.businessObject.get('processRef');
134+
}

src/provider/camunda-platform/properties/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ export { TasklistProps } from './TasklistProps';
3131
export { UserAssignmentProps } from './UserAssignmentProps';
3232
export { VersionTagProps } from './VersionTagProps';
3333
export { TimerProps } from './TimerProps';
34+
export { IdProps } from './IdProps';
35+
export { ProcessProps } from './ProcessProps';
File renamed without changes.

0 commit comments

Comments
 (0)