]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: show full subvol path snap schedule 56419/head
authorIvo Almeida <ialmeida@redhat.com>
Wed, 20 Mar 2024 10:35:52 +0000 (10:35 +0000)
committerIvo Almeida <ialmeida@redhat.com>
Fri, 22 Mar 2024 19:44:23 +0000 (19:44 +0000)
Show full subvolume path when adding snap schedule

Fixes: https://tracker.ceph.com/issues/65000
Signed-off-by: Ivo Almeida <ialmeida@redhat.com>
(cherry picked from commit b6dbf0f24d189d5b75148f07f1dc7f332d23b64a)

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-snapshotschedule-form/cephfs-snapshotschedule-form.component.ts

index 22fa33f0fe1cbbdc87a5db31d72ed3153a731e91..a34226c563ba35b799bcfee3135868c4f912695c 100644 (file)
@@ -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() {