Skip to content

Commit

Permalink
Add useIsNodebalancerVPCEnabled() hook and test coverage; fix flag na…
Browse files Browse the repository at this point in the history
…me from nodebalancerVPC --> nodebalancerVpc
  • Loading branch information
DevDW committed Feb 28, 2025
1 parent e878bb4 commit 01f5db4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/manager/src/dev-tools/FeatureFlagTool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export interface Flags {
mainContentBanner: MainContentBanner;
marketplaceAppOverrides: MarketplaceAppOverride[];
metadata: boolean;
nodebalancerVPC: boolean;
nodebalancerVpc: boolean;
objMultiCluster: boolean;
objectStorageGen2: BaseFeatureFlag;
productInformationBanners: ProductInformationBannerFlag[];
Expand Down
31 changes: 31 additions & 0 deletions packages/manager/src/features/NodeBalancers/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
17 changes: 17 additions & 0 deletions packages/manager/src/features/NodeBalancers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { filter, isNil } from 'ramda';

import { useFlags } from 'src/hooks/useFlags';
import { getErrorMap } from 'src/utilities/errorUtils';

import {
Expand Down Expand Up @@ -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 };
};

0 comments on commit 01f5db4

Please sign in to comment.