@@ -17,21 +17,31 @@ export const WaldiezAgentSwarmHandoffs = (props: WaldiezAgentSwarmHandoffsProps)
17
17
const onConditionHandoffsCount = agentOnConditionHandoffs . length ;
18
18
const afterWorkHandoffs = agentHandoffs . filter ( isAfterWork ) ;
19
19
const onMoveAgentHandoffUp = ( index : number ) => {
20
- const onConditions = [ ...agentOnConditionHandoffs ] ;
21
- const temp = onConditions [ index ] ;
22
- onConditions [ index - 1 ] . target . order = index ;
23
- onConditions [ index ] = onConditions [ index - 1 ] ;
24
- onConditions [ index - 1 ] = temp ;
20
+ const tmpConditions = [ ...agentOnConditionHandoffs ] as WaldiezSwarmOnCondition [ ] ;
21
+ //swap the members and sort by .order
22
+ const prev = tmpConditions [ index - 1 ] ;
23
+ const thisCondition = tmpConditions [ index ] ;
24
+ tmpConditions [ index - 1 ] = thisCondition ;
25
+ tmpConditions [ index ] = prev ;
26
+ const onConditions = tmpConditions . map ( ( condition , i ) => {
27
+ condition . target . order = i ;
28
+ return condition ;
29
+ } ) ;
25
30
setToSort ( [ ...onConditions ] ) ;
26
31
const allHandoffs = [ ...onConditions , ...afterWorkHandoffs ] ;
27
32
onDataChange ( { handoffs : allHandoffs } ) ;
28
33
} ;
29
34
const onMoveAgentHandoffDown = ( index : number ) => {
30
- const onConditions = [ ...agentOnConditionHandoffs ] ;
31
- const temp = onConditions [ index ] ;
32
- onConditions [ index + 1 ] . target . order = index ;
33
- onConditions [ index ] = onConditions [ index + 1 ] ;
34
- onConditions [ index + 1 ] = temp ;
35
+ const tmpConditions = [ ...agentOnConditionHandoffs ] ;
36
+ //swap the members and sort by .order
37
+ const next = tmpConditions [ index + 1 ] ;
38
+ const thisCondition = tmpConditions [ index ] ;
39
+ tmpConditions [ index + 1 ] = thisCondition ;
40
+ tmpConditions [ index ] = next ;
41
+ const onConditions = tmpConditions . map ( ( condition , i ) => {
42
+ condition . target . order = i ;
43
+ return condition ;
44
+ } ) ;
35
45
setToSort ( [ ...onConditions ] ) ;
36
46
const allHandoffs = [ ...onConditions , ...afterWorkHandoffs ] ;
37
47
onDataChange ( { handoffs : allHandoffs } ) ;
0 commit comments