Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ export class ContentManagementService {
);
}

deleteNodes(items: NodeEntry[]): void {
deleteNodes(items: NodeEntry[], allowUndo = true): void {
const batch: Observable<DeletedNodeInfo>[] = [];

items.forEach((node) => {
Expand All @@ -671,7 +671,7 @@ export class ContentManagementService {
const status = this.processStatus(data);
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]));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ describe('NodeEffects', () => {
const node: any = {};
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(contentService.deleteNodes).toHaveBeenCalledWith([node]);
expect(contentService.deleteNodes).toHaveBeenCalledWith([node], true);
});

it('should delete nodes from the active selection', fakeAsync(() => {
Expand All @@ -233,9 +233,9 @@ describe('NodeEffects', () => {

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(contentService.deleteNodes).toHaveBeenCalledWith([node]);
expect(contentService.deleteNodes).toHaveBeenCalledWith([node], true);
}));

it('should do nothing if invoking delete with no data', () => {
Expand Down
4 changes: 2 additions & 2 deletions projects/aca-content/src/lib/store/effects/node.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ export class NodeEffects {
map((action) => {
this.store.dispatch(new ShowLoaderAction(true));
if (action?.payload?.length > 0) {
this.contentService.deleteNodes(action.payload);
this.contentService.deleteNodes(action.payload, action.allowUndo);
} else {
this.store
.select(getAppSelection)
.pipe(take(1))
.subscribe((selection) => {
if (selection && selection.count > 0) {
this.contentService.deleteNodes(selection.nodes);
this.contentService.deleteNodes(selection.nodes, action.allowUndo);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion projects/aca-shared/store/src/actions/node.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class SetSelectedNodesAction implements Action {
export class DeleteNodesAction implements Action {
readonly type = NodeActionTypes.Delete;

constructor(public payload: NodeEntry[] = []) {}
constructor(public payload: NodeEntry[] = [], public allowUndo = true) {}
}

export class UndoDeleteNodesAction implements Action {
Expand Down
Loading