mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
* Use typescript-strict-plugin to iteratively turn on strict * Add strict testing to pipeline Can be executed locally through either `npm run test:types` for full type checking including spec files, or `npx tsc-strict` for only tsconfig.json included files. * turn on strict for scripts directory * Use plugin for all tsconfigs in monorepo vscode is capable of executing tsc with plugins, but uses the most relevant tsconfig to do so. If the plugin is not a part of that config, it is skipped and developers get no feedback of strict compile time issues. These updates remedy that at the cost of slightly more complex removal of the plugin when the time comes. * remove plugin from configs that extend one that already has it * Update workspace settings to honor strict plugin * Apply strict-plugin to native message test runner * Update vscode workspace to use root tsc version * `./node_modules/.bin/update-strict-comments` 🤖 This is a one-time operation. All future files should adhere to strict type checking. * Add fixme to `ts-strict-ignore` comments * `update-strict-comments` 🤖 repeated for new merge files
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import { Directive, Input, OnInit, TemplateRef, ViewContainerRef } from "@angular/core";
|
|
|
|
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";
|
|
|
|
/**
|
|
* Directive that conditionally renders the element when the feature flag is enabled and/or
|
|
* matches the value specified by {@link appIfFeatureValue}.
|
|
*
|
|
* When a feature flag is not found in the config service, the element is hidden.
|
|
*/
|
|
@Directive({
|
|
selector: "[appIfFeature]",
|
|
})
|
|
export class IfFeatureDirective implements OnInit {
|
|
/**
|
|
* The feature flag to check.
|
|
*/
|
|
@Input() appIfFeature: FeatureFlag;
|
|
|
|
/**
|
|
* Optional value to compare against the value of the feature flag in the config service.
|
|
* @default true
|
|
*/
|
|
@Input() appIfFeatureValue: AllowedFeatureFlagTypes = true;
|
|
|
|
private hasView = false;
|
|
|
|
constructor(
|
|
private templateRef: TemplateRef<any>,
|
|
private viewContainer: ViewContainerRef,
|
|
private configService: ConfigService,
|
|
private logService: LogService,
|
|
) {}
|
|
|
|
async ngOnInit() {
|
|
try {
|
|
const flagValue = await this.configService.getFeatureFlag(this.appIfFeature);
|
|
|
|
if (this.appIfFeatureValue === flagValue) {
|
|
if (!this.hasView) {
|
|
this.viewContainer.createEmbeddedView(this.templateRef);
|
|
this.hasView = true;
|
|
}
|
|
} else {
|
|
this.viewContainer.clear();
|
|
this.hasView = false;
|
|
}
|
|
} catch (e) {
|
|
this.logService.error(e);
|
|
this.viewContainer.clear();
|
|
this.hasView = false;
|
|
}
|
|
}
|
|
}
|