|
5 | 5 | * |
6 | 6 | * Copyright Oxide Computer Company |
7 | 7 | */ |
8 | | -import { useState } from 'react' |
| 8 | +import { useCallback, useState } from 'react' |
9 | 9 | import { type LoaderFunctionArgs } from 'react-router-dom' |
10 | 10 |
|
11 | 11 | import { |
@@ -122,48 +122,55 @@ export function NetworkingTab() { |
122 | 122 | }) |
123 | 123 | const canUpdateNic = instanceCan.updateNic(instance) |
124 | 124 |
|
125 | | - const makeActions = (nic: InstanceNetworkInterface): MenuAction[] => [ |
126 | | - { |
127 | | - label: 'Make primary', |
128 | | - onActivate() { |
129 | | - editNic.mutate({ |
130 | | - path: { interface: nic.name }, |
131 | | - query: instanceSelector, |
132 | | - body: { ...nic, primary: true }, |
133 | | - }) |
| 125 | + const makeActions = useCallback( |
| 126 | + (nic: InstanceNetworkInterface): MenuAction[] => [ |
| 127 | + { |
| 128 | + label: 'Make primary', |
| 129 | + onActivate() { |
| 130 | + editNic.mutate({ |
| 131 | + path: { interface: nic.name }, |
| 132 | + query: instanceSelector, |
| 133 | + body: { ...nic, primary: true }, |
| 134 | + }) |
| 135 | + }, |
| 136 | + disabled: nic.primary |
| 137 | + ? 'This network interface is already set as primary' |
| 138 | + : !canUpdateNic && ( |
| 139 | + <> |
| 140 | + The instance must be {updateNicStates} to change its primary network |
| 141 | + interface |
| 142 | + </> |
| 143 | + ), |
134 | 144 | }, |
135 | | - disabled: nic.primary |
136 | | - ? 'This network interface is already set as primary' |
137 | | - : !canUpdateNic && ( |
138 | | - <> |
139 | | - The instance must be {updateNicStates} to change its primary network interface |
140 | | - </> |
141 | | - ), |
142 | | - }, |
143 | | - { |
144 | | - label: 'Edit', |
145 | | - onActivate() { |
146 | | - setEditing(nic) |
| 145 | + { |
| 146 | + label: 'Edit', |
| 147 | + onActivate() { |
| 148 | + setEditing(nic) |
| 149 | + }, |
| 150 | + disabled: !canUpdateNic && ( |
| 151 | + <> |
| 152 | + The instance must be {updateNicStates} before editing a network interface's |
| 153 | + settings |
| 154 | + </> |
| 155 | + ), |
147 | 156 | }, |
148 | | - disabled: !canUpdateNic && ( |
149 | | - <> |
150 | | - The instance must be {updateNicStates} before editing a network interface's |
151 | | - settings |
152 | | - </> |
153 | | - ), |
154 | | - }, |
155 | | - { |
156 | | - label: 'Delete', |
157 | | - onActivate: confirmDelete({ |
158 | | - doDelete: () => |
159 | | - deleteNic.mutateAsync({ path: { interface: nic.name }, query: instanceSelector }), |
160 | | - label: nic.name, |
161 | | - }), |
162 | | - disabled: !canUpdateNic && ( |
163 | | - <>The instance must be {updateNicStates} to delete a network interface</> |
164 | | - ), |
165 | | - }, |
166 | | - ] |
| 157 | + { |
| 158 | + label: 'Delete', |
| 159 | + onActivate: confirmDelete({ |
| 160 | + doDelete: () => |
| 161 | + deleteNic.mutateAsync({ |
| 162 | + path: { interface: nic.name }, |
| 163 | + query: instanceSelector, |
| 164 | + }), |
| 165 | + label: nic.name, |
| 166 | + }), |
| 167 | + disabled: !canUpdateNic && ( |
| 168 | + <>The instance must be {updateNicStates} to delete a network interface</> |
| 169 | + ), |
| 170 | + }, |
| 171 | + ], |
| 172 | + [canUpdateNic, deleteNic, editNic, instanceSelector] |
| 173 | + ) |
167 | 174 |
|
168 | 175 | const emptyState = ( |
169 | 176 | <EmptyMessage |
|
0 commit comments