-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcustomKeyDropdownProvider.ts
More file actions
102 lines (82 loc) · 3.07 KB
/
customKeyDropdownProvider.ts
File metadata and controls
102 lines (82 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import SelectEntry from './bpmn-io-dependencies';
/**
* Custom properties provider that replaces the path entry
*/
class CustomKeyDropdownProvider {
private pathOptionsService: any;
private modeling: any;
static $inject = ['propertiesPanel', 'pathOptionsService', 'modeling'];
constructor(propertiesPanel: any, pathOptionsService: any, modeling: any) {
this.pathOptionsService = pathOptionsService;
this.modeling = modeling;
propertiesPanel.registerProvider(this, 500);
}
getGroups(field: any, editField: any) {
const pathOptionsService = this.pathOptionsService;
const modeling = this.modeling;
return function(groups: any[]) {
// Find and modify the general group that contains the path entry
const generalGroup = groups.find(g => g.id === 'general');
if (!generalGroup) {
return groups;
}
// For Group components, just remove the key field entirely (don't add dropdown)
if (field.type === 'group') {
generalGroup.entries = generalGroup.entries.filter(
(entry: any) => entry.id !== 'path'
);
}
// For Expression components, keep the original free-text key input
// (expression keys store computed results, not form input paths)
if (field.type === 'expression') {
return groups;
}
const curKeyEntry = generalGroup.entries.find((entry: any) => entry.id === 'key');
// Only replace the Key input with dropdown if it exists
if (curKeyEntry) {
// Remove the original key entry
generalGroup.entries = generalGroup.entries.filter(
(entry: any) => entry.id !== 'key'
);
// Add our custom dropdown key entry for non-group components
generalGroup.entries.unshift({
...curKeyEntry,
component: (props: any) => CustomKeyDropdown({ ...props, pathOptionsService, modeling })
});
}
return groups;
};
}
}
function CustomKeyDropdown(props: any) {
const { element: field, id, pathOptionsService, modeling } = props;
const getValue = () => { return field.key || '' };
const setValue = (value: string) => {
return modeling.editFormField(field, 'key', value);
};
const getOptions = () => {
// Get current field's key so it won't be disabled in the dropdown
const currentKey = field.key || '';
// Get the component type to filter compatible options
const componentType = field.type || '';
console.log(componentType);
// Get options from the injected service, passing current key to exclude from disabling
const options = pathOptionsService?.getOptions(currentKey, componentType) || [];
// Add empty option
return [{ value: field.id, label: '(none)' }, ...options];
};
return SelectEntry({
element: field,
id: id || 'key',
label: 'Key',
description: 'Select the data path for this field',
getValue,
setValue,
getOptions
});
}
// Module definition for didi
export const customKeyModule = {
__init__: ['customKeyDropdownProvider'],
customKeyDropdownProvider: ['type', CustomKeyDropdownProvider]
};