Skip to content

Commit f9495c3

Browse files
committed
configurable numInCell on ListPlusCell, use for firewall rule filters
1 parent 22bbad5 commit f9495c3

File tree

5 files changed

+69
-23
lines changed

5 files changed

+69
-23
lines changed

app/components/ListPlusCell.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,30 @@ import { Tooltip } from '~/ui/lib/Tooltip'
1313
type ListPlusCellProps = {
1414
tooltipTitle: string
1515
children: React.ReactNode
16+
/** The number of items to show in the cell vs. in the popup */
17+
numInCell?: number
1618
}
1719

1820
/**
1921
* Gives a count with a tooltip that expands to show details when the user hovers over it
2022
*/
21-
export const ListPlusCell = ({ tooltipTitle, children }: ListPlusCellProps) => {
22-
const [first, ...rest] = React.Children.toArray(children)
23+
export const ListPlusCell = ({
24+
tooltipTitle,
25+
children,
26+
numInCell = 1,
27+
}: ListPlusCellProps) => {
28+
const array = React.Children.toArray(children)
29+
const inCell = array.slice(0, numInCell)
30+
const rest = array.slice(numInCell)
2331
const content = (
2432
<div>
2533
<div className="mb-2">{tooltipTitle}</div>
26-
{...rest}
34+
<div className="flex flex-col items-start gap-2">{...rest}</div>
2735
</div>
2836
)
2937
return (
3038
<div className="flex items-baseline gap-2">
31-
{first}
39+
{inCell}
3240
{rest.length > 0 && (
3341
<Tooltip content={content} placement="bottom">
3442
<div className="text-mono-sm">+{rest.length}</div>

app/pages/project/vpcs/VpcPage/tabs/VpcFirewallRulesTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const VpcFirewallRulesTab = () => {
151151
/>
152152
)}
153153
</div>
154-
{rules.length > 0 ? <Table table={table} rowHeight="large" /> : emptyState}
154+
{rules.length > 0 ? <Table table={table} /> : emptyState}
155155
</>
156156
)
157157
}

app/table/cells/FirewallFilterCell.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@
77
*/
88
import type { VpcFirewallRuleFilter } from '@oxide/api'
99

10+
import { ListPlusCell } from '~/components/ListPlusCell'
1011
import { Badge } from '~/ui/lib/Badge'
1112

1213
import { TypeValueCell } from './TypeValueCell'
1314

14-
export const FirewallFilterCell = ({ hosts, ports, protocols }: VpcFirewallRuleFilter) => (
15-
<div className="flex flex-col gap-1">
16-
<div className="flex flex-wrap gap-1">
17-
{hosts?.map((tv, i) => <TypeValueCell key={`${tv}-${i}`} {...tv} />)}
15+
export const FirewallFilterCell = ({ hosts, ports, protocols }: VpcFirewallRuleFilter) => {
16+
const children = [
17+
...(hosts || []).map((tv, i) => <TypeValueCell key={`${tv}-${i}`} {...tv} />),
18+
...(protocols || []).map((p, i) => <Badge key={`${p}-${i}`}>{p}</Badge>),
19+
...(ports || []).map((p, i) => (
20+
<TypeValueCell key={`port-${p}-${i}`} type="Port" value={p} />
21+
)),
22+
]
23+
return (
24+
<div className="flex flex-col gap-1">
25+
<ListPlusCell numInCell={2} tooltipTitle="Other filters">
26+
{children}
27+
</ListPlusCell>
1828
</div>
19-
<div className="flex gap-1">
20-
{protocols?.map((p, i) => <Badge key={`${p}-${i}`}>{p}</Badge>)}
21-
{ports?.map((p, i) => (
22-
<Badge key={`${p}-${i}`} variant="solid">
23-
{p}
24-
</Badge>
25-
))}
26-
</div>
27-
</div>
28-
)
29+
)
30+
}

mock-api/msw/db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ const initDb = {
286286
snapshots: [...mock.snapshots],
287287
sshKeys: [...mock.sshKeys],
288288
users: [...mock.users],
289-
vpcFirewallRules: [...mock.defaultFirewallRules],
290-
vpcs: [mock.vpc],
289+
vpcFirewallRules: [...mock.firewallRules],
290+
vpcs: [...mock.vpcs],
291291
vpcSubnets: [mock.vpcSubnet],
292292
}
293293

mock-api/vpc.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import type { Vpc, VpcFirewallRule, VpcSubnet } from '@oxide/api'
1010

1111
import type { Json } from './json-type'
12-
import { project } from './project'
12+
import { project, project2 } from './project'
1313

1414
const time_created = new Date(2021, 0, 1).toISOString()
1515
const time_modified = new Date(2021, 0, 2).toISOString()
@@ -28,6 +28,20 @@ export const vpc: Json<Vpc> = {
2828
time_modified,
2929
}
3030

31+
export const vpc2: Json<Vpc> = {
32+
id: 'e54078df-fe72-4673-b36c-a362e3b4e38b',
33+
name: 'mock-vpc-2',
34+
description: 'a fake vpc',
35+
dns_name: 'mock-vpc-2',
36+
project_id: project2.id,
37+
system_router_id: systemRouterId,
38+
ipv6_prefix: 'fdf6:1818:b6e2::/48',
39+
time_created,
40+
time_modified,
41+
}
42+
43+
export const vpcs: Json<Vpc[]> = [vpc, vpc2]
44+
3145
export const vpcSubnet: Json<VpcSubnet> = {
3246
// this is supposed to be flattened into the top level. will fix in API
3347
id: 'd12bf934-d2bf-40e9-8596-bb42a7793749',
@@ -49,7 +63,7 @@ export const vpcSubnet2: Json<VpcSubnet> = {
4963
ipv4_block: '10.1.1.2/24',
5064
}
5165

52-
export const defaultFirewallRules: Json<VpcFirewallRule[]> = [
66+
export const firewallRules: Json<VpcFirewallRule[]> = [
5367
{
5468
id: 'b74aeea8-1201-4efd-b6ec-011f10a0b176',
5569
name: 'allow-internal-inbound',
@@ -117,4 +131,26 @@ export const defaultFirewallRules: Json<VpcFirewallRule[]> = [
117131
time_modified,
118132
vpc_id: vpc.id,
119133
},
134+
{
135+
id: '097c849e-68c8-43f7-9ceb-b1855c51f178',
136+
name: 'lots-of-filters',
137+
status: 'enabled',
138+
direction: 'inbound',
139+
targets: [{ type: 'vpc', value: 'default' }],
140+
description: 'we just want to test with lots of filters',
141+
filters: {
142+
ports: ['3389', '45-89'],
143+
protocols: ['TCP'],
144+
hosts: [
145+
{ type: 'instance', value: 'hello-friend' },
146+
{ type: 'subnet', value: 'my-subnet' },
147+
{ type: 'ip', value: '148.38.89.5' },
148+
],
149+
},
150+
action: 'allow',
151+
priority: 65534,
152+
time_created,
153+
time_modified,
154+
vpc_id: vpc2.id,
155+
},
120156
]

0 commit comments

Comments
 (0)