diff --git a/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.html b/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.html
index be94218f4a..0941a20d00 100644
--- a/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.html
+++ b/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.html
@@ -88,7 +88,7 @@
- {{ 'widget-config.action-name' | translate }}
+ {{ 'widget-config.action-name' | translate }}
{{ action.name }}
@@ -100,7 +100,7 @@
- {{ 'widget-config.action-type' | translate }}
+ {{ 'widget-config.action-type' | translate }}
{{ action.typeName }}
diff --git a/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts b/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts
index 8c329df938..5b746e95bc 100644
--- a/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts
+++ b/ui-ngx/src/app/modules/home/components/widget/action/manage-widget-actions.component.ts
@@ -37,7 +37,7 @@ import { Direction, SortOrder } from '@shared/models/page/sort-order';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { fromEvent, merge } from 'rxjs';
-import { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators';
+import { debounceTime, distinctUntilChanged, first, tap } from 'rxjs/operators';
import {
toWidgetActionDescriptor,
WidgetActionCallbacks,
@@ -167,43 +167,16 @@ export class ManageWidgetActionsComponent extends PageComponent implements OnIni
dropAction(event: CdkDragDrop) {
this.dragDisabled = true;
- const droppedAction = event.item.data;
- this.dataSource.getAllActions().subscribe(
- (actions) => {
- moveItemInArray(actions, event.previousIndex, event.currentIndex);
-
- const isBackward = event.currentIndex > event.previousIndex;
- let nearestNeighbourAction: WidgetActionDescriptorInfo = null;
- for (let i: number = isBackward ? actions.length - 1 : 0;
- isBackward ? i >= 0 : i < actions.length; isBackward ? --i : ++i) {
- if (actions[i].id === droppedAction.id) {
- break;
- }
- if (actions[i].actionSourceId === droppedAction.actionSourceId) {
- nearestNeighbourAction = actions[i];
- }
- }
-
- const targetActions = this.getOrCreateTargetActions(droppedAction.actionSourceId);
- let oldIndex = -1;
- let newIndex: number = nearestNeighbourAction ? -1 : (isBackward ? targetActions.length - 1 : 0);
-
- for (let i: number = isBackward ? targetActions.length - 1 : 0;
- isBackward ? i >= 0 : i < targetActions.length; isBackward ? --i : ++i) {
- if (targetActions[i].id === droppedAction.id) {
- oldIndex = i;
- }
- if (nearestNeighbourAction && targetActions[i].id === nearestNeighbourAction.id) {
- newIndex = isBackward ? i - 1 : i + 1;
- }
- if (oldIndex !== -1 && newIndex !== -1) {
- moveItemInArray(targetActions, oldIndex, newIndex);
- this.onActionsUpdated();
- return;
- }
- }
- }
- );
+ const droppedAction: WidgetActionDescriptorInfo = event.item.data;
+ this.dataSource.pageData$.pipe(
+ first()
+ ).subscribe((actions) => {
+ const action = actions.data;
+ const startActionSourceIndex = action.findIndex(element => element.actionSourceId === droppedAction.actionSourceId);
+ const targetActions = this.getOrCreateTargetActions(droppedAction.actionSourceId);
+ moveItemInArray(targetActions, event.previousIndex - startActionSourceIndex, event.currentIndex - startActionSourceIndex);
+ this.onActionsUpdated();
+ });
}
addAction($event: Event) {