@@ -45,7 +45,7 @@ export interface EditorActionAddProps {
45
45
setError : UseFormSetError < CopilotDocV1 . Action > ,
46
46
) => boolean
47
47
onCancel : ( ) => void
48
- action ?: CopilotDocV1 . Action
48
+ editingAction ?: CopilotDocV1 . Action
49
49
}
50
50
51
51
const defaultAction : DeepPartial < CopilotDocV1 . Action > = {
@@ -59,11 +59,11 @@ const defaultMoveCameraAction: DeepPartial<CopilotDocV1.ActionMoveCamera> = {
59
59
60
60
export const EditorActionAdd = ( {
61
61
control : operationControl ,
62
- action ,
62
+ editingAction ,
63
63
onSubmit : _onSubmit ,
64
64
onCancel,
65
65
} : EditorActionAddProps ) => {
66
- const isNew = ! action
66
+ const isNew = ! editingAction
67
67
const operatorGroups = useWatch ( { control : operationControl , name : 'groups' } )
68
68
69
69
const {
@@ -91,21 +91,73 @@ export const EditorActionAdd = ({
91
91
...defaultAction ,
92
92
// to prevent layout jumping, we persist the action type on reset
93
93
type,
94
-
95
94
...( type === 'MoveCamera' ? defaultMoveCameraAction : null ) ,
96
95
}
97
96
98
97
useEffect ( ( ) => {
99
- reset ( action || resettingValues )
100
- } , [ reset , action ] )
98
+ if ( editingAction ) {
99
+ if ( 'type' in editingAction ) {
100
+ setValue ( 'type' , editingAction . type )
101
+ }
102
+ // 修复切换type的时候,数据丢失的问题
103
+ // 原因:因为切换type的时候会触发页面绘制,导致form和对应的item组件丢失绑定,
104
+ // 当重置时没办法正常清空item组件内部的值。
105
+ // 放入setTimeout中,延迟赋值,就可以避免丢失绑定的问题
106
+ setTimeout ( ( ) => {
107
+ // 修复先点击“部署”动作的编辑按钮,再连续点击“二倍速”动作的编辑按钮,“部署”的数据丢失
108
+ // 原因:通过reset方式赋值给form,相当于将action变量跟form绑定,
109
+ // 当再通过reset(undefined)后,会将action的值置为null,
110
+ // 通过setValue的方式,不会将action和form绑定
111
+ if ( 'doc' in editingAction ) {
112
+ setValue ( 'doc' , editingAction . doc )
113
+ }
114
+ if ( 'docColor' in editingAction ) {
115
+ setValue ( 'docColor' , editingAction . docColor )
116
+ }
117
+ if ( 'costs' in editingAction ) {
118
+ setValue ( 'costs' , editingAction . costs )
119
+ }
120
+ if ( 'costChanges' in editingAction ) {
121
+ setValue ( 'costChanges' , editingAction . costChanges )
122
+ }
123
+ if ( 'kills' in editingAction ) {
124
+ setValue ( 'kills' , editingAction . kills )
125
+ }
126
+ if ( 'cooling' in editingAction ) {
127
+ setValue ( 'cooling' , editingAction . cooling )
128
+ }
129
+ if ( 'preDelay' in editingAction ) {
130
+ setValue ( 'preDelay' , editingAction . preDelay )
131
+ }
132
+ if ( 'rearDelay' in editingAction ) {
133
+ setValue ( 'rearDelay' , editingAction . rearDelay )
134
+ }
135
+ if ( 'name' in editingAction ) {
136
+ setValue ( 'name' , editingAction . name )
137
+ }
138
+ if ( 'direction' in editingAction ) {
139
+ setValue ( 'direction' , editingAction . direction )
140
+ }
141
+ if ( 'location' in editingAction ) {
142
+ setValue ( 'location' , editingAction . location )
143
+ }
144
+ if ( 'skillUsage' in editingAction ) {
145
+ setValue ( 'skillUsage' , editingAction . skillUsage )
146
+ }
147
+ if ( 'distance' in editingAction ) {
148
+ setValue ( 'distance' , editingAction . distance )
149
+ }
150
+ } , 0 )
151
+ } else {
152
+ reset ( resettingValues )
153
+ }
154
+ } , [ editingAction ] )
101
155
102
156
useEffect ( ( ) => {
103
- // fill in default values for MoveCamera
104
- if ( type === 'MoveCamera' && ! action ) {
105
- // looks like the passed object will be mutated somehow
106
- reset ( { ...defaultMoveCameraAction } )
157
+ if ( type === 'MoveCamera' ) {
158
+ reset ( resettingValues )
107
159
}
108
- } , [ reset , action , type ] )
160
+ } , [ type ] )
109
161
110
162
useEffect ( ( ) => {
111
163
setValue (
0 commit comments