mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
[PM-6827] Browser Extension Refresh - Tabs Routing (#9004)
* [PM-6827] Add componentRouteSwap util function * [PM-6827] Add extension-refresh feature flag * [PM-6827] Add extension-refresh route swap utils * [PM-6827] Add the TabsV2 component * [PM-6827] Add the TabsV2 to routing module * [PM-6827] Fix route prefixes in popup-tab-navigation component
This commit is contained in:
55
libs/angular/src/utils/component-route-swap.ts
Normal file
55
libs/angular/src/utils/component-route-swap.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { Type } from "@angular/core";
|
||||
import { Route, Routes } from "@angular/router";
|
||||
|
||||
/**
|
||||
* Helper function to swap between two components based on an async condition. The async condition is evaluated
|
||||
* as an `CanMatchFn` and supports Angular dependency injection via `inject()`.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const routes = [
|
||||
* ...componentRouteSwap(
|
||||
* defaultComponent,
|
||||
* altComponent,
|
||||
* async () => {
|
||||
* const configService = inject(ConfigService);
|
||||
* return configService.getFeatureFlag(FeatureFlag.SomeFlag);
|
||||
* },
|
||||
* {
|
||||
* path: 'some-path'
|
||||
* }
|
||||
* ),
|
||||
* // Other routes...
|
||||
* ];
|
||||
* ```
|
||||
*
|
||||
* @param defaultComponent - The default component to render.
|
||||
* @param altComponent - The alternate component to render when the condition is met.
|
||||
* @param shouldSwapFn - The async function to determine if the alternate component should be rendered.
|
||||
* @param options - The shared route options to apply to both components.
|
||||
*/
|
||||
export function componentRouteSwap(
|
||||
defaultComponent: Type<any>,
|
||||
altComponent: Type<any>,
|
||||
shouldSwapFn: () => Promise<boolean>,
|
||||
options: Route,
|
||||
): Routes {
|
||||
const defaultRoute = {
|
||||
...options,
|
||||
component: defaultComponent,
|
||||
};
|
||||
|
||||
const altRoute: Route = {
|
||||
...options,
|
||||
component: altComponent,
|
||||
canMatch: [
|
||||
async () => {
|
||||
return await shouldSwapFn();
|
||||
},
|
||||
...(options.canMatch ?? []),
|
||||
],
|
||||
};
|
||||
|
||||
// Return the alternate route first, so it is evaluated first.
|
||||
return [altRoute, defaultRoute];
|
||||
}
|
||||
@@ -16,6 +16,7 @@ export enum FeatureFlag {
|
||||
AC1795_UpdatedSubscriptionStatusSection = "AC-1795_updated-subscription-status-section",
|
||||
UnassignedItemsBanner = "unassigned-items-banner",
|
||||
EnableDeleteProvider = "AC-1218-delete-provider",
|
||||
ExtensionRefresh = "extension-refresh",
|
||||
}
|
||||
|
||||
export type AllowedFeatureFlagTypes = boolean | number | string;
|
||||
@@ -42,6 +43,7 @@ export const DefaultFeatureFlagValue = {
|
||||
[FeatureFlag.AC1795_UpdatedSubscriptionStatusSection]: FALSE,
|
||||
[FeatureFlag.UnassignedItemsBanner]: FALSE,
|
||||
[FeatureFlag.EnableDeleteProvider]: FALSE,
|
||||
[FeatureFlag.ExtensionRefresh]: FALSE,
|
||||
} satisfies Record<FeatureFlag, AllowedFeatureFlagTypes>;
|
||||
|
||||
export type DefaultFeatureFlagValueType = typeof DefaultFeatureFlagValue;
|
||||
|
||||
Reference in New Issue
Block a user