From 2a47bf4f4bc5d1d49de1d84249483ae5280e7c42 Mon Sep 17 00:00:00 2001 From: Ivo Almeida Date: Wed, 20 Mar 2024 10:35:52 +0000 Subject: [PATCH] mgr/dashboard: show full subvol path snap schedule Show full subvolume path when adding snap schedule Fixes: https://tracker.ceph.com/issues/65000 Signed-off-by: Ivo Almeida (cherry picked from commit b6dbf0f24d189d5b75148f07f1dc7f332d23b64a) --- .../cephfs-snapshotschedule-form.component.ts | 76 ++++++++++++++----- 1 file changed, 56 insertions(+), 20 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-snapshotschedule-form/cephfs-snapshotschedule-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-snapshotschedule-form/cephfs-snapshotschedule-form.component.ts index 22fa33f0fe1cb..a34226c563ba3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-snapshotschedule-form/cephfs-snapshotschedule-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-snapshotschedule-form/cephfs-snapshotschedule-form.component.ts @@ -3,7 +3,17 @@ import { AbstractControl, FormArray, FormControl, FormGroup, Validators } from ' import { NgbActiveModal, NgbDateStruct, NgbTimeStruct } from '@ng-bootstrap/ng-bootstrap'; import { padStart, uniq } from 'lodash'; import { Observable, OperatorFunction, of, timer } from 'rxjs'; -import { catchError, debounceTime, distinctUntilChanged, map, switchMap } from 'rxjs/operators'; +import { + catchError, + debounceTime, + distinctUntilChanged, + filter, + map, + mergeMap, + pluck, + switchMap, + tap +} from 'rxjs/operators'; import { CephfsSnapshotScheduleService } from '~/app/shared/api/cephfs-snapshot-schedule.service'; import { CephfsSubvolumeService } from '~/app/shared/api/cephfs-subvolume.service'; import { DirectoryStoreService } from '~/app/shared/api/directory-store.service'; @@ -91,25 +101,51 @@ export class CephfsSnapshotscheduleFormComponent extends CdForm implements OnIni this.directoryStore.loadDirectories(this.id, '/', 3); this.createForm(); this.isEdit ? this.populateForm() : this.loadingReady(); - this.snapScheduleForm.get('directory').valueChanges.subscribe({ - next: (value: string) => { - this.subvolumeGroup = value?.split?.('/')?.[2]; - this.subvolume = value?.split?.('/')?.[3]; - this.subvolumeService - .exists( - this.subvolume, - this.fsName, - this.subvolumeGroup === DEFAULT_SUBVOLUME_GROUP ? '' : this.subvolumeGroup - ) - .subscribe({ - next: (exists: boolean) => { - this.isSubvolume = exists; - this.isDefaultSubvolumeGroup = - exists && this.subvolumeGroup === DEFAULT_SUBVOLUME_GROUP; - } - }); - } - }); + + this.snapScheduleForm + .get('directory') + .valueChanges.pipe( + filter(() => !this.isEdit), + debounceTime(DEBOUNCE_TIMER), + tap(() => { + this.isSubvolume = false; + }), + tap((value: string) => { + this.subvolumeGroup = value?.split?.('/')?.[2]; + this.subvolume = value?.split?.('/')?.[3]; + }), + filter(() => !!this.subvolume && !!this.subvolumeGroup), + mergeMap(() => + this.subvolumeService + .exists( + this.subvolume, + this.fsName, + this.subvolumeGroup === DEFAULT_SUBVOLUME_GROUP ? '' : this.subvolumeGroup + ) + .pipe( + tap((exists: boolean) => (this.isSubvolume = exists)), + tap( + (exists: boolean) => + (this.isDefaultSubvolumeGroup = + exists && this.subvolumeGroup === DEFAULT_SUBVOLUME_GROUP) + ) + ) + ), + filter((exists: boolean) => exists), + mergeMap(() => + this.subvolumeService + .info( + this.fsName, + this.subvolume, + this.subvolumeGroup === DEFAULT_SUBVOLUME_GROUP ? '' : this.subvolumeGroup + ) + .pipe(pluck('path')) + ), + filter((path: string) => path !== this.snapScheduleForm.get('directory').value) + ) + .subscribe({ + next: (path: string) => this.snapScheduleForm.get('directory').setValue(path) + }); } get retentionPolicies() { -- 2.39.5