Skip to content

Commit 94792d4

Browse files
committed
feat: hint for additional operators in actions
1 parent 6ab07e5 commit 94792d4

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

src/components/editor/operator/EditorPerformer.tsx

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NonIdealState } from '@blueprintjs/core'
1+
import { Callout, Icon, NonIdealState } from '@blueprintjs/core'
22
import {
33
Active,
44
DndContext,
@@ -17,9 +17,14 @@ import {
1717
verticalListSortingStrategy,
1818
} from '@dnd-kit/sortable'
1919

20-
import { uniqueId } from 'lodash-es'
21-
import { FC, useEffect, useState } from 'react'
22-
import { Control, UseFieldArrayMove, useFieldArray } from 'react-hook-form'
20+
import { compact, uniq, uniqueId } from 'lodash-es'
21+
import { FC, useEffect, useMemo, useState } from 'react'
22+
import {
23+
Control,
24+
UseFieldArrayMove,
25+
useFieldArray,
26+
useWatch,
27+
} from 'react-hook-form'
2328
import { SetRequired } from 'type-fest'
2429

2530
import { CopilotDocV1 } from 'models/copilot.schema'
@@ -52,6 +57,7 @@ const getId = (performer: Operator | Group) => {
5257
export const EditorPerformer: FC<EditorPerformerProps> = ({ control }) => {
5358
const [editMode, setEditMode] = useState<PerformerType>('operator')
5459
const sensors = useSensors(useSensor(PointerSensor))
60+
const actions = useWatch({ control, name: 'actions' })
5561

5662
const {
5763
fields: _operators,
@@ -79,6 +85,25 @@ export const EditorPerformer: FC<EditorPerformerProps> = ({ control }) => {
7985
const operators: Operator[] = _operators
8086
const groups: Group[] = _groups
8187

88+
const additionalOperatorsFromActions = useMemo(() => {
89+
if (!actions) return []
90+
91+
const additionalOperators = actions.map((action) => {
92+
if (
93+
'name' in action &&
94+
!operators.some(({ name }) => name === action.name) &&
95+
!groups.some(({ opers }) =>
96+
opers?.some(({ name }) => name === action.name),
97+
)
98+
) {
99+
return action.name
100+
}
101+
return undefined
102+
})
103+
104+
return uniq(compact(additionalOperators))
105+
}, [actions, operators, groups])
106+
82107
const [draggingOperator, setDraggingOperator] = useState<Operator>()
83108
const [draggingGroup, setDraggingGroup] = useState<Group>()
84109
const [editingOperator, setEditingOperator] = useState<Operator>()
@@ -354,14 +379,16 @@ export const EditorPerformer: FC<EditorPerformerProps> = ({ control }) => {
354379
<>
355380
<div className="flex flex-wrap md:flex-nowrap">
356381
<div className="w-full md:w-1/3 md:mr-8 flex flex-col pb-8">
357-
<EditorSheetTrigger
358-
submitOperator={submitOperator}
359-
submitGroup={submitGroup}
360-
existedOperators={operators}
361-
existedGroups={groups}
362-
removeOperator={removeOperator}
363-
removeGroup={removeGroup}
364-
/>
382+
<div className="mb-2">
383+
<EditorSheetTrigger
384+
submitOperator={submitOperator}
385+
submitGroup={submitGroup}
386+
existedOperators={operators}
387+
existedGroups={groups}
388+
removeOperator={removeOperator}
389+
removeGroup={removeGroup}
390+
/>
391+
</div>
365392
<EditorPerformerAdd
366393
mode={editMode}
367394
operator={editingOperator}
@@ -377,7 +404,17 @@ export const EditorPerformer: FC<EditorPerformerProps> = ({ control }) => {
377404
/>
378405
</div>
379406
<div className="w-full md:w-2/3 pb-8">
380-
<div className="p-2 -mx-2 relative">
407+
{additionalOperatorsFromActions.length > 0 && (
408+
<Callout
409+
className="flex items-center py-2 mb-2"
410+
icon={null}
411+
intent="primary"
412+
>
413+
<Icon icon="info-sign" className="mr-1" />
414+
未加入干员:{additionalOperatorsFromActions.join(', ')}
415+
</Callout>
416+
)}
417+
<div className="mt-2 relative">
381418
<DndContext
382419
sensors={sensors}
383420
onDragStart={handleDragStart}

0 commit comments

Comments
 (0)