Merge pull request #34442 from tspmelo/wip-fix-rgw-bucket-checkbox

Reviewed-by: Stephan Müller <smueller@suse.com>
Reviewed-by: Volker Theile <vtheile@suse.com>
This commit is contained in:
Lenz Grimmer 2020-04-22 13:31:49 +02:00 committed by GitHub
commit 65239481f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 28 deletions

View File

@ -131,8 +131,7 @@
id="versioning"
name="versioning"
formControlName="versioning"
[checked]="isVersioningEnabled"
(change)="updateVersioning()">
(change)="setMfaDeleteValidators()">
<label class="custom-control-label"
for="versioning"
i18n>Enabled</label>
@ -158,8 +157,7 @@
id="mfa-delete"
name="mfa-delete"
formControlName="mfa-delete"
[checked]="isMfaDeleteEnabled"
(change)="updateMfaDelete()">
(change)="setMfaDeleteValidators()">
<label class="custom-control-label"
for="mfa-delete"
i18n>Delete enabled</label>

View File

@ -227,8 +227,10 @@ describe('RgwBucketFormComponent', () => {
component.editing = true;
rgwBucketServiceGetSpy.and.returnValue(observableOf(fakeResponse));
component.ngOnInit();
component.isVersioningEnabled = versioningChecked;
component.isMfaDeleteEnabled = mfaDeleteChecked;
component.bucketForm.patchValue({
versioning: versioningChecked,
'mfa-delete': mfaDeleteChecked
});
fixture.detectChanges();
const mfaTokenSerial = fixture.debugElement.nativeElement.querySelector('#mfa-token-serial');

View File

@ -33,12 +33,17 @@ export class RgwBucketFormComponent implements OnInit {
resource: string;
zonegroup: string;
placementTargets: object[] = [];
isVersioningEnabled = false;
isVersioningAlreadyEnabled = false;
isMfaDeleteEnabled = false;
isMfaDeleteAlreadyEnabled = false;
icons = Icons;
get isVersioningEnabled(): boolean {
return this.bucketForm.getValue('versioning');
}
get isMfaDeleteEnabled(): boolean {
return this.bucketForm.getValue('mfa-delete');
}
constructor(
private route: ActivatedRoute,
private router: Router,
@ -117,22 +122,26 @@ export class RgwBucketFormComponent implements OnInit {
this.rgwBucketService.get(bid).subscribe((resp: object) => {
this.loading = false;
// Get the default values (incl. the values from disabled fields).
const defaults = _.clone(this.bucketForm.getRawValue());
// Get the values displayed in the form. We need to do that to
// extract those key/value pairs from the response data, otherwise
// the Angular react framework will throw an error if there is no
// field for a given key.
let value: object = _.pick(resp, _.keys(defaults));
value['placement-target'] = resp['placement_rule'];
value['versioning'] = resp['versioning'] === RgwBucketVersioning.ENABLED;
value['mfa-delete'] = resp['mfa_delete'] === RgwBucketMfaDelete.ENABLED;
// Append default values.
value = _.merge(defaults, value);
// Update the form.
this.bucketForm.setValue(value);
if (this.editing) {
this.setVersioningStatus(resp['versioning']);
this.isVersioningAlreadyEnabled = this.isVersioningEnabled;
this.setMfaDeleteStatus(resp['mfa_delete']);
this.isMfaDeleteAlreadyEnabled = this.isMfaDeleteEnabled;
this.setMfaDeleteValidators();
}
@ -308,25 +317,7 @@ export class RgwBucketFormComponent implements OnInit {
return this.isVersioningEnabled ? RgwBucketVersioning.ENABLED : RgwBucketVersioning.SUSPENDED;
}
setVersioningStatus(status: RgwBucketVersioning) {
this.isVersioningEnabled = status === RgwBucketVersioning.ENABLED;
}
updateVersioning() {
this.isVersioningEnabled = !this.isVersioningEnabled;
this.setMfaDeleteValidators();
}
getMfaDeleteStatus() {
return this.isMfaDeleteEnabled ? RgwBucketMfaDelete.ENABLED : RgwBucketMfaDelete.DISABLED;
}
setMfaDeleteStatus(status: RgwBucketMfaDelete) {
this.isMfaDeleteEnabled = status === RgwBucketMfaDelete.ENABLED;
}
updateMfaDelete() {
this.isMfaDeleteEnabled = !this.isMfaDeleteEnabled;
this.setMfaDeleteValidators();
}
}