@@ -187,7 +187,7 @@ func (i *ComponentStageForm) RenderGroupMoveStagesForm() (err error) {
187
187
if len (stepDragGroup ) <= 0 {
188
188
return errors .New ("the dragGroupKey is not exists" )
189
189
}
190
- firstStepDrag , lastStepDrag := findFirstLastStepIDInGroup (stepDragGroup )
190
+ firstStepDrag , lastStepDrag := findFirstLastStepInGroup (stepDragGroup )
191
191
req .StepID = firstStepDrag .ID
192
192
req .LastStepID = lastStepDrag .ID
193
193
@@ -202,9 +202,10 @@ func (i *ComponentStageForm) RenderGroupMoveStagesForm() (err error) {
202
202
if len (stepDropGroup ) <= 0 {
203
203
return errors .New ("the dropGroupKey is not exists" )
204
204
}
205
- firstStepDrop , _ := findFirstLastStepIDInGroup (stepDropGroup )
205
+ firstStepDrop , _ := findFirstLastStepInGroup (stepDropGroup )
206
206
req .PreID = firstStepDrop .PreID
207
207
req .TargetStepID = firstStepDrop .ID
208
+ // the order of the linked list has not changed
208
209
if req .PreID == req .LastStepID {
209
210
return nil
210
211
}
@@ -216,10 +217,11 @@ func (i *ComponentStageForm) RenderGroupMoveStagesForm() (err error) {
216
217
if len (stepDropGroup ) <= 0 {
217
218
return errors .New ("the dropGroupKey is not exists" )
218
219
}
219
- _ , lastStepDrop := findFirstLastStepIDInGroup (stepDropGroup )
220
+ _ , lastStepDrop := findFirstLastStepInGroup (stepDropGroup )
220
221
req .PreID = lastStepDrop .ID
221
222
req .TargetStepID = lastStepDrop .ID
222
- if req .PreID == req .StepID {
223
+ // the order of the linked list has not changed
224
+ if req .PreID == firstStepDrag .PreID {
223
225
return nil
224
226
}
225
227
default :
@@ -228,7 +230,7 @@ func (i *ComponentStageForm) RenderGroupMoveStagesForm() (err error) {
228
230
return i .ctxBdl .Bdl .MoveTestPlansV2Step (req )
229
231
}
230
232
231
- func findFirstLastStepIDInGroup (steps []* apistructs.TestPlanV2Step ) (firstStep , lastStep * apistructs.TestPlanV2Step ) {
233
+ func findFirstLastStepInGroup (steps []* apistructs.TestPlanV2Step ) (firstStep , lastStep * apistructs.TestPlanV2Step ) {
232
234
stepIDMap := make (map [uint64 ]* apistructs.TestPlanV2Step , len (steps ))
233
235
preIDMap := make (map [uint64 ]* apistructs.TestPlanV2Step , len (steps ))
234
236
for _ , v := range steps {
@@ -256,12 +258,15 @@ func (i *ComponentStageForm) RenderItemMoveStagesForm() (err error) {
256
258
req apistructs.TestPlanV2StepMoveRequest
257
259
testPlan * apistructs.TestPlanV2GetResponse
258
260
)
261
+ dragGroupKey := uint64 (i .State .DragParams .DragGroupKey )
262
+ dropGroupKey := uint64 (i .State .DragParams .DropGroupKey )
263
+
259
264
req .UserID = i .ctxBdl .Identity .UserID
260
265
req .TestPlanID = i .State .TestPlanId
261
266
req .StepID = uint64 (i .State .DragParams .DragKey )
262
267
req .LastStepID = uint64 (i .State .DragParams .DragKey )
263
268
req .IsGroup = false
264
- if i .State .DragParams .DropKey == - 1 {
269
+ if i .State .DragParams .DropKey == - 1 { // move to the end and be independent group
265
270
req .TargetStepID = 0
266
271
} else {
267
272
req .TargetStepID = uint64 (i .State .DragParams .DropKey )
@@ -284,12 +289,21 @@ func (i *ComponentStageForm) RenderItemMoveStagesForm() (err error) {
284
289
return
285
290
}
286
291
req .PreID = uint64 (i .State .DragParams .DropKey )
292
+ // the order of the linked list has not changed in the same group
293
+ if req .PreID == step .PreID && dragGroupKey == dropGroupKey {
294
+ return nil
295
+ }
296
+
287
297
case - 1 : // in front of the target
288
298
step , err = i .ctxBdl .Bdl .GetTestPlanV2Step (uint64 (i .State .DragParams .DropKey ))
289
299
if err != nil {
290
300
return
291
301
}
292
302
req .PreID = step .PreID
303
+ // the order of the linked list has not changed in the same group
304
+ if req .PreID == req .LastStepID && dragGroupKey == dropGroupKey {
305
+ return nil
306
+ }
293
307
default :
294
308
return errors .New ("unknown position" )
295
309
}
@@ -319,7 +333,10 @@ func (i *ComponentStageForm) RenderSplitStagesForm(opsData interface{}) (err err
319
333
if len (stepGroup ) <= 0 {
320
334
return errors .New ("the groupID is not exists" )
321
335
}
322
- _ , lastStep := findFirstLastStepIDInGroup (stepGroup )
336
+ if len (stepGroup ) == 1 {
337
+ return nil
338
+ }
339
+ _ , lastStep := findFirstLastStepInGroup (stepGroup )
323
340
req .PreID = lastStep .ID
324
341
return i .ctxBdl .Bdl .MoveTestPlansV2Step (req )
325
342
}
0 commit comments