Skip to content

upcoming: [M3-9785, M3-9788] - Added NodeBalacer Table and replace Linodes with Resources #12232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Added NodeBalacer Table under Subnets Table and replace Linodes Text with Resources ([#12232](https://github.com/linode/manager/pull/12232))
14 changes: 9 additions & 5 deletions packages/manager/cypress/e2e/core/vpc/vpc-create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { extendRegion } from 'support/util/regions';

import { accountUserFactory } from 'src/factories';
import { getUniqueLinodesFromSubnets } from 'src/features/VPCs/utils';
import { getUniqueResourcesFromSubnets } from 'src/features/VPCs/utils';

import type { Subnet, VPC } from '@linode/api-v4';

Expand Down Expand Up @@ -78,7 +78,7 @@ describe('VPC create flow', () => {
const ipValidationErrorMessage1 = 'A subnet must have an IPv4 range.';
const ipValidationErrorMessage2 = 'The IPv4 range must be in CIDR format.';
const vpcCreationErrorMessage = 'An unknown error has occurred.';
const totalSubnetUniqueLinodes = getUniqueLinodesFromSubnets(mockSubnets);
const totalSubnetUniqueLinodes = getUniqueResourcesFromSubnets(mockSubnets);

mockGetRegions([mockVPCRegion]).as('getRegions');

Expand Down Expand Up @@ -238,7 +238,9 @@ describe('VPC create flow', () => {
.should('be.visible')
.within(() => {
cy.contains(`Subnets ${mockVpc.subnets.length}`).should('be.visible');
cy.contains(`Linodes ${totalSubnetUniqueLinodes}`).should('be.visible');
cy.contains(`Resources ${totalSubnetUniqueLinodes}`).should(
'be.visible'
);
cy.contains(`VPC ID ${mockVpc.id}`).should('be.visible');
cy.contains(`Region ${mockVPCRegion.label}`).should('be.visible');
});
Expand Down Expand Up @@ -276,7 +278,7 @@ describe('VPC create flow', () => {
subnets: [],
});

const totalSubnetUniqueLinodes = getUniqueLinodesFromSubnets([]);
const totalSubnetUniqueLinodes = getUniqueResourcesFromSubnets([]);

mockGetRegions([mockVPCRegion]).as('getRegions');

Expand Down Expand Up @@ -326,7 +328,9 @@ describe('VPC create flow', () => {
.should('be.visible')
.within(() => {
cy.contains(`Subnets ${mockVpc.subnets.length}`).should('be.visible');
cy.contains(`Linodes ${totalSubnetUniqueLinodes}`).should('be.visible');
cy.contains(`Resources ${totalSubnetUniqueLinodes}`).should(
'be.visible'
);
cy.contains(`VPC ID ${mockVpc.id}`).should('be.visible');
cy.contains(`Region ${mockVPCRegion.label}`).should('be.visible');
});
Expand Down
15 changes: 14 additions & 1 deletion packages/manager/src/factories/subnets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Factory } from '@linode/utilities';
import type {
Subnet,
SubnetAssignedLinodeData,
SubnetAssignedNodeBalancerData,
} from '@linode/api-v4/lib/vpcs/types';

// NOTE: Changing to fixed array length for the interfaces and linodes fields of the
Expand All @@ -20,6 +21,12 @@ export const subnetAssignedLinodeDataFactory =
),
});

export const subnetAssignedNodebalancerDataFactory =
Factory.Sync.makeFactory<SubnetAssignedNodeBalancerData>({
id: Factory.each((i) => i),
ipv4_range: Factory.each((i) => `192.168.${i}.0/30`),
});

export const subnetFactory = Factory.Sync.makeFactory<Subnet>({
created: '2023-07-12T16:08:53',
id: Factory.each((i) => i),
Expand All @@ -32,6 +39,12 @@ export const subnetFactory = Factory.Sync.makeFactory<Subnet>({
})
)
),
nodebalancers: [],
nodebalancers: Factory.each((i) =>
Array.from({ length: 3 }, (_, arrIdx) =>
subnetAssignedNodebalancerDataFactory.build({
id: i * 10 + arrIdx,
})
)
),
updated: '2023-07-12T16:08:53',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { waitFor, waitForElementToBeRemoved } from '@testing-library/react';
import * as React from 'react';
import { afterAll, afterEach, beforeAll, describe, it } from 'vitest';

import {
firewallFactory,
subnetAssignedNodebalancerDataFactory,
} from 'src/factories';
import { makeResourcePage } from 'src/mocks/serverHandlers';
import { http, HttpResponse, server } from 'src/mocks/testServer';
import {
mockMatchMedia,
renderWithTheme,
wrapWithTableBody,
} from 'src/utilities/testHelpers';

import { SubnetNodeBalancerRow } from './SubnetNodebalancerRow';

const LOADING_TEST_ID = 'circle-progress';

beforeAll(() => mockMatchMedia());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

describe('SubnetNodeBalancerRow', () => {
const nodebalancer = {
id: 123,
label: 'test-nodebalancer',
};

const configs = [
{ nodes_status: { up: 3, down: 1 } },
{ nodes_status: { up: 2, down: 2 } },
];

const firewalls = makeResourcePage(
firewallFactory.buildList(1, { label: 'mock-firewall' })
);

const subnetNodebalancer = subnetAssignedNodebalancerDataFactory.build({
id: nodebalancer.id,
ipv4_range: '192.168.99.0/30',
});

it('renders loading state', async () => {
const { getByTestId } = renderWithTheme(
wrapWithTableBody(
<SubnetNodeBalancerRow
ipv4={subnetNodebalancer.ipv4_range}
nodeBalancerId={subnetNodebalancer.id}
/>
)
);

expect(getByTestId(LOADING_TEST_ID)).toBeInTheDocument();

Check warning on line 55 in packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 Avoid destructuring queries from `render` result, use `screen.getByTestId` instead Raw Output: {"ruleId":"testing-library/prefer-screen-queries","severity":1,"message":"Avoid destructuring queries from `render` result, use `screen.getByTestId` instead","line":55,"column":12,"nodeType":"Identifier","messageId":"preferScreenQueries","endLine":55,"endColumn":23}

Check warning on line 55 in packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 Don't wrap `getBy*` query with `expect` & presence matchers like `toBeInTheDocument` or `not.toBeNull` as `getBy*` queries fail implicitly when element is not found Raw Output: {"ruleId":"testing-library/prefer-implicit-assert","severity":1,"message":"Don't wrap `getBy*` query with `expect` & presence matchers like `toBeInTheDocument` or `not.toBeNull` as `getBy*` queries fail implicitly when element is not found","line":55,"column":12,"nodeType":"Identifier","messageId":"preferImplicitAssert","endLine":55,"endColumn":23}
await waitForElementToBeRemoved(() => getByTestId(LOADING_TEST_ID));

Check warning on line 56 in packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 Prefer using queryBy* when waiting for disappearance Raw Output: {"ruleId":"testing-library/prefer-query-by-disappearance","severity":1,"message":"Prefer using queryBy* when waiting for disappearance","line":56,"column":43,"nodeType":"Identifier","messageId":"preferQueryByDisappearance","endLine":56,"endColumn":54}

Check warning on line 56 in packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 Avoid destructuring queries from `render` result, use `screen.getByTestId` instead Raw Output: {"ruleId":"testing-library/prefer-screen-queries","severity":1,"message":"Avoid destructuring queries from `render` result, use `screen.getByTestId` instead","line":56,"column":43,"nodeType":"Identifier","messageId":"preferScreenQueries","endLine":56,"endColumn":54}
});

it('renders nodebalancer row with data', async () => {
server.use(
http.get('*/nodebalancers/:id', () => {
return HttpResponse.json(nodebalancer);
}),
http.get('*/nodebalancers/:id/configs', () => {
return HttpResponse.json(configs);
}),
http.get('*/nodebalancers/:id/firewalls', () => {
return HttpResponse.json(firewalls);
})
);

const { getByText, getByRole } = renderWithTheme(
wrapWithTableBody(
<SubnetNodeBalancerRow
ipv4={subnetNodebalancer.ipv4_range}
nodeBalancerId={nodebalancer.id}
/>
)
);

await waitFor(() => {
expect(getByText(nodebalancer.label)).toBeInTheDocument();

Check warning on line 82 in packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 Avoid destructuring queries from `render` result, use `screen.getByText` instead Raw Output: {"ruleId":"testing-library/prefer-screen-queries","severity":1,"message":"Avoid destructuring queries from `render` result, use `screen.getByText` instead","line":82,"column":14,"nodeType":"Identifier","messageId":"preferScreenQueries","endLine":82,"endColumn":23}

Check warning on line 82 in packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 Don't wrap `getBy*` query with `expect` & presence matchers like `toBeInTheDocument` or `not.toBeNull` as `getBy*` queries fail implicitly when element is not found Raw Output: {"ruleId":"testing-library/prefer-implicit-assert","severity":1,"message":"Don't wrap `getBy*` query with `expect` & presence matchers like `toBeInTheDocument` or `not.toBeNull` as `getBy*` queries fail implicitly when element is not found","line":82,"column":14,"nodeType":"Identifier","messageId":"preferImplicitAssert","endLine":82,"endColumn":23}
});

expect(getByText(subnetNodebalancer.ipv4_range)).toBeInTheDocument();

Check warning on line 85 in packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 Avoid destructuring queries from `render` result, use `screen.getByText` instead Raw Output: {"ruleId":"testing-library/prefer-screen-queries","severity":1,"message":"Avoid destructuring queries from `render` result, use `screen.getByText` instead","line":85,"column":12,"nodeType":"Identifier","messageId":"preferScreenQueries","endLine":85,"endColumn":21}

Check warning on line 85 in packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 Don't wrap `getBy*` query with `expect` & presence matchers like `toBeInTheDocument` or `not.toBeNull` as `getBy*` queries fail implicitly when element is not found Raw Output: {"ruleId":"testing-library/prefer-implicit-assert","severity":1,"message":"Don't wrap `getBy*` query with `expect` & presence matchers like `toBeInTheDocument` or `not.toBeNull` as `getBy*` queries fail implicitly when element is not found","line":85,"column":12,"nodeType":"Identifier","messageId":"preferImplicitAssert","endLine":85,"endColumn":21}
expect(getByText('mock-firewall')).toBeInTheDocument();

Check warning on line 86 in packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 Avoid destructuring queries from `render` result, use `screen.getByText` instead Raw Output: {"ruleId":"testing-library/prefer-screen-queries","severity":1,"message":"Avoid destructuring queries from `render` result, use `screen.getByText` instead","line":86,"column":12,"nodeType":"Identifier","messageId":"preferScreenQueries","endLine":86,"endColumn":21}

Check warning on line 86 in packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.test.tsx

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 Don't wrap `getBy*` query with `expect` & presence matchers like `toBeInTheDocument` or `not.toBeNull` as `getBy*` queries fail implicitly when element is not found Raw Output: {"ruleId":"testing-library/prefer-implicit-assert","severity":1,"message":"Don't wrap `getBy*` query with `expect` & presence matchers like `toBeInTheDocument` or `not.toBeNull` as `getBy*` queries fail implicitly when element is not found","line":86,"column":12,"nodeType":"Identifier","messageId":"preferImplicitAssert","endLine":86,"endColumn":21}

const nodebalancerLink = getByRole('link', {
name: nodebalancer.label,
});

expect(nodebalancerLink).toHaveAttribute(
'href',
`/nodebalancers/${nodebalancer.id}/summary`
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import {
useAllNodeBalancerConfigsQuery,
useNodeBalancerQuery,
useNodeBalancersFirewallsQuery,
} from '@linode/queries';
import { Box, CircleProgress, Hidden } from '@linode/ui';
import ErrorOutline from '@mui/icons-material/ErrorOutline';
import { Typography } from '@mui/material';
import * as React from 'react';

import { Link } from 'src/components/Link';
import { StatusIcon } from 'src/components/StatusIcon/StatusIcon';
import { TableCell } from 'src/components/TableCell';
import { TableRow } from 'src/components/TableRow';

interface Props {
hover?: boolean;
ipv4: string;
nodeBalancerId: number;
}

export const SubnetNodeBalancerRow = ({
nodeBalancerId,
hover = false,
ipv4,
}: Props) => {
const {
data: nodebalancer,
error: nodebalancerError,
isLoading: nodebalancerLoading,
} = useNodeBalancerQuery(nodeBalancerId);
const { data: attachedFirewallData } = useNodeBalancersFirewallsQuery(
Number(nodeBalancerId)
);
const { data: configs } = useAllNodeBalancerConfigsQuery(
Number(nodeBalancerId)
);

const firewallLabel = attachedFirewallData?.data[0]?.label;
const firewallId = attachedFirewallData?.data[0]?.id;

const down = configs?.reduce((acc: number, config) => {
return acc + config.nodes_status.down;
}, 0); // add the downtime for each config together

const up = configs?.reduce((acc: number, config) => {
return acc + config.nodes_status.up;
}, 0); // add the uptime for each config together

if (nodebalancerLoading || !nodebalancer) {
return (
<TableRow hover={hover}>
<TableCell colSpan={6} style={{ justifyItems: 'center' }}>
<CircleProgress size="sm" />
</TableCell>
</TableRow>
);
}

if (nodebalancerError) {
return (
<TableRow data-testid="subnet-nodebalancer-row-error" hover={hover}>
<TableCell colSpan={6} style={{ justifyItems: 'center' }}>
<Box alignItems="center" display="flex">
<ErrorOutline
data-qa-error-icon
sx={(theme) => ({ color: theme.color.red, marginRight: 1 })}
/>
<Typography>
There was an error loading{' '}
<Link to={`/nodebalancers/${nodebalancer?.id}/summary`}>
Nodebalancer {nodeBalancerId}
</Link>
</Typography>
</Box>
</TableCell>
</TableRow>
);
}

return (
<TableRow key={nodeBalancerId}>
<TableCell>
<Link
className="secondaryLink"
to={`/nodebalancers/${nodebalancer?.id}/summary`}
>
{nodebalancer?.label}
</Link>
</TableCell>
<TableCell statusCell>
<StatusIcon
aria-label={`Nodebalancer status active`}
status={'active'}
/>
{`${up} up, ${down} down`}
</TableCell>
<TableCell>{ipv4}</TableCell>
<TableCell>
<Link
accessibleAriaLabel={`Firewall ${firewallLabel}`}
className="secondaryLink"
to={`/firewalls/${firewallId}`}
>
{firewallLabel}
</Link>
</TableCell>
</TableRow>
);
};

export const SubnetNodebalancerTableRowHead = (
<TableRow>
<TableCell>NodeBalancer</TableCell>
<TableCell>Backend Status</TableCell>
<Hidden smDown>
<TableCell>VPC IPv4 Range</TableCell>
</Hidden>
<Hidden smDown>
<TableCell>Firewalls</TableCell>
</Hidden>
<TableCell />
</TableRow>
);
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('VPC Detail Summary section', () => {
});
});

it('should display number of subnets and linodes, region, id, creation and update dates', async () => {
it('should display number of subnets and resources, region, id, creation and update dates', async () => {
const vpcFactory1 = vpcFactory.build({ id: 1, subnets: [] });
server.use(
http.get('*/vpcs/:vpcId', () => {
Expand All @@ -60,7 +60,7 @@ describe('VPC Detail Summary section', () => {
}

getAllByText('Subnets');
getAllByText('Linodes');
getAllByText('Resources');
getAllByText('0');

getAllByText('Region');
Expand Down
6 changes: 3 additions & 3 deletions packages/manager/src/features/VPCs/VPCDetail/VPCDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { VPC_DOCS_LINK, VPC_LABEL } from 'src/features/VPCs/constants';

import {
getIsVPCLKEEnterpriseCluster,
getUniqueLinodesFromSubnets,
getUniqueResourcesFromSubnets,
} from '../utils';
import { VPCDeleteDialog } from '../VPCLanding/VPCDeleteDialog';
import { VPCEditDrawer } from '../VPCLanding/VPCEditDrawer';
Expand Down Expand Up @@ -93,7 +93,7 @@ const VPCDetail = () => {
const regionLabel =
regions?.find((r) => r.id === vpc.region)?.label ?? vpc.region;

const numLinodes = getUniqueLinodesFromSubnets(vpc.subnets);
const numLinodes = getUniqueResourcesFromSubnets(vpc.subnets);

const summaryData = [
[
Expand All @@ -102,7 +102,7 @@ const VPCDetail = () => {
value: vpc.subnets.length,
},
{
label: 'Linodes',
label: 'Resources',
value: numLinodes,
},
],
Expand Down
Loading
Loading