mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 13:23:34 +00:00
PM-3623 - VaultTimeoutInputComp - resolve double value changes emission issue which was causing double dialogs to be shown when the user chose never as a vault timeout option by not emitting the setting of the custom hours & min values based on the user's non-custom timeout choice. + Add interface for form value to replace any. (#6098)
This commit is contained in:
@@ -15,6 +15,14 @@ import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
|||||||
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
|
|
||||||
|
interface VaultTimeoutFormValue {
|
||||||
|
vaultTimeout: number | null;
|
||||||
|
custom: {
|
||||||
|
hours: number | null;
|
||||||
|
minutes: number | null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Directive()
|
@Directive()
|
||||||
export class VaultTimeoutInputComponent
|
export class VaultTimeoutInputComponent
|
||||||
implements ControlValueAccessor, Validator, OnInit, OnDestroy, OnChanges
|
implements ControlValueAccessor, Validator, OnInit, OnDestroy, OnChanges
|
||||||
@@ -70,7 +78,9 @@ export class VaultTimeoutInputComponent
|
|||||||
this.applyVaultTimeoutPolicy();
|
this.applyVaultTimeoutPolicy();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.form.valueChanges.pipe(takeUntil(this.destroy$)).subscribe((value) => {
|
this.form.valueChanges
|
||||||
|
.pipe(takeUntil(this.destroy$))
|
||||||
|
.subscribe((value: VaultTimeoutFormValue) => {
|
||||||
if (this.onChange) {
|
if (this.onChange) {
|
||||||
this.onChange(this.getVaultTimeout(value));
|
this.onChange(this.getVaultTimeout(value));
|
||||||
}
|
}
|
||||||
@@ -87,12 +97,19 @@ export class VaultTimeoutInputComponent
|
|||||||
)
|
)
|
||||||
.subscribe((value) => {
|
.subscribe((value) => {
|
||||||
const current = Math.max(value, 0);
|
const current = Math.max(value, 0);
|
||||||
this.form.patchValue({
|
|
||||||
|
// This cannot emit an event b/c it would cause form.valueChanges to fire again
|
||||||
|
// and we are already handling that above so just silently update
|
||||||
|
// custom fields when vaultTimeout changes to a non-custom value
|
||||||
|
this.form.patchValue(
|
||||||
|
{
|
||||||
custom: {
|
custom: {
|
||||||
hours: Math.floor(current / 60),
|
hours: Math.floor(current / 60),
|
||||||
minutes: current % 60,
|
minutes: current % 60,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
{ emitEvent: false }
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.canLockVault$ = this.vaultTimeoutSettingsService
|
this.canLockVault$ = this.vaultTimeoutSettingsService
|
||||||
@@ -116,7 +133,7 @@ export class VaultTimeoutInputComponent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getVaultTimeout(value: any) {
|
getVaultTimeout(value: VaultTimeoutFormValue) {
|
||||||
if (value.vaultTimeout !== VaultTimeoutInputComponent.CUSTOM_VALUE) {
|
if (value.vaultTimeout !== VaultTimeoutInputComponent.CUSTOM_VALUE) {
|
||||||
return value.vaultTimeout;
|
return value.vaultTimeout;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user