Skip to content

Commit 34b8d68

Browse files
committed
Fix issue in api deployment onboarding screen
1 parent ec4d87b commit 34b8d68

File tree

1 file changed

+56
-23
lines changed

1 file changed

+56
-23
lines changed

portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/DeploymentOnbording.jsx

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,28 @@ export default function DeploymentOnboarding(props) {
172172
isLoading: true
173173
});
174174

175+
const wsDisabled = (vhost) => vhost.wsPort === null && vhost.wsHost === null;
176+
const wssDisabled = (vhost) => vhost.wssPort === null && vhost.wssHost === null;
177+
const hasValidWebSocketPorts = (vhost) => {
178+
return !wsDisabled(vhost) || !wssDisabled(vhost);
179+
};
180+
const hasValidHosts = (environment) => {
181+
if (!environment.vhosts || environment.vhosts.length === 0) {
182+
return false;
183+
}
184+
return environment.vhosts.some((vhost) => !api.isWebSocket()
185+
|| hasValidWebSocketPorts(vhost));
186+
};
187+
const getHostValue = (vhost, isWebSocket) => {
188+
if (!isWebSocket) {
189+
return vhost.host;
190+
}
191+
if (wsDisabled(vhost) && !wssDisabled(vhost)) {
192+
return vhost.wssHost;
193+
}
194+
return vhost.wsHost;
195+
};
196+
175197
useEffect(() => {
176198
let gatewayType;
177199
if (api.apiType === 'APIPRODUCT') {
@@ -211,7 +233,7 @@ export default function DeploymentOnboarding(props) {
211233
if (e.vhosts && e.vhosts.length > 0) {
212234
return {
213235
env: e.name,
214-
vhost: api.isWebSocket() ? e.vhosts[0].wsHost : e.vhosts[0].host
236+
vhost: getHostValue(e.vhosts[0], api.isWebSocket()),
215237
};
216238
} else {
217239
return undefined;
@@ -232,7 +254,7 @@ export default function DeploymentOnboarding(props) {
232254
if (e.vhosts && e.vhosts.length > 0) {
233255
return {
234256
env: e.name,
235-
vhost: api.isWebSocket() ? e.vhosts[0].wsHost : e.vhosts[0].host
257+
vhost: getHostValue(e.vhosts[0], api.isWebSocket()),
236258
};
237259
} else {
238260
return undefined;
@@ -434,6 +456,7 @@ export default function DeploymentOnboarding(props) {
434456
value={row.name}
435457
checked={selectedEnvironment.includes(row.name)}
436458
onChange={handleChange}
459+
disabled={!hasValidHosts(row)}
437460
color='primary'
438461
icon={<RadioButtonUncheckedIcon />}
439462
checkedIcon=
@@ -524,18 +547,21 @@ export default function DeploymentOnboarding(props) {
524547
},
525548
}}
526549
>
527-
{row.vhosts.map(
528-
(vhost) => (
529-
<MenuItem value =
530-
{api.isWebSocket()
531-
? vhost.wsHost
532-
: vhost.host}>
533-
{api.isWebSocket()
534-
? vhost.wsHost
535-
: vhost.host}
550+
{row.vhosts.filter((vhost
551+
) => !api.isWebSocket()
552+
|| hasValidWebSocketPorts(vhost))
553+
.map((vhost) => {const
554+
hostValue = getHostValue(vhost,
555+
api.isWebSocket());
556+
return (
557+
<MenuItem
558+
key={hostValue}
559+
value={hostValue}
560+
>
561+
{hostValue}
536562
</MenuItem>
537-
),
538-
)}
563+
);
564+
})}
539565
</TextField>
540566
</Tooltip>
541567
</Grid>
@@ -655,7 +681,8 @@ export default function DeploymentOnboarding(props) {
655681
value={row.name}
656682
checked=
657683
{selectedExternalGateway.includes(row.name)}
658-
disabled={isDeployRestricted()}
684+
disabled={isDeployRestricted()
685+
|| !hasValidHosts(row)}
659686
onChange={handleChange}
660687
color='primary'
661688
icon={<RadioButtonUncheckedIcon />}
@@ -718,15 +745,21 @@ export default function DeploymentOnboarding(props) {
718745
helperText={getVhostHelperText(row.name,
719746
selectedVhostDeploy, true)}
720747
>
721-
{row.vhosts?.map(
722-
(vhost) => (
723-
<MenuItem value={api.isWebSocket()
724-
? vhost.wsHost : vhost.host}>
725-
{api.isWebSocket()
726-
? vhost.wsHost : vhost.host}
727-
</MenuItem>
728-
),
729-
)}
748+
{row.vhosts
749+
.filter((vhost) => !api.isWebSocket()
750+
|| hasValidWebSocketPorts(vhost))
751+
.map((vhost) => {
752+
const hostValue = getHostValue(vhost,
753+
api.isWebSocket());
754+
return (
755+
<MenuItem
756+
key={hostValue}
757+
value={hostValue}
758+
>
759+
{hostValue}
760+
</MenuItem>
761+
);
762+
})}
730763
</TextField>
731764
</Tooltip>
732765
</Grid>

0 commit comments

Comments
 (0)