@@ -32,9 +32,11 @@ export const EditorOperatorName = <T extends FieldValues>({
32
32
name,
33
33
control,
34
34
rules,
35
+ operators,
35
36
...controllerProps
36
37
} : EditorFieldProps < T , string > & {
37
38
groups ?: CopilotDocV1 . Group [ ]
39
+ operators ?: CopilotDocV1 . Operator [ ]
38
40
} ) => {
39
41
const entityName = useMemo ( ( ) => ( groups ? '干员或干员组' : '干员' ) , [ groups ] )
40
42
@@ -48,10 +50,25 @@ export const EditorOperatorName = <T extends FieldValues>({
48
50
...controllerProps ,
49
51
} )
50
52
51
- const items : PerformerItem [ ] = useMemo (
52
- ( ) => [ ...( groups || [ ] ) , ...OPERATORS ] ,
53
- [ groups ] ,
54
- )
53
+ const items : PerformerItem [ ] = useMemo ( ( ) => {
54
+ const _selectOperators : CopilotDocV1 . Operator [ ] = operators || [ ]
55
+ if ( ! _selectOperators . length ) return [ ...( groups || [ ] ) , ...OPERATORS ]
56
+ // 已选择的名称做 set
57
+ const _selectedOperatorsNameSet = new Set < string > ( )
58
+ _selectOperators . forEach ( ( v ) => {
59
+ _selectedOperatorsNameSet . add ( v . name )
60
+ } )
61
+ // 已选择的
62
+ const _selectedOperators : OperatorInfo [ ] = [ ]
63
+ // 过滤出未加入干员列表的干员,顺便插入已选择的列表
64
+ const _OPERATORS = OPERATORS . filter ( ( v ) => {
65
+ const has = _selectedOperatorsNameSet . has ( v . name )
66
+ if ( has ) _selectedOperators . push ( v )
67
+ return ! has
68
+ } )
69
+ // 干员组和已选择的放前面
70
+ return [ ...( groups || [ ] ) , ..._selectedOperators , ..._OPERATORS ]
71
+ } , [ groups , operators ] )
55
72
56
73
const fuse = useMemo (
57
74
( ) =>
0 commit comments