From b78e8165eaeab382ed845e12f5e83c8985bccbab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20=C4=8Coko?= Date: Mon, 18 Nov 2024 11:59:23 +0100 Subject: [PATCH 1/2] 1715 - introduce a condition flag for the SubPropertyPopover because it has TYPE overlaps --- .../components/Properties/ArrayProperty.tsx | 33 ++++++++++++-- .../Properties/components/PropertySelect.tsx | 4 +- .../components/SubPropertyPopover.tsx | 43 +++++++++++++------ 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/client/src/pages/platform/workflow-editor/components/Properties/ArrayProperty.tsx b/client/src/pages/platform/workflow-editor/components/Properties/ArrayProperty.tsx index c480b935411..8d978216d01 100644 --- a/client/src/pages/platform/workflow-editor/components/Properties/ArrayProperty.tsx +++ b/client/src/pages/platform/workflow-editor/components/Properties/ArrayProperty.tsx @@ -77,14 +77,26 @@ const ArrayProperty = ({onDeleteClick, path, property}: ArrayPropertyProps) => { useEffect(() => { let propertyTypes: Array<{label: ValuePropertyControlType; value: ValuePropertyControlType}> = []; + const hasDuplicateTypes = items?.some( + (item, index) => items.findIndex((otherItem) => otherItem.type === item.type) !== index + ); + const processItems = (items: Array) => items.reduce((types: Array<{label: ValuePropertyControlType; value: ValuePropertyControlType}>, item) => { if (item.type) { - types.push({ - label: item.type as ValuePropertyControlType, - value: item.type as ValuePropertyControlType, - }); + if (currentComponent?.componentName === 'condition' && hasDuplicateTypes) { + types.push({ + label: item.label, + value: `${item.type}_${item.label}`, + }); + } else { + types.push({ + label: item.type as ValuePropertyControlType, + value: item.type as ValuePropertyControlType, + }); + } } + return types; }, []); @@ -116,6 +128,12 @@ const ArrayProperty = ({onDeleteClick, path, property}: ArrayPropertyProps) => { } }, [availablePropertyTypes]); + useEffect(() => { + if (currentComponent?.componentName === 'condition' && availablePropertyTypes.length) { + setNewPropertyType(availablePropertyTypes[0].label); + } + }, [currentComponent?.componentName, availablePropertyTypes]); + // render individual array items with data gathered from parameters useEffect(() => { if ( @@ -236,6 +254,12 @@ const ArrayProperty = ({onDeleteClick, path, property}: ArrayPropertyProps) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + useEffect(() => { + if (property.items?.length) { + setArrayItems(property.items); + } + }, [property.items]); + return (
    @@ -272,6 +296,7 @@ const ArrayProperty = ({onDeleteClick, path, property}: ArrayPropertyProps) => { @@ -136,7 +136,7 @@ const PropertySelect = ({ ) : ( - + {option.label} ) diff --git a/client/src/pages/platform/workflow-editor/components/Properties/components/SubPropertyPopover.tsx b/client/src/pages/platform/workflow-editor/components/Properties/components/SubPropertyPopover.tsx index 29ba8810627..8337dad7bcc 100644 --- a/client/src/pages/platform/workflow-editor/components/Properties/components/SubPropertyPopover.tsx +++ b/client/src/pages/platform/workflow-editor/components/Properties/components/SubPropertyPopover.tsx @@ -11,6 +11,7 @@ import PropertySelect from './PropertySelect'; interface SubPropertyPopoverProps { array?: boolean; availablePropertyTypes: Array<{label: string; value: string}>; + condition?: boolean; handleClick: () => void; newPropertyName?: string; newPropertyType: keyof typeof VALUE_PROPERTY_CONTROL_TYPES; @@ -21,6 +22,7 @@ interface SubPropertyPopoverProps { const SubPropertyPopover = ({ array, availablePropertyTypes, + condition, handleClick, newPropertyName, newPropertyType, @@ -77,29 +79,44 @@ const SubPropertyPopover = ({ /> )} - {availablePropertyTypes?.length > 1 ? ( + {condition && availablePropertyTypes?.length > 1 && ( setNewPropertyType(value as keyof typeof VALUE_PROPERTY_CONTROL_TYPES) } options={availablePropertyTypes.map((property) => ({ - label: property.value!, - value: property.value!, + label: property.label!, + value: property.label!, }))} value={newPropertyType} /> - ) : ( -
    - Type - - {availablePropertyTypes[0] && ( - - {availablePropertyTypes[0].value} - - )} -
    )} + + {!condition && + (availablePropertyTypes?.length > 1 ? ( + + setNewPropertyType(value as keyof typeof VALUE_PROPERTY_CONTROL_TYPES) + } + options={availablePropertyTypes.map((property) => ({ + label: property.label!, + value: property.value!, + }))} + value={newPropertyType} + /> + ) : ( +
    + Type + + {availablePropertyTypes[0] && ( + + {availablePropertyTypes[0].value} + + )} +
    + ))}