[ACS-8604] Add new param to control undo for deleting nodes (#4308)

* [ACS-8604] Add new param to control undo for deleting nodes

* [ACS-8604] Unit test fixes
This commit is contained in:
MichalKinas 2024-12-19 10:18:56 +01:00 committed by GitHub
parent 53a1b2c5cb
commit 65763df7ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 9 deletions

View File

@ -660,7 +660,7 @@ export class ContentManagementService {
); );
} }
deleteNodes(items: NodeEntry[]): void { deleteNodes(items: NodeEntry[], allowUndo = true): void {
const batch: Observable<DeletedNodeInfo>[] = []; const batch: Observable<DeletedNodeInfo>[] = [];
items.forEach((node) => { items.forEach((node) => {
@ -671,7 +671,7 @@ export class ContentManagementService {
const status = this.processStatus(data); const status = this.processStatus(data);
const message = this.getDeleteMessage(status); const message = this.getDeleteMessage(status);
if (message && status.someSucceeded) { if (message && status.someSucceeded && allowUndo) {
message.userAction = new SnackbarUserAction('APP.ACTIONS.UNDO', new UndoDeleteNodesAction([...status.success])); message.userAction = new SnackbarUserAction('APP.ACTIONS.UNDO', new UndoDeleteNodesAction([...status.success]));
} }

View File

@ -218,9 +218,9 @@ describe('NodeEffects', () => {
const node: any = {}; const node: any = {};
store.dispatch(new DeleteNodesAction([node])); store.dispatch(new DeleteNodesAction([node]));
expect(store.dispatch).toHaveBeenCalledWith(new DeleteNodesAction([node])); expect(store.dispatch).toHaveBeenCalledWith(new DeleteNodesAction([node], true));
expect(store.dispatch).toHaveBeenCalledWith(new ShowLoaderAction(true)); expect(store.dispatch).toHaveBeenCalledWith(new ShowLoaderAction(true));
expect(contentService.deleteNodes).toHaveBeenCalledWith([node]); expect(contentService.deleteNodes).toHaveBeenCalledWith([node], true);
}); });
it('should delete nodes from the active selection', fakeAsync(() => { it('should delete nodes from the active selection', fakeAsync(() => {
@ -233,9 +233,9 @@ describe('NodeEffects', () => {
store.dispatch(new DeleteNodesAction(null)); store.dispatch(new DeleteNodesAction(null));
expect(store.dispatch).toHaveBeenCalledWith(new DeleteNodesAction(null)); expect(store.dispatch).toHaveBeenCalledWith(new DeleteNodesAction(null, true));
expect(store.dispatch).toHaveBeenCalledWith(new ShowLoaderAction(true)); expect(store.dispatch).toHaveBeenCalledWith(new ShowLoaderAction(true));
expect(contentService.deleteNodes).toHaveBeenCalledWith([node]); expect(contentService.deleteNodes).toHaveBeenCalledWith([node], true);
})); }));
it('should do nothing if invoking delete with no data', () => { it('should do nothing if invoking delete with no data', () => {

View File

@ -163,14 +163,14 @@ export class NodeEffects {
map((action) => { map((action) => {
this.store.dispatch(new ShowLoaderAction(true)); this.store.dispatch(new ShowLoaderAction(true));
if (action?.payload?.length > 0) { if (action?.payload?.length > 0) {
this.contentService.deleteNodes(action.payload); this.contentService.deleteNodes(action.payload, action.allowUndo);
} else { } else {
this.store this.store
.select(getAppSelection) .select(getAppSelection)
.pipe(take(1)) .pipe(take(1))
.subscribe((selection) => { .subscribe((selection) => {
if (selection && selection.count > 0) { if (selection && selection.count > 0) {
this.contentService.deleteNodes(selection.nodes); this.contentService.deleteNodes(selection.nodes, action.allowUndo);
} }
}); });
} }

View File

@ -60,7 +60,7 @@ export class SetSelectedNodesAction implements Action {
export class DeleteNodesAction implements Action { export class DeleteNodesAction implements Action {
readonly type = NodeActionTypes.Delete; readonly type = NodeActionTypes.Delete;
constructor(public payload: NodeEntry[] = []) {} constructor(public payload: NodeEntry[] = [], public allowUndo = true) {}
} }
export class UndoDeleteNodesAction implements Action { export class UndoDeleteNodesAction implements Action {