Skip to content

Commit 4eacb3d

Browse files
authored
tooling: Fix HMR on firewall rules form (#2338)
move firewall rules form utils to another file to fix HMR
1 parent f278a74 commit 4eacb3d

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

app/forms/firewall-rules-create.tsx

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
type VpcFirewallRule,
2222
type VpcFirewallRuleHostFilter,
2323
type VpcFirewallRuleTarget,
24-
type VpcFirewallRuleUpdate,
2524
} from '@oxide/api'
2625

2726
import { CheckboxField } from '~/components/form/fields/CheckboxField'
@@ -44,35 +43,7 @@ import { KEYS } from '~/ui/util/keys'
4443
import { links } from '~/util/links'
4544
import { pb } from '~/util/path-builder'
4645

47-
export type FirewallRuleValues = {
48-
enabled: boolean
49-
priority: number
50-
name: string
51-
description: string
52-
action: VpcFirewallRule['action']
53-
direction: VpcFirewallRule['direction']
54-
55-
protocols: NonNullable<VpcFirewallRule['filters']['protocols']>
56-
57-
ports: NonNullable<VpcFirewallRule['filters']['ports']>
58-
hosts: NonNullable<VpcFirewallRule['filters']['hosts']>
59-
targets: VpcFirewallRuleTarget[]
60-
}
61-
62-
export const valuesToRuleUpdate = (values: FirewallRuleValues): VpcFirewallRuleUpdate => ({
63-
name: values.name,
64-
status: values.enabled ? 'enabled' : 'disabled',
65-
action: values.action,
66-
description: values.description,
67-
direction: values.direction,
68-
filters: {
69-
hosts: values.hosts,
70-
ports: values.ports,
71-
protocols: values.protocols,
72-
},
73-
priority: values.priority,
74-
targets: values.targets,
75-
})
46+
import { valuesToRuleUpdate, type FirewallRuleValues } from './firewall-rules-util'
7647

7748
/** convert in the opposite direction for when we're creating from existing rule */
7849
const ruleToValues = (rule: VpcFirewallRule): FirewallRuleValues => ({

app/forms/firewall-rules-edit.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ import {
2626
import { invariant } from '~/util/invariant'
2727
import { pb } from '~/util/path-builder'
2828

29-
import {
30-
CommonFields,
31-
valuesToRuleUpdate,
32-
type FirewallRuleValues,
33-
} from './firewall-rules-create'
29+
import { CommonFields } from './firewall-rules-create'
30+
import { valuesToRuleUpdate, type FirewallRuleValues } from './firewall-rules-util'
3431

3532
EditFirewallRuleForm.loader = async ({ params }: LoaderFunctionArgs) => {
3633
const { project, vpc, rule } = getFirewallRuleSelector(params)

app/forms/firewall-rules-util.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
5+
*
6+
* Copyright Oxide Computer Company
7+
*/
8+
import type { VpcFirewallRule, VpcFirewallRuleTarget, VpcFirewallRuleUpdate } from '~/api'
9+
10+
export type FirewallRuleValues = {
11+
enabled: boolean
12+
priority: number
13+
name: string
14+
description: string
15+
action: VpcFirewallRule['action']
16+
direction: VpcFirewallRule['direction']
17+
18+
protocols: NonNullable<VpcFirewallRule['filters']['protocols']>
19+
20+
ports: NonNullable<VpcFirewallRule['filters']['ports']>
21+
hosts: NonNullable<VpcFirewallRule['filters']['hosts']>
22+
targets: VpcFirewallRuleTarget[]
23+
}
24+
25+
export const valuesToRuleUpdate = (values: FirewallRuleValues): VpcFirewallRuleUpdate => ({
26+
name: values.name,
27+
status: values.enabled ? 'enabled' : 'disabled',
28+
action: values.action,
29+
description: values.description,
30+
direction: values.direction,
31+
filters: {
32+
hosts: values.hosts,
33+
ports: values.ports,
34+
protocols: values.protocols,
35+
},
36+
priority: values.priority,
37+
targets: values.targets,
38+
})

0 commit comments

Comments
 (0)