Skip to content

Commit 8488d1d

Browse files
kresimir-cokoivicac
authored andcommitted
1715 - use label instead of type for SubPropertyPopover and adjust types
1 parent 58b77e7 commit 8488d1d

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

client/src/pages/platform/workflow-editor/components/Properties/ArrayProperty.tsx

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@ interface ArrayPropertyProps {
1818
property: PropertyAllType;
1919
}
2020

21-
type ValuePropertyControlType = keyof typeof VALUE_PROPERTY_CONTROL_TYPES;
22-
2321
const initialAvailablePropertyTypes = Object.keys(VALUE_PROPERTY_CONTROL_TYPES).map((type) => ({
24-
label: type as ValuePropertyControlType,
25-
value: type as ValuePropertyControlType,
22+
label: type as string,
23+
value: type as string,
2624
}));
2725

2826
const ArrayProperty = ({onDeleteClick, path, property}: ArrayPropertyProps) => {
2927
const [arrayItems, setArrayItems] = useState<Array<ArrayPropertyType | Array<ArrayPropertyType>>>([]);
3028
const [availablePropertyTypes, setAvailablePropertyTypes] =
31-
useState<Array<{label: ValuePropertyControlType; value: ValuePropertyControlType}>>(
32-
initialAvailablePropertyTypes
33-
);
34-
const [newPropertyType, setNewPropertyType] = useState<ValuePropertyControlType>();
29+
useState<Array<{label: string; value: string}>>(initialAvailablePropertyTypes);
30+
const [newPropertyType, setNewPropertyType] = useState<string>();
3531

3632
const {currentComponent} = useWorkflowNodeDetailsPanelStore();
3733

@@ -44,18 +40,24 @@ const ArrayProperty = ({onDeleteClick, path, property}: ArrayPropertyProps) => {
4440
return;
4541
}
4642

43+
const controlType: ControlType = matchingItem
44+
? (matchingItem.controlType as ControlType)
45+
: newPropertyType && newPropertyType in VALUE_PROPERTY_CONTROL_TYPES
46+
? (VALUE_PROPERTY_CONTROL_TYPES[
47+
newPropertyType as keyof typeof VALUE_PROPERTY_CONTROL_TYPES
48+
] as ControlType)
49+
: ('STRING' as ControlType);
50+
4751
const newItem = {
4852
...matchingItem,
49-
controlType: matchingItem
50-
? matchingItem?.controlType
51-
: (VALUE_PROPERTY_CONTROL_TYPES[newPropertyType!] as ControlType),
53+
controlType,
5254
custom: true,
5355
expressionEnabled: true,
5456
key: getRandomId(),
5557
label: `Item ${arrayItems.length.toString()}`,
5658
name: `${name}__${arrayItems.length.toString()}`,
5759
path: `${path}[${arrayItems.length.toString()}]`,
58-
type: matchingItem?.type || newPropertyType || 'STRING',
60+
type: (matchingItem?.type as PropertyType) || (newPropertyType as PropertyType) || 'STRING',
5961
};
6062

6163
setArrayItems([...arrayItems, newItem]);
@@ -75,24 +77,24 @@ const ArrayProperty = ({onDeleteClick, path, property}: ArrayPropertyProps) => {
7577

7678
// get available property types from items and additional properties
7779
useEffect(() => {
78-
let propertyTypes: Array<{label: ValuePropertyControlType; value: ValuePropertyControlType}> = [];
80+
let propertyTypes: Array<{label: string; value: string}> = [];
7981

8082
const hasDuplicateTypes = items?.some(
8183
(item, index) => items.findIndex((otherItem) => otherItem.type === item.type) !== index
8284
);
8385

8486
const processItems = (items: Array<PropertyAllType>) =>
85-
items.reduce((types: Array<{label: ValuePropertyControlType; value: ValuePropertyControlType}>, item) => {
87+
items.reduce((types: Array<{label: string; value: string}>, item) => {
8688
if (item.type) {
8789
if (currentComponent?.componentName === 'condition' && hasDuplicateTypes) {
8890
types.push({
89-
label: item.label,
91+
label: item.label ?? item.type,
9092
value: `${item.type}_${item.label}`,
9193
});
9294
} else {
9395
types.push({
94-
label: item.type as ValuePropertyControlType,
95-
value: item.type as ValuePropertyControlType,
96+
label: item.type,
97+
value: item.type,
9698
});
9799
}
98100
}
@@ -130,7 +132,7 @@ const ArrayProperty = ({onDeleteClick, path, property}: ArrayPropertyProps) => {
130132

131133
useEffect(() => {
132134
if (currentComponent?.componentName === 'condition' && availablePropertyTypes.length) {
133-
setNewPropertyType(availablePropertyTypes[0].label);
135+
setNewPropertyType(availablePropertyTypes[0].value);
134136
}
135137
}, [currentComponent?.componentName, availablePropertyTypes]);
136138

@@ -187,11 +189,16 @@ const ArrayProperty = ({onDeleteClick, path, property}: ArrayPropertyProps) => {
187189
parameterItemType = 'ARRAY';
188190
}
189191

192+
const controlType: ControlType =
193+
parameterItemType && parameterItemType in VALUE_PROPERTY_CONTROL_TYPES
194+
? (VALUE_PROPERTY_CONTROL_TYPES[
195+
parameterItemType as keyof typeof VALUE_PROPERTY_CONTROL_TYPES
196+
] as ControlType)
197+
: ('STRING' as ControlType);
198+
190199
const newSubProperty = {
191200
arrayName: name,
192-
controlType: VALUE_PROPERTY_CONTROL_TYPES[
193-
parameterItemType as ValuePropertyControlType
194-
] as ControlType,
201+
controlType,
195202
custom: true,
196203
defaultValue: parameterItemValue,
197204
expressionEnabled: true,

client/src/pages/platform/workflow-editor/components/Properties/components/SubPropertyPopover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface SubPropertyPopoverProps {
1414
condition?: boolean;
1515
handleClick: () => void;
1616
newPropertyName?: string;
17-
newPropertyType: keyof typeof VALUE_PROPERTY_CONTROL_TYPES;
17+
newPropertyType: keyof typeof VALUE_PROPERTY_CONTROL_TYPES | string;
1818
setNewPropertyName?: (value: string) => void;
1919
setNewPropertyType: (value: keyof typeof VALUE_PROPERTY_CONTROL_TYPES) => void;
2020
}

0 commit comments

Comments
 (0)