From 01f5db4fa485aa52a2824b4948711effb283eb13 Mon Sep 17 00:00:00 2001 From: Dajahi Wiley Date: Fri, 28 Feb 2025 16:20:54 -0500 Subject: [PATCH] Add useIsNodebalancerVPCEnabled() hook and test coverage; fix flag name from nodebalancerVPC --> nodebalancerVpc --- .../manager/src/dev-tools/FeatureFlagTool.tsx | 2 +- packages/manager/src/featureFlags.ts | 2 +- .../src/features/NodeBalancers/utils.test.ts | 31 +++++++++++++++++++ .../src/features/NodeBalancers/utils.ts | 17 ++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 packages/manager/src/features/NodeBalancers/utils.test.ts diff --git a/packages/manager/src/dev-tools/FeatureFlagTool.tsx b/packages/manager/src/dev-tools/FeatureFlagTool.tsx index 70de56d4cc4..6fe611676df 100644 --- a/packages/manager/src/dev-tools/FeatureFlagTool.tsx +++ b/packages/manager/src/dev-tools/FeatureFlagTool.tsx @@ -28,7 +28,7 @@ const options: { flag: keyof Flags; label: string }[] = [ { flag: 'linodeDiskEncryption', label: 'Linode Disk Encryption (LDE)' }, { flag: 'linodeInterfaces', label: 'Linode Interfaces' }, { flag: 'lkeEnterprise', label: 'LKE-Enterprise' }, - { flag: 'nodebalancerVPC', label: 'NodeBalancer-VPC Integration' }, + { flag: 'nodebalancerVpc', label: 'NodeBalancer-VPC Integration' }, { flag: 'objMultiCluster', label: 'OBJ Multi-Cluster' }, { flag: 'objectStorageGen2', label: 'OBJ Gen2' }, { flag: 'selfServeBetas', label: 'Self Serve Betas' }, diff --git a/packages/manager/src/featureFlags.ts b/packages/manager/src/featureFlags.ts index a3ed5f146ae..74f43c0e71e 100644 --- a/packages/manager/src/featureFlags.ts +++ b/packages/manager/src/featureFlags.ts @@ -126,7 +126,7 @@ export interface Flags { mainContentBanner: MainContentBanner; marketplaceAppOverrides: MarketplaceAppOverride[]; metadata: boolean; - nodebalancerVPC: boolean; + nodebalancerVpc: boolean; objMultiCluster: boolean; objectStorageGen2: BaseFeatureFlag; productInformationBanners: ProductInformationBannerFlag[]; diff --git a/packages/manager/src/features/NodeBalancers/utils.test.ts b/packages/manager/src/features/NodeBalancers/utils.test.ts new file mode 100644 index 00000000000..b207693537d --- /dev/null +++ b/packages/manager/src/features/NodeBalancers/utils.test.ts @@ -0,0 +1,31 @@ +import { renderHook, waitFor } from '@testing-library/react'; + +import { wrapWithTheme } from 'src/utilities/testHelpers'; + +import { useIsNodebalancerVPCEnabled } from './utils'; + +describe('useIsNodebalancerVPCEnabled', () => { + it('returns true if the feature is enabled', async () => { + const options = { flags: { nodebalancerVpc: true } }; + + const { result } = renderHook(() => useIsNodebalancerVPCEnabled(), { + wrapper: (ui) => wrapWithTheme(ui, options), + }); + + await waitFor(() => { + expect(result.current.isNodebalancerVPCEnabled).toBe(true); + }); + }); + + it('returns false if the feature is NOT enabled', async () => { + const options = { flags: { nodebalancerVpc: false } }; + + const { result } = renderHook(() => useIsNodebalancerVPCEnabled(), { + wrapper: (ui) => wrapWithTheme(ui, options), + }); + + await waitFor(() => { + expect(result.current.isNodebalancerVPCEnabled).toBe(false); + }); + }); +}); diff --git a/packages/manager/src/features/NodeBalancers/utils.ts b/packages/manager/src/features/NodeBalancers/utils.ts index e8dca450145..5ee96d6075d 100644 --- a/packages/manager/src/features/NodeBalancers/utils.ts +++ b/packages/manager/src/features/NodeBalancers/utils.ts @@ -1,5 +1,6 @@ import { filter, isNil } from 'ramda'; +import { useFlags } from 'src/hooks/useFlags'; import { getErrorMap } from 'src/utilities/errorUtils'; import { @@ -211,3 +212,19 @@ export const getStickinessOptions = (protocol: Protocol) => { option.supportedProtocols.includes(protocol) ); }; + +/** + * Returns whether or not features related to the NB-VPC project + * should be enabled. + * + * Currently, this just uses the `nodebalancerVPC` feature flag as a source of truth, + * but will eventually also look at account capabilities. + */ + +export const useIsNodebalancerVPCEnabled = () => { + const flags = useFlags(); + + // @TODO NB-VPC: check for customer tag/account capability when it exists + + return { isNodebalancerVPCEnabled: flags.nodebalancerVpc ?? false }; +};