({
host,
workspace,
agent,
template,
sharedPorts,
listeningPorts,
portSharingControlsEnabled,
refetchSharedPorts,
})
| 140 | } |
| 141 | |
| 142 | export const PortForwardPopoverView: FC<PortForwardPopoverViewProps> = ({ |
| 143 | host, |
| 144 | workspace, |
| 145 | agent, |
| 146 | template, |
| 147 | sharedPorts, |
| 148 | listeningPorts, |
| 149 | portSharingControlsEnabled, |
| 150 | refetchSharedPorts, |
| 151 | }) => { |
| 152 | const theme = useTheme(); |
| 153 | const [listeningPortProtocol, setListeningPortProtocol] = useState( |
| 154 | getWorkspaceListeningPortsProtocol(workspace.id), |
| 155 | ); |
| 156 | |
| 157 | const upsertSharedPortMutation = useMutation({ |
| 158 | ...upsertWorkspacePortShare(workspace.id), |
| 159 | onSuccess: refetchSharedPorts, |
| 160 | }); |
| 161 | |
| 162 | const deleteSharedPortMutation = useMutation({ |
| 163 | ...deleteWorkspacePortShare(workspace.id), |
| 164 | onSuccess: refetchSharedPorts, |
| 165 | }); |
| 166 | |
| 167 | const { |
| 168 | mutateAsync: upsertWorkspacePortShareForm, |
| 169 | isPending: isSubmitting, |
| 170 | error: submitError, |
| 171 | } = useMutation({ |
| 172 | ...upsertWorkspacePortShare(workspace.id), |
| 173 | onSuccess: refetchSharedPorts, |
| 174 | }); |
| 175 | |
| 176 | const form = useFormik({ |
| 177 | initialValues: { |
| 178 | agent_name: agent.name, |
| 179 | port: "", |
| 180 | protocol: "http", |
| 181 | share_level: "authenticated", |
| 182 | }, |
| 183 | validationSchema: openPortSchema(), |
| 184 | onSubmit: async (values, { resetForm }) => { |
| 185 | resetForm(); |
| 186 | await upsertWorkspacePortShareForm({ |
| 187 | agent_name: values.agent_name, |
| 188 | port: Number(values.port), |
| 189 | share_level: values.share_level as WorkspaceAgentPortShareLevel, |
| 190 | protocol: values.protocol as WorkspaceAgentPortShareProtocol, |
| 191 | }); |
| 192 | }, |
| 193 | }); |
| 194 | const getFieldHelpers = getFormHelpers(form, submitError); |
| 195 | |
| 196 | // filter out shared ports that are not from this agent |
| 197 | const filteredSharedPorts = sharedPorts.filter( |
| 198 | (port) => port.agent_name === agent.name, |
| 199 | ); |
nothing calls this directly
no test coverage detected