Skip to content

Commit 9f4a82a

Browse files
upcoming: [UIE-9709] - Integrate Prefix List Details Drawer with Edit and Add Rule Drawer (#13158)
* Update tests and fix typo * Added changeset: Integrate Prefix List details drawer with Edit and Add Rule drawer * Add tests for handleOpenPrefixListDrawer call on click of View Details * Update ruleset details drawer button text from cancel to close * Change from Link to LinkButton * Update mock protocol
1 parent bb2a467 commit 9f4a82a

11 files changed

+110
-32
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Upcoming Features
3+
---
4+
5+
Integrate Prefix List details drawer with Edit and Add Rule drawer ([#13158](https://github.com/linode/manager/pull/13158))

packages/manager/src/features/Firewalls/FirewallDetail/Rules/FirewallPrefixListDrawer.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ const computeExpectedElements = (
5252
label = 'Prefix List Name:';
5353
}
5454

55+
if (context?.type === 'rule' && context.modeViewedFrom === 'create') {
56+
title = `Add an ${capitalize(category)} Rule or Rule Set`;
57+
button = `Back to ${capitalize(category)} Rule`;
58+
label = 'Prefix List Name:';
59+
}
60+
5561
if (context?.type === 'ruleset' && context.modeViewedFrom === 'view') {
5662
title = `${capitalize(category)} Rule Set details`;
5763
button = 'Back to the Rule Set';
@@ -98,6 +104,15 @@ describe('PrefixListDrawer', () => {
98104
plRuleRef: { inIPv4Rule: true, inIPv6Rule: true },
99105
},
100106
},
107+
{
108+
...baseProps,
109+
category: 'inbound',
110+
context: {
111+
type: 'rule',
112+
modeViewedFrom: 'create',
113+
plRuleRef: { inIPv4Rule: true, inIPv6Rule: true },
114+
},
115+
},
101116
{
102117
...baseProps,
103118
category: 'outbound',

packages/manager/src/features/Firewalls/FirewallDetail/Rules/FirewallPrefixListDrawer.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ export const FirewallPrefixListDrawer = React.memo(
8080
};
8181
}
8282

83+
if (type === 'rule' && modeViewedFrom === 'create') {
84+
return {
85+
title: `Add an ${capitalize(category)} Rule or Rule Set`,
86+
backButton: `Back to ${capitalize(category)} Rule`,
87+
};
88+
}
89+
8390
if (type === 'ruleset' && modeViewedFrom === 'view') {
8491
return {
8592
title: `${capitalize(category)} Rule Set details`,

packages/manager/src/features/Firewalls/FirewallDetail/Rules/FirewallRuleDrawer.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe('ViewRuleSetDetailsDrawer', () => {
267267
expect(getByText(`${capitalize(category)} Rules`)).toBeVisible();
268268

269269
// Cancel button
270-
expect(getByRole('button', { name: 'Cancel' })).toBeVisible();
270+
expect(getByRole('button', { name: 'Close' })).toBeVisible();
271271
}
272272
);
273273
});

packages/manager/src/features/Firewalls/FirewallDetail/Rules/FirewallRuleDrawer.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ export const FirewallRuleDrawer = React.memo(
245245
addressesLabel={addressesLabel}
246246
category={category}
247247
closeDrawer={onClose}
248+
handleOpenPrefixListDrawer={(prefixListLabel, plRuleRef) => {
249+
handleOpenPrefixListDrawer(
250+
prefixListLabel,
251+
plRuleRef,
252+
'rule'
253+
);
254+
}}
248255
ips={ips}
249256
mode={mode}
250257
pls={pls}

packages/manager/src/features/Firewalls/FirewallDetail/Rules/FirewallRuleDrawer.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export interface FirewallRuleFormProps extends FormikProps<FormState> {
4545
addressesLabel: string;
4646
category: Category;
4747
closeDrawer: () => void;
48+
handleOpenPrefixListDrawer: (
49+
prefixListLabel: string,
50+
plRuleRef: PrefixListRuleReference
51+
) => void;
4852
ips: ExtendedIP[];
4953
mode: FirewallRuleDrawerMode;
5054
pls: ExtendedPL[];

packages/manager/src/features/Firewalls/FirewallDetail/Rules/FirewallRuleForm.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
import { ipFieldPlaceholder } from 'src/utilities/ipUtils';
2525

2626
import { enforceIPMasks } from './FirewallRuleDrawer.utils';
27-
import { MultiplePrefixListSelect } from './MutiplePrefixListSelect';
27+
import { MultiplePrefixListSelect } from './MultiplePrefixListSelect';
2828
import { PORT_PRESETS, PORT_PRESETS_ITEMS } from './shared';
2929

3030
import type { FirewallRuleFormProps } from './FirewallRuleDrawer.types';
@@ -45,6 +45,7 @@ export const FirewallRuleForm = React.memo((props: FirewallRuleFormProps) => {
4545
errors,
4646
handleBlur,
4747
handleChange,
48+
handleOpenPrefixListDrawer,
4849
handleSubmit,
4950
ips,
5051
pls,
@@ -348,6 +349,7 @@ export const FirewallRuleForm = React.memo((props: FirewallRuleFormProps) => {
348349
{isFirewallRulesetsPrefixlistsFeatureEnabled && (
349350
<MultiplePrefixListSelect
350351
aria-label="Prefix List for Firewall rule"
352+
handleOpenPrefixListDrawer={handleOpenPrefixListDrawer}
351353
onChange={handlePrefixListChange}
352354
pls={pls}
353355
/>

packages/manager/src/features/Firewalls/FirewallDetail/Rules/FirewallRuleSetDetailsView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const FirewallRuleSetDetailsView = (
196196

197197
<ActionsPanel
198198
secondaryButtonProps={{
199-
label: 'Cancel',
199+
label: 'Close',
200200
onClick: closeDrawer,
201201
}}
202202
/>

packages/manager/src/features/Firewalls/FirewallDetail/Rules/MutiplePrefixListSelect.test.tsx renamed to packages/manager/src/features/Firewalls/FirewallDetail/Rules/MultiplePrefixListSelect.test.tsx

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React from 'react';
55
import { renderWithTheme } from 'src/utilities/testHelpers';
66

77
import * as shared from '../../shared';
8-
import { MultiplePrefixListSelect } from './MutiplePrefixListSelect';
8+
import { MultiplePrefixListSelect } from './MultiplePrefixListSelect';
99

1010
const queryMocks = vi.hoisted(() => ({
1111
useAllFirewallPrefixListsQuery: vi.fn().mockReturnValue({}),
@@ -31,7 +31,10 @@ describe('MultiplePrefixListSelect', () => {
3131
});
3232
});
3333

34-
const onChange = vi.fn();
34+
const baseProps = {
35+
handleOpenPrefixListDrawer: vi.fn(),
36+
onChange: vi.fn(),
37+
};
3538

3639
const mockPrefixLists = [
3740
{
@@ -62,7 +65,7 @@ describe('MultiplePrefixListSelect', () => {
6265
it('should render the title only when at least one PL row is added', () => {
6366
const { getByText } = renderWithTheme(
6467
<MultiplePrefixListSelect
65-
onChange={vi.fn()}
68+
{...baseProps}
6669
pls={[{ address: '', inIPv4Rule: false, inIPv6Rule: false }]}
6770
/>
6871
);
@@ -71,24 +74,23 @@ describe('MultiplePrefixListSelect', () => {
7174

7275
it('should not render the title when no PL row is added', () => {
7376
const { queryByText } = renderWithTheme(
74-
<MultiplePrefixListSelect onChange={vi.fn()} pls={[]} />
77+
<MultiplePrefixListSelect {...baseProps} pls={[]} />
7578
);
7679
expect(queryByText('Prefix List')).not.toBeInTheDocument();
7780
});
7881

7982
it('should add a new PL row (empty state) when clicking "Add a Prefix List"', async () => {
8083
const { getByText } = renderWithTheme(
81-
<MultiplePrefixListSelect onChange={onChange} pls={[]} />
84+
<MultiplePrefixListSelect {...baseProps} pls={[]} />
8285
);
8386

8487
await userEvent.click(getByText('Add a Prefix List'));
85-
expect(onChange).toHaveBeenCalledWith([
88+
expect(baseProps.onChange).toHaveBeenCalledWith([
8689
{ address: '', inIPv4Rule: false, inIPv6Rule: false },
8790
]);
8891
});
8992

9093
it('should remove a PL row when clicking delete (X)', async () => {
91-
const onChange = vi.fn();
9294
const pls = [
9395
{
9496
address: 'pl::supports-both',
@@ -97,17 +99,17 @@ describe('MultiplePrefixListSelect', () => {
9799
},
98100
];
99101
const { getByTestId } = renderWithTheme(
100-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
102+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
101103
);
102104

103105
await userEvent.click(getByTestId('delete-pl-0'));
104-
expect(onChange).toHaveBeenCalledWith([]);
106+
expect(baseProps.onChange).toHaveBeenCalledWith([]);
105107
});
106108

107109
it('filters out unsupported PLs from dropdown', async () => {
108110
const pls = [{ address: '', inIPv4Rule: false, inIPv6Rule: false }];
109111
const { getByRole, queryByText } = renderWithTheme(
110-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
112+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
111113
);
112114

113115
const input = getByRole('combobox');
@@ -131,7 +133,7 @@ describe('MultiplePrefixListSelect', () => {
131133
{ address: '', inIPv4Rule: false, inIPv6Rule: false },
132134
];
133135
const { getAllByRole, findByText } = renderWithTheme(
134-
<MultiplePrefixListSelect onChange={onChange} pls={selectedPLs} />
136+
<MultiplePrefixListSelect {...baseProps} pls={selectedPLs} />
135137
);
136138

137139
const inputs = getAllByRole('combobox');
@@ -166,7 +168,7 @@ describe('MultiplePrefixListSelect', () => {
166168
},
167169
];
168170
const { getByDisplayValue, queryAllByTestId } = renderWithTheme(
169-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
171+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
170172
);
171173

172174
expect(queryAllByTestId('prefixlist-select')).toHaveLength(3);
@@ -178,7 +180,7 @@ describe('MultiplePrefixListSelect', () => {
178180
it('defaults to IPv4 selected and IPv6 unselected when choosing a PL that supports both', async () => {
179181
const pls = [{ address: '', inIPv4Rule: false, inIPv6Rule: false }];
180182
const { findByText, getByRole } = renderWithTheme(
181-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
183+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
182184
);
183185

184186
const input = getByRole('combobox');
@@ -190,7 +192,7 @@ describe('MultiplePrefixListSelect', () => {
190192
const option = await findByText('pl::supports-both');
191193
await userEvent.click(option);
192194

193-
expect(onChange).toHaveBeenCalledWith([
195+
expect(baseProps.onChange).toHaveBeenCalledWith([
194196
{
195197
address: 'pl::supports-both',
196198
inIPv4Rule: true,
@@ -202,7 +204,7 @@ describe('MultiplePrefixListSelect', () => {
202204
it('defaults to IPv4 selected and IPv6 unselected when choosing a PL that supports only IPv4', async () => {
203205
const pls = [{ address: '', inIPv4Rule: false, inIPv6Rule: false }];
204206
const { findByText, getByRole } = renderWithTheme(
205-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
207+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
206208
);
207209

208210
const input = getByRole('combobox');
@@ -214,7 +216,7 @@ describe('MultiplePrefixListSelect', () => {
214216
const option = await findByText('pl:system:supports-only-ipv4');
215217
await userEvent.click(option);
216218

217-
expect(onChange).toHaveBeenCalledWith([
219+
expect(baseProps.onChange).toHaveBeenCalledWith([
218220
{
219221
address: 'pl:system:supports-only-ipv4',
220222
inIPv4Rule: true,
@@ -226,7 +228,7 @@ describe('MultiplePrefixListSelect', () => {
226228
it('defaults to IPv4 unselected and IPv6 selected when choosing a PL that supports only IPv6', async () => {
227229
const pls = [{ address: '', inIPv4Rule: false, inIPv6Rule: false }];
228230
const { findByText, getByRole } = renderWithTheme(
229-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
231+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
230232
);
231233

232234
const input = getByRole('combobox');
@@ -238,7 +240,7 @@ describe('MultiplePrefixListSelect', () => {
238240
const option = await findByText('pl::supports-only-ipv6');
239241
await userEvent.click(option);
240242

241-
expect(onChange).toHaveBeenCalledWith([
243+
expect(baseProps.onChange).toHaveBeenCalledWith([
242244
{
243245
address: 'pl::supports-only-ipv6',
244246
inIPv4Rule: false,
@@ -252,7 +254,7 @@ describe('MultiplePrefixListSelect', () => {
252254
{ address: 'pl::supports-both', inIPv4Rule: true, inIPv6Rule: false },
253255
];
254256
const { findByTestId } = renderWithTheme(
255-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
257+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
256258
);
257259

258260
const ipv4CheckboxWrapper = await findByTestId('ipv4-checkbox-0');
@@ -275,7 +277,7 @@ describe('MultiplePrefixListSelect', () => {
275277
{ address: 'pl::supports-both', inIPv4Rule: false, inIPv6Rule: true },
276278
];
277279
const { findByTestId } = renderWithTheme(
278-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
280+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
279281
);
280282

281283
const ipv4CheckboxWrapper = await findByTestId('ipv4-checkbox-0');
@@ -298,7 +300,7 @@ describe('MultiplePrefixListSelect', () => {
298300
{ address: 'pl::supports-both', inIPv4Rule: true, inIPv6Rule: true },
299301
];
300302
const { findByTestId } = renderWithTheme(
301-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
303+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
302304
);
303305

304306
const ipv4CheckboxWrapper = await findByTestId('ipv4-checkbox-0');
@@ -325,7 +327,7 @@ describe('MultiplePrefixListSelect', () => {
325327
},
326328
];
327329
const { findByTestId } = renderWithTheme(
328-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
330+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
329331
);
330332

331333
const ipv4CheckboxWrapper = await findByTestId('ipv4-checkbox-0');
@@ -352,7 +354,7 @@ describe('MultiplePrefixListSelect', () => {
352354
},
353355
];
354356
const { findByTestId } = renderWithTheme(
355-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
357+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
356358
);
357359

358360
const ipv4CheckboxWrapper = await findByTestId('ipv4-checkbox-0');
@@ -376,14 +378,31 @@ describe('MultiplePrefixListSelect', () => {
376378
{ address: 'pl::supports-both', inIPv4Rule: true, inIPv6Rule: false },
377379
];
378380
const { findByTestId } = renderWithTheme(
379-
<MultiplePrefixListSelect onChange={onChange} pls={pls} />
381+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
380382
);
381383

382384
const ipv6Checkbox = await findByTestId('ipv6-checkbox-0');
383385
await userEvent.click(ipv6Checkbox);
384386

385-
expect(onChange).toHaveBeenCalledWith([
387+
expect(baseProps.onChange).toHaveBeenCalledWith([
386388
{ address: 'pl::supports-both', inIPv4Rule: true, inIPv6Rule: true },
387389
]);
388390
});
391+
392+
it('calls handleOpenPrefixListDrawer with correct arguments when clicking "View Details"', async () => {
393+
const pls = [
394+
{ address: 'pl::supports-both', inIPv4Rule: true, inIPv6Rule: false },
395+
];
396+
397+
const { getByText } = renderWithTheme(
398+
<MultiplePrefixListSelect {...baseProps} pls={pls} />
399+
);
400+
401+
await userEvent.click(getByText('View Details'));
402+
403+
expect(baseProps.handleOpenPrefixListDrawer).toHaveBeenCalledWith(
404+
'pl::supports-both',
405+
{ inIPv4Rule: true, inIPv6Rule: false }
406+
);
407+
});
389408
});

0 commit comments

Comments
 (0)