Skip to content

Commit 9a35dd3

Browse files
authored
Merge pull request #246 from hmydgz/dev
✨ feat(EditorOperatorName): 调整动作序列中的干员选择列表排序,已选择的排在前面
2 parents cae030b + e43b710 commit 9a35dd3

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/components/editor/action/EditorActionAdd.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const EditorActionAdd = ({
6565
}: EditorActionAddProps) => {
6666
const isNew = !editingAction
6767
const operatorGroups = useWatch({ control: operationControl, name: 'groups' })
68+
const operators = useWatch({ control: operationControl, name: 'opers' })
6869

6970
const {
7071
control,
@@ -163,7 +164,7 @@ export const EditorActionAdd = ({
163164
setValue(
164165
'skillTimes',
165166
skillUsage === CopilotDocV1.SkillUsageType.ReadyToUseTimes
166-
? (action as CopilotDocV1.ActionSkillUsage)?.skillTimes ?? 1
167+
? (editingAction as CopilotDocV1.ActionSkillUsage)?.skillTimes ?? 1
167168
: undefined,
168169
)
169170
}, [skillUsage])
@@ -248,6 +249,7 @@ export const EditorActionAdd = ({
248249
<EditorOperatorName
249250
shouldUnregister
250251
groups={operatorGroups}
252+
operators={operators}
251253
control={control}
252254
name="name"
253255
rules={{

src/components/editor/operator/EditorOperator.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ export const EditorOperatorName = <T extends FieldValues>({
3232
name,
3333
control,
3434
rules,
35+
operators,
3536
...controllerProps
3637
}: EditorFieldProps<T, string> & {
3738
groups?: CopilotDocV1.Group[]
39+
operators?: CopilotDocV1.Operator[]
3840
}) => {
3941
const entityName = useMemo(() => (groups ? '干员或干员组' : '干员'), [groups])
4042

@@ -48,10 +50,25 @@ export const EditorOperatorName = <T extends FieldValues>({
4850
...controllerProps,
4951
})
5052

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])
5572

5673
const fuse = useMemo(
5774
() =>

src/styles/blueprint.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ body {
237237

238238
.bp4-dark {
239239
.docs-content-wrapper {
240+
@apply min-h-screen;
240241
background-color: #2f343c;
241242
}
242243
.bp4-tag{

0 commit comments

Comments
 (0)