Skip to content

Commit

Permalink
NAS-130334 / 24.10 / EE: Snapshots card for TrueCloud Backup task has…
Browse files Browse the repository at this point in the history
… no 'Delete' option (#10418)

* NAS-130334: EE: Snapshots card for TrueCloud Backup task has no Delete option

* NAS-130334: PR Update

* NAS-130334: PR update

* NAS-130334: PR Update
  • Loading branch information
AlexKarpov98 authored Aug 9, 2024
1 parent c03c259 commit 002da50
Show file tree
Hide file tree
Showing 92 changed files with 153 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app/interfaces/api/api-job-directory.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface ApiJobDirectory {
// CloudBackup
'cloud_backup.sync': { params: [id: number, params?: { dry_run: boolean }]; response: void };
'cloud_backup.restore': { params: CloudBackupRestoreParams; response: CloudBackupSnapshot[] };
'cloud_backup.delete_snapshot': { params: [taskId: number, snapshotId: string]; response: void };

// CloudSync
'cloudsync.sync': { params: [id: number, params?: { dry_run: boolean }]; response: number };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class IxCellStateButtonComponent<T> extends ColumnComponent<T> {
if (this.job?.state && !state) {
state = {
state: this.job.state,
error: this.job.error,
} as RowState['state'];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { createComponentFactory, mockProvider } from '@ngneat/spectator/jest';
import { provideMockStore } from '@ngrx/store/testing';
import { of } from 'rxjs';
import { mockAuth } from 'app/core/testing/utils/mock-auth.utils';
import { mockWebSocket, mockCall } from 'app/core/testing/utils/mock-websocket.utils';
import { mockCall, mockWebSocket } from 'app/core/testing/utils/mock-websocket.utils';
import { CloudBackup, CloudBackupSnapshot } from 'app/interfaces/cloud-backup.interface';
import { DialogService } from 'app/modules/dialog/dialog.service';
import { IxSlideInRef } from 'app/modules/forms/ix-forms/components/ix-slide-in/ix-slide-in-ref';
import { IxIconHarness } from 'app/modules/ix-icon/ix-icon.harness';
import { IxTableHarness } from 'app/modules/ix-table/components/ix-table/ix-table.harness';
Expand All @@ -15,6 +16,7 @@ import { CloudBackupRestoreFromSnapshotFormComponent } from 'app/pages/data-prot
import { CloudBackupSnapshotsComponent } from 'app/pages/data-protection/cloud-backup/cloud-backup-details/cloud-backup-snapshots/cloud-backup-snapshots.component';
import { IxSlideInService } from 'app/services/ix-slide-in.service';
import { StorageService } from 'app/services/storage.service';
import { WebSocketService } from 'app/services/ws.service';
import { selectPreferences } from 'app/store/preferences/preferences.selectors';
import { selectGeneralConfig } from 'app/store/system-config/system-config.selectors';

Expand Down Expand Up @@ -50,6 +52,9 @@ describe('CloudBackupSnapshotsComponent', () => {
mockWebSocket([
mockCall('cloud_backup.list_snapshots', cloudBackupSnapshots),
]),
mockProvider(DialogService, {
confirm: jest.fn(() => of(true)),
}),
mockProvider(StorageService),
mockProvider(IxSlideInService, {
open: jest.fn(() => {
Expand Down Expand Up @@ -118,4 +123,11 @@ describe('CloudBackupSnapshotsComponent', () => {
const cells = await table.getCellTexts();
expect(cells).toEqual(expectedRows);
});

it('opens delete dialog when "Delete" button is pressed', async () => {
const deleteButton = await table.getHarnessInCell(IxIconHarness.with({ name: 'delete' }), 1, 2);
await deleteButton.click();

expect(spectator.inject(WebSocketService).job).toHaveBeenCalledWith('cloud_backup.delete_snapshot', [1, 'second']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ import {
} from '@angular/core';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { TranslateService } from '@ngx-translate/core';
import { filter, map } from 'rxjs';
import {
catchError,
EMPTY,
filter, finalize, map, switchMap,
} from 'rxjs';
import { JobState } from 'app/enums/job-state.enum';
import { Role } from 'app/enums/role.enum';
import { tapOnce } from 'app/helpers/operators/tap-once.operator';
import { CloudBackup, CloudBackupSnapshot } from 'app/interfaces/cloud-backup.interface';
import { IxSimpleChanges } from 'app/interfaces/simple-changes.interface';
import { DialogService } from 'app/modules/dialog/dialog.service';
import { EmptyService } from 'app/modules/empty/empty.service';
import { AsyncDataProvider } from 'app/modules/ix-table/classes/async-data-provider/async-data-provider';
import { actionsColumn } from 'app/modules/ix-table/components/ix-table-body/cells/ix-cell-actions/ix-cell-actions.component';
import { relativeDateColumn } from 'app/modules/ix-table/components/ix-table-body/cells/ix-cell-relative-date/ix-cell-relative-date.component';
import { textColumn } from 'app/modules/ix-table/components/ix-table-body/cells/ix-cell-text/ix-cell-text.component';
import { createTable } from 'app/modules/ix-table/utils';
import { AppLoaderService } from 'app/modules/loader/app-loader.service';
import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service';
import { CloudBackupRestoreFromSnapshotFormComponent } from 'app/pages/data-protection/cloud-backup/cloud-backup-details/cloud-backup-restore-form-snapshot-form/cloud-backup-restore-from-snapshot-form.component';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { IxSlideInService } from 'app/services/ix-slide-in.service';
import { WebSocketService } from 'app/services/ws.service';

Expand Down Expand Up @@ -49,6 +59,12 @@ export class CloudBackupSnapshotsComponent implements OnChanges {
onClick: (row) => this.restore(row),
requiredRoles: this.requiredRoles,
},
{
iconName: 'delete',
tooltip: this.translate.instant('Delete'),
requiredRoles: [Role.FullAdmin],
onClick: (row) => this.doDelete(row),
},
],
}),
], {
Expand All @@ -61,6 +77,10 @@ export class CloudBackupSnapshotsComponent implements OnChanges {
private slideIn: IxSlideInService,
private translate: TranslateService,
private ws: WebSocketService,
private dialog: DialogService,
private errorHandler: ErrorHandlerService,
private loader: AppLoaderService,
private snackbar: SnackbarService,
) {}

ngOnChanges(changes: IxSimpleChanges<this>): void {
Expand All @@ -76,7 +96,7 @@ export class CloudBackupSnapshotsComponent implements OnChanges {
this.getCloudBackupSnapshots();
}

getCloudBackupSnapshots(): void {
private getCloudBackupSnapshots(): void {
this.dataProvider.load();
}

Expand All @@ -97,4 +117,32 @@ export class CloudBackupSnapshotsComponent implements OnChanges {
},
});
}

doDelete(row: CloudBackupSnapshot): void {
this.dialog
.confirm({
title: this.translate.instant('Delete Snapshot'),
message: this.translate.instant('Are you sure you want to delete the <b>{name}</b>?', {
name: row.hostname,
}),
buttonText: this.translate.instant('Delete'),
})
.pipe(
filter(Boolean),
switchMap(() => this.ws.job('cloud_backup.delete_snapshot', [this.backup.id, row.id])),
tapOnce(() => this.loader.open()),
catchError((error) => {
this.dialog.error(this.errorHandler.parseError(error));
return EMPTY;
}),
finalize(() => this.loader.close()),
untilDestroyed(this),
)
.subscribe((job) => {
if (job.state === JobState.Success) {
this.snackbar.success(this.translate.instant('Snapshot deleted.'));
this.getCloudBackupSnapshots();
}
});
}
}
1 change: 1 addition & 0 deletions src/assets/i18n/af.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/az.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/br.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@
"Delete Rsync Task <b>\"{name}\"</b>?": "",
"Delete S.M.A.R.T. Test <b>\"{name}\"</b>?": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/dsb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en-au.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en-gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/eo.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es-ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es-co.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es-mx.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es-ni.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es-ve.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/et.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@
"Delete SSH Keypair": "",
"Delete Script": "",
"Delete Scrub Task <b>\"{name}\"</b>?": "",
"Delete Snapshot": "",
"Delete Static Route": "",
"Delete Sysctl": "",
"Delete Sysctl Variable {variable}?": "",
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"Default – follow upstream / TrueNAS default": "",
"Defect": "",
"Delete All Selected": "",
"Delete Snapshot": "",
"Delete all TrueNAS configurations that depend on the exported pool. Impacted configurations may include services (listed above if applicable), applications, shares, and scheduled data protection tasks.": "",
"Delete dataset {name}": "",
"Delete raw file": "",
Expand Down
Loading

0 comments on commit 002da50

Please sign in to comment.