@@ -3,13 +3,19 @@ import { AddRegular } from '@fluentui/react-icons';
3
3
import { useDispatch , useSelector } from 'react-redux' ;
4
4
import type { RootState } from '../../../core/state/Store' ;
5
5
import type { FunctionData , FunctionDictionary } from '../../../models' ;
6
- import type { ConnectionDictionary , ConnectionUnit , InputConnection } from '../../../models/Connection' ;
6
+ import type { ConnectionDictionary , NodeConnection , InputConnection , EmptyConnection } from '../../../models/Connection' ;
7
7
import type { InputOptionProps } from '../inputDropdown/InputDropdown' ;
8
8
import { useStyles } from '../styles' ;
9
9
import { List } from '@fluentui/react-list-preview' ;
10
10
import type { SchemaNodeDictionary } from '@microsoft/logic-apps-shared' ;
11
11
import { SchemaType } from '@microsoft/logic-apps-shared' ;
12
- import { flattenInputs , newConnectionWillHaveCircularLogic } from '../../../utils/Connection.Utils' ;
12
+ import {
13
+ createNewEmptyConnection ,
14
+ isNodeConnection ,
15
+ isEmptyConnection ,
16
+ newConnectionWillHaveCircularLogic ,
17
+ createCustomInputConnection ,
18
+ } from '../../../utils/Connection.Utils' ;
13
19
import { makeConnectionFromMap , setConnectionInput } from '../../../core/state/DataMapSlice' ;
14
20
import { useState } from 'react' ;
15
21
import { isSchemaNodeExtended } from '../../../utils' ;
@@ -24,36 +30,38 @@ export const OutputTabContents = (props: {
24
30
const functionNodeDictionary = useSelector ( ( state : RootState ) => state . dataMap . present . curDataMapOperation . functionNodes ) ;
25
31
const connections = useSelector ( ( state : RootState ) => state . dataMap . present . curDataMapOperation . dataMapConnections ) ;
26
32
const styles = useStyles ( ) ;
27
- const outputs : ( ConnectionUnit | undefined ) [ ] = [ ...connections [ props . functionId ] . outputs ] ;
33
+ const outputs : ( NodeConnection | EmptyConnection | undefined ) [ ] = [ ...connections [ props . functionId ] . outputs ] ;
28
34
const dispatch = useDispatch ( ) ;
29
- const [ additionalOutput , setAdditionalOutput ] = useState < ( ConnectionUnit | undefined ) [ ] > ( [ ] ) ;
35
+ const [ additionalOutput , setAdditionalOutput ] = useState < ( NodeConnection | EmptyConnection | undefined ) [ ] > ( [ ] ) ;
30
36
31
37
if ( outputs . length === 0 ) {
32
38
outputs [ 0 ] = undefined ;
33
39
}
34
40
35
41
const addOutputClick = ( ) => {
36
- setAdditionalOutput ( [ ...additionalOutput , undefined ] ) ;
42
+ setAdditionalOutput ( [ ...additionalOutput , createNewEmptyConnection ( ) ] ) ;
37
43
} ;
38
44
39
45
const getIDForTargetConnection = ( connection : InputConnection ) => {
40
- if ( connection === undefined ) {
46
+ if ( connection === undefined || ! isNodeConnection ( connection ) ) {
41
47
return '' ;
42
48
}
43
- if ( typeof connection === 'string' ) {
44
- return connection ;
45
- }
46
49
return connection . reactFlowKey ;
47
50
} ;
48
51
49
- const removeConnection = ( newOutput : InputConnection ) => {
52
+ const removeConnection = ( newOutput ? : InputConnection ) => {
50
53
if ( newOutput === undefined ) {
51
54
return ;
52
55
}
56
+ if ( ! isNodeConnection ( newOutput ) ) {
57
+ const shortenedOutput = additionalOutput . slice ( 0 , additionalOutput . length - 2 ) ;
58
+ setAdditionalOutput ( shortenedOutput ) ;
59
+ return ;
60
+ }
53
61
const dest = getIDForTargetConnection ( newOutput ) ;
54
62
const destinationNode = connectionDictionary [ dest ] ;
55
- const flattened = flattenInputs ( destinationNode . inputs ) ;
56
- const index = flattened . findIndex ( ( input ) => getIDForTargetConnection ( input ) === props . functionId ) ;
63
+ const inputs = destinationNode . inputs ;
64
+ const index = inputs . findIndex ( ( input ) => getIDForTargetConnection ( input ) === props . functionId ) ;
57
65
dispatch (
58
66
setConnectionInput ( {
59
67
targetNode : destinationNode . self . node ,
@@ -80,9 +88,11 @@ export const OutputTabContents = (props: {
80
88
const validateAndCreateConnection = (
81
89
optionValue : string | undefined ,
82
90
option : InputOptionProps | undefined ,
83
- oldOutput : InputConnection
91
+ oldOutput : InputConnection | undefined
84
92
) => {
85
- removeConnection ( oldOutput ) ;
93
+ if ( oldOutput !== undefined ) {
94
+ removeConnection ( oldOutput ) ;
95
+ }
86
96
if ( optionValue ) {
87
97
const newOutput = validateAndCreateConnectionOutput (
88
98
optionValue ,
@@ -104,7 +114,9 @@ export const OutputTabContents = (props: {
104
114
< List >
105
115
{ outputs . concat ( additionalOutput ) . map ( ( output , index ) => {
106
116
let outputValue = undefined ;
107
- if ( output ) {
117
+ if ( output && isEmptyConnection ( output ) ) {
118
+ outputValue = '' ;
119
+ } else if ( output ) {
108
120
outputValue = isSchemaNodeExtended ( output ?. node ) ? output ?. node . name : '' ;
109
121
}
110
122
const listItem = (
@@ -163,15 +175,17 @@ const validateAndCreateConnectionOutput = (
163
175
164
176
// Create connection
165
177
const output = isSelectedOutputFunction ? functionNodeDictionary [ selectedOutputKey ] : sourceSchemaDictionary [ selectedOutputKey ] ;
166
- const srcConUnit : ConnectionUnit = {
178
+ const srcConUnit : NodeConnection = {
167
179
node : output ,
168
180
reactFlowKey : selectedOutputKey ,
181
+ isCustom : false ,
182
+ isDefined : true ,
169
183
} ;
170
184
171
185
return srcConUnit ;
172
186
}
173
187
// Create custom value connection
174
- const srcConUnit : InputConnection = optionValue ;
188
+ const srcConUnit : InputConnection = createCustomInputConnection ( optionValue ) ;
175
189
176
190
return srcConUnit ;
177
191
}
0 commit comments