>
</cd-table-actions>
</div>
- >
<cd-smb-cluster-tabs
*cdTableDetail
[selection]="expandedRow">
selectionType="single"
[hasDetails]="false"
(fetchData)="loadSMBShares()"
+ (updateSelection)="updateSelection($event)"
>
<div class="table-actions">
<cd-table-actions
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SmbShareListComponent } from './smb-share-list.component';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
+import { provideHttpClientTesting } from '@angular/common/http/testing';
+import { provideHttpClient } from '@angular/common/http';
+import { ToastrModule } from 'ngx-toastr';
+import { SharedModule } from '~/app/shared/shared.module';
describe('SmbShareListComponent', () => {
let component: SmbShareListComponent;
beforeEach(async () => {
await TestBed.configureTestingModule({
- imports: [HttpClientTestingModule],
- declarations: [SmbShareListComponent]
+ imports: [ToastrModule.forRoot(), SharedModule],
+ declarations: [SmbShareListComponent],
+ providers: [provideHttpClient(), provideHttpClientTesting()]
}).compileComponents();
fixture = TestBed.createComponent(SmbShareListComponent);
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
import { Icons } from '~/app/shared/enum/icons.enum';
+import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component';
+import { FinishedTask } from '~/app/shared/models/finished-task';
+import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
+import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
+import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
@Component({
selector: 'cd-smb-share-list',
smbShares$: Observable<SMBShare[]>;
subject$ = new BehaviorSubject<SMBShare[]>([]);
+ modalRef: NgbModalRef;
constructor(
private authStorageService: AuthStorageService,
public actionLabels: ActionLabelsI18n,
- private smbService: SmbService
+ private smbService: SmbService,
+ private taskWrapper: TaskWrapperService,
+ private modalService: ModalCdsService
) {
this.permission = this.authStorageService.getPermissions().smb;
}
icon: Icons.add,
routerLink: () => ['/cephfs/smb/share/create', this.clusterId],
canBePrimary: (selection: CdTableSelection) => !selection.hasSingleSelection
+ },
+ {
+ permission: 'delete',
+ icon: Icons.destroy,
+ click: () => this.deleteShareModal(),
+ name: this.actionLabels.DELETE
}
];
loadSMBShares() {
this.subject$.next([]);
}
+
+ updateSelection(selection: CdTableSelection) {
+ this.selection = selection;
+ }
+
+ deleteShareModal() {
+ const cluster_id = this.selection.first().cluster_id;
+ const share_id = this.selection.first().share_id;
+ const name = this.selection.first().name;
+
+ this.modalRef = this.modalService.show(DeleteConfirmationModalComponent, {
+ itemDescription: $localize`SMB Share`,
+ itemNames: [`Share: ${share_id} (${name}) from cluster: ${cluster_id}`],
+ submitActionObservable: () =>
+ this.taskWrapper.wrapTaskAroundCall({
+ task: new FinishedTask('smb/share/delete', {
+ share_id: share_id
+ }),
+ call: this.smbService.deleteShare(cluster_id, share_id)
+ })
+ });
+ }
}
const req = httpTesting.expectOne('api/smb/share');
expect(req.request.method).toBe('POST');
});
+
+ it('should call delete for given share of a cluster', () => {
+ const cluster_id = 'foo';
+ const share_id = 'bar';
+ service.deleteShare(cluster_id, share_id).subscribe((response: null) => {
+ expect(response).toBeUndefined();
+ });
+ const req = httpTesting.expectOne(`api/smb/share/${cluster_id}/${share_id}`);
+ expect(req.request.method).toBe('DELETE');
+ });
});
-import { HttpClient } from '@angular/common/http';
+import { HttpClient, HttpResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
createShare(requestModel: ShareRequestModel) {
return this.http.post(`${this.baseURL}/share`, requestModel);
}
+
+ deleteShare(clusterId: string, shareId: string): Observable<HttpResponse<null>> {
+ return this.http.delete<null>(`${this.baseURL}/share/${clusterId}/${shareId}`, {
+ observe: 'response'
+ });
+ }
}
),
'smb/share/create': this.newTaskMessage(this.commonOperations.create, (metadata) =>
this.smbShare(metadata)
+ ),
+ 'smb/share/delete': this.newTaskMessage(this.commonOperations.delete, (metadata) =>
+ this.smbShare(metadata)
)
};
return $localize`SMB Cluster '${metadata.cluster_id}'`;
}
- smbShare(metadata: { share_id: string }) {
- return $localize`SMB Share '${metadata.share_id}'`;
- }
-
service(metadata: any) {
return $localize`service '${metadata.service_name}'`;
}
snapshotSchedule(metadata: any) {
return $localize`snapshot schedule for path '${metadata?.path}'`;
}
+
+ smbShare(metadata: Record<'share_id', string>) {
+ return $localize`SMB share '${metadata?.share_id}'`;
+ }
+
crudMessageId(id: string) {
return $localize`${id}`;
}