mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 13:23:34 +00:00
[PM-2282] Make feature flags type safe (#8612)
Refactors the feature flags in ConfigService to be type safe. It also moves the default value to a centralized location rather than the caller defining it. This ensures consistency across the various places they are used.
This commit is contained in:
@@ -3,7 +3,7 @@ import { ComponentFixture, TestBed } from "@angular/core/testing";
|
||||
import { By } from "@angular/platform-browser";
|
||||
import { mock, MockProxy } from "jest-mock-extended";
|
||||
|
||||
import { FeatureFlag, FeatureFlagValue } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { AllowedFeatureFlagTypes, FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
|
||||
@@ -41,10 +41,8 @@ describe("IfFeatureDirective", () => {
|
||||
let content: HTMLElement;
|
||||
let mockConfigService: MockProxy<ConfigService>;
|
||||
|
||||
const mockConfigFlagValue = (flag: FeatureFlag, flagValue: FeatureFlagValue) => {
|
||||
mockConfigService.getFeatureFlag.mockImplementation((f, defaultValue) =>
|
||||
flag == f ? Promise.resolve(flagValue) : Promise.resolve(defaultValue),
|
||||
);
|
||||
const mockConfigFlagValue = (flag: FeatureFlag, flagValue: AllowedFeatureFlagTypes) => {
|
||||
mockConfigService.getFeatureFlag.mockImplementation((f) => Promise.resolve(flagValue as any));
|
||||
};
|
||||
|
||||
const queryContent = (testId: string) =>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Directive, Input, OnInit, TemplateRef, ViewContainerRef } from "@angular/core";
|
||||
|
||||
import { FeatureFlag, FeatureFlagValue } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { AllowedFeatureFlagTypes, FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
|
||||
@@ -23,7 +23,7 @@ export class IfFeatureDirective implements OnInit {
|
||||
* Optional value to compare against the value of the feature flag in the config service.
|
||||
* @default true
|
||||
*/
|
||||
@Input() appIfFeatureValue: FeatureFlagValue = true;
|
||||
@Input() appIfFeatureValue: AllowedFeatureFlagTypes = true;
|
||||
|
||||
private hasView = false;
|
||||
|
||||
|
||||
@@ -34,12 +34,12 @@ describe("canAccessFeature", () => {
|
||||
flag == testFlag ? Promise.resolve(flagValue) : Promise.resolve(defaultValue),
|
||||
);
|
||||
} else if (typeof flagValue === "string") {
|
||||
mockConfigService.getFeatureFlag.mockImplementation((flag, defaultValue = "") =>
|
||||
flag == testFlag ? Promise.resolve(flagValue) : Promise.resolve(defaultValue),
|
||||
mockConfigService.getFeatureFlag.mockImplementation((flag) =>
|
||||
flag == testFlag ? Promise.resolve(flagValue as any) : Promise.resolve(""),
|
||||
);
|
||||
} else if (typeof flagValue === "number") {
|
||||
mockConfigService.getFeatureFlag.mockImplementation((flag, defaultValue = 0) =>
|
||||
flag == testFlag ? Promise.resolve(flagValue) : Promise.resolve(defaultValue),
|
||||
mockConfigService.getFeatureFlag.mockImplementation((flag) =>
|
||||
flag == testFlag ? Promise.resolve(flagValue as any) : Promise.resolve(0),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,6 @@ export class AddEditComponent implements OnInit, OnDestroy {
|
||||
async ngOnInit() {
|
||||
this.flexibleCollectionsV1Enabled = await this.configService.getFeatureFlag(
|
||||
FeatureFlag.FlexibleCollectionsV1,
|
||||
false,
|
||||
);
|
||||
|
||||
this.policyService
|
||||
|
||||
Reference in New Issue
Block a user