From 55402146d71326279ecbbff34e9c3596ada6f0df Mon Sep 17 00:00:00 2001 From: Dineth Date: Wed, 15 Oct 2025 10:47:13 +0530 Subject: [PATCH 1/5] Adjust vhost based on whether wss/ws is disabled --- .../Details/AsyncApiConsole/AsyncApiUI.jsx | 49 ++++-- .../components/Apis/Details/Environments.jsx | 33 ++-- .../Details/Environments/Environments.jsx | 146 ++++++++++++------ 3 files changed, 149 insertions(+), 79 deletions(-) diff --git a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx index 07c32a6323a..36b918a62dc 100644 --- a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx +++ b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx @@ -54,6 +54,12 @@ const Root = styled('div')({ padding: '2px 2px 2px 10px', borderRadius: '4px', color: '#3b4151', + '&.Mui-disabled': { + backgroundColor: '#f5f5f5', + color: '#999', + border: '2px solid #ddd', + cursor: 'not-allowed', + }, } }); @@ -69,11 +75,21 @@ export default function AsyncApiUI(props) { const { api } = useContext(ApiContext); const isAdvertised = api.advertiseInfo && api.advertiseInfo.advertised; + const getPreferredEndpoint = (URLsObj, apiType) => { + if (!URLsObj) return ''; + if (apiType === CONSTANTS.API_TYPES.WS) { + // prefer ws, but if ws does not exist fall back to wss + if (URLsObj.ws) return URLsObj.ws; + if (URLsObj.wss) return URLsObj.wss; + return ''; + } + // for non-WS APIs prefer http, but if http does not exist fall back to https + if (URLsObj.http) return URLsObj.http; + if (URLsObj.https) return URLsObj.https; + return ''; + }; let initialEndpoint; - initialEndpoint = URLs && (URLs.http || URLs.https); - if (api.type === CONSTANTS.API_TYPES.WS) { - initialEndpoint = URLs && (URLs.ws || URLs.wss); - } + initialEndpoint = getPreferredEndpoint(URLs, api.type); let expandable = true; if (!URLs || (!URLs.http && !URLs.https)) { @@ -84,11 +100,8 @@ export default function AsyncApiUI(props) { const [endPoint, setEndpoint] = useState(initialEndpoint); useEffect(() => { - let newInitialEndpoint = URLs && URLs.http; - if (api.type === CONSTANTS.API_TYPES.WS) { - newInitialEndpoint = URLs && URLs.ws; - } - setEndpoint(newInitialEndpoint); + const newInitialEndpoint = getPreferredEndpoint(URLs, api.type); + setEndpoint(newInitialEndpoint || ''); }, [URLs, api.type]); useEffect(() => { @@ -229,13 +242,21 @@ export default function AsyncApiUI(props) { id="api-endpoint-select" value={endPoint} displayEmpty + disabled={Object.keys(URLs).length === 0 || !Object.values(URLs).some((url) => url)} onChange={handleServerChange} > - {Object.entries(URLs).map(([key, value]) => { - if (value) { - return {value}; - } - })} + {Object.keys(URLs).length === 0 || !Object.values(URLs).some((url) => url) ? ( + + No servers available + + ) : ( + Object.entries(URLs).map(([key, value]) => { + if (value) { + return {value}; + } + return null; + }) + )} {api.type === CONSTANTS.API_TYPES.WEBSUB && allTopics.list.map((topic, index) => ( diff --git a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx index 11eae01a3cb..679f28f2233 100644 --- a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx +++ b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx @@ -118,6 +118,17 @@ function Environments(props) { const intl = useIntl(); + const pickFirstEnabledUrl = (urls) => { + if (!urls || typeof urls !== 'object') { + return ''; + } + // Get all truthy values and return the first one, or '' if none are found. + const firstUrl = Object.values(urls).find( + (val) => typeof val === 'string' && val.trim() !== '', + ); + return firstUrl || ''; + }; + const onCopy = () => { setUrlCopied(true); const caller = function () { @@ -128,11 +139,8 @@ function Environments(props) { const getDefaultVersionUrl = () => { const { defaultVersionURLs } = selectedEndpoint; - if (defaultVersionURLs - && (defaultVersionURLs.https - || defaultVersionURLs.http - || defaultVersionURLs.ws - || defaultVersionURLs.wss)) { + const firstEnabledDefaultUrl = pickFirstEnabledUrl(defaultVersionURLs); + if (firstEnabledDefaultUrl) { return ( <> {` @@ -140,7 +148,7 @@ function Environments(props) { id: 'Apis.Details.Environments.default.url', defaultMessage: '( Default Version ) ', })} - ${(defaultVersionURLs.https || defaultVersionURLs.http || defaultVersionURLs.ws || defaultVersionURLs.wss)}`} + ${(firstEnabledDefaultUrl)}`} { - navigator.clipboard.writeText(defaultVersionURLs.https - || defaultVersionURLs.http - || defaultVersionURLs.ws - || defaultVersionURLs.wss).then(onCopy('urlCopied')); + navigator.clipboard.writeText(firstEnabledDefaultUrl).then(onCopy('urlCopied')); }} > file_copy @@ -243,10 +248,7 @@ function Environments(props) { @@ -303,8 +305,7 @@ function Environments(props) { diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx index 7d5cfa75fc6..d3075a4a289 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx @@ -547,6 +547,30 @@ export default function Environments() { }; const isCreateOrPublishRestricted = () => isRestricted(getCreateOrPublishScopes(), api); + const wsDisabled = (vhost) => vhost.wsPort === null && vhost.wsHost === null; + const wssDisabled = (vhost) => vhost.wssPort === null && vhost.wssHost === null; + + const hasValidWebSocketPorts = (vhost) => { + return !wsDisabled(vhost) || !wssDisabled(vhost); + }; + + const hasValidHosts = (environment) => { + if (!environment.vhosts || environment.vhosts.length === 0) { + return false; + } + return environment.vhosts.some((vhost) => !api.isWebSocket() + || hasValidWebSocketPorts(vhost)); + }; + + const getHostValue = (vhost, isWebSocket) => { + if (!isWebSocket) { + return vhost.host; + } + if (wsDisabled(vhost) && !wssDisabled(vhost)) { + return vhost.wssHost; + } + return vhost.wsHost; + }; useEffect(() => { if (settings) { let gatewayType; @@ -584,7 +608,7 @@ export default function Environments() { if (e.vhosts && e.vhosts.length > 0) { return { env: e.name, - vhost: api.isWebSocket() ? e.vhosts[0].wsHost : e.vhosts[0].host + vhost: getHostValue(e.vhosts[0], api.isWebSocket()) }; } else { return undefined; @@ -607,7 +631,7 @@ export default function Environments() { if (e.vhosts && e.vhosts.length > 0) { return { env: e.name, - vhost: api.isWebSocket() ? e.vhosts[0].wsHost : e.vhosts[0].host + vhost: getHostValue(e.vhosts[0], api.isWebSocket()) }; } else { return undefined; @@ -768,6 +792,12 @@ export default function Environments() { }; const handleChange = (event) => { + // Check if the environment has valid hosts before allowing selection + const environment = settings.environment.find((env) => env.name === event.target.value); + if (event.target.checked && environment && !hasValidHosts(environment)) { + return; // Prevent selection if no valid hosts + } + if (event.target.checked) { setSelectedEnvironment([...SelectedEnvironment, event.target.value]); } else { @@ -2107,8 +2137,13 @@ export default function Environments() { } if (type === 'WS') { - endpoints.primary = 'ws://' + vhost.wsHost + ':' + vhost.wsPort; - endpoints.secondary = 'wss://' + vhost.wssHost + ':' + vhost.wssPort; + if (!wsDisabled(vhost)) { + endpoints.primary = 'ws://' + vhost.wsHost + ':' + vhost.wsPort; + } + if (!wssDisabled(vhost)) { + endpoints.secondary = + 'wss://' + vhost.wssHost + ':' + vhost.wssPort; + } endpoints.combined = endpoints.secondary + ' ' + endpoints.primary; return endpoints; } @@ -2165,7 +2200,8 @@ export default function Environments() { style={{ width: '50%' }} disabled={api.isRevision || isCreateOrPublishRestricted() || (settings && settings.portalConfigurationOnlyModeEnabled) || - !allRevisions || allRevisions.length === 0} + !allRevisions || allRevisions.length === 0 + || !hasValidHosts(row)} > {allRevisions && allRevisions.length !== 0 && allRevisions.map((number) => ( {number.displayName} @@ -2278,7 +2314,8 @@ export default function Environments() { style={{ width: '50%' }} disabled={api.isRevision || isCreateOrPublishRestricted() || (settings && settings.portalConfigurationOnlyModeEnabled) || - !filteredRevisions || filteredRevisions.length === 0} + !filteredRevisions || filteredRevisions.length === 0 + || !hasValidHosts(row)} > {filteredRevisions && filteredRevisions.length !== 0 && filteredRevisions.map((number) => ( {number.displayName} @@ -2510,8 +2547,11 @@ export default function Environments() { const gateways = internalGateways.length > 0 ? internalGateways: externalGateways; if (api.isWebSocket() ) { vhost = gateways.find((e) => e.name === env).vhosts.find( - (v) => v.wsHost === selected.vhost, + (v) => v.wsHost === selected.vhost || (v.wsHost === null && v.wssHost === selected.vhost), ); + if (!hasValidWebSocketPorts(vhost)) { + return 'No valid hosts available for this environment'; + } } else { vhost = gateways.find((e) => e.name === env).vhosts.find( (v) => v.host === selected.vhost, @@ -2866,6 +2906,7 @@ export default function Environments() { checked={ SelectedEnvironment.includes(row.name)} onChange={handleChange} + disabled={!hasValidHosts(row)} color='primary' icon={} checkedIcon={< @@ -2942,6 +2983,7 @@ export default function Environments() { value={selectedVhostDeploy.find( (v) => v.env === row.name, ).vhost} + disabled={!hasValidHosts(row)} onChange={handleVhostDeploySelect} margin='dense' variant='outlined' @@ -2949,15 +2991,18 @@ export default function Environments() { helperText={getVhostHelperText(row.name, selectedVhostDeploy, true)} > - {row.vhosts.map( - (vhost) => ( - - {api.isWebSocket() - ? vhost.wsHost : vhost.host} - - ), - )} + {row.vhosts + .filter((vhost) => !api.isWebSocket() + || hasValidWebSocketPorts(vhost)) + .map((vhost) => { + const hostValue = getHostValue(vhost, + api.isWebSocket()); + return ( + + {hostValue} + + ); + })} @@ -3126,10 +3171,10 @@ export default function Environments() { > {row.vhosts?.map( (vhost) => ( - - {api.isWebSocket() - ? vhost.wsHost : vhost.host} + + {getHostValue( + vhost,api.isWebSocket())} ), )} @@ -3511,14 +3556,15 @@ export default function Environments() { <> - - {getVhostHelperText(row.name, - selectedVhosts)} - - - )} + title={!hasValidHosts(row) + ? 'No valid hosts available for this environment' : ( + <> + + {getVhostHelperText(row.name, + selectedVhosts)} + + + )} placement='bottom' > )} @@ -3545,19 +3591,20 @@ export default function Environments() { fullWidth disabled={ api.isRevision - || (settings - && settings.portalConfigurationOnlyModeEnabled) - || !allRevisions || allRevisions.length === 0 + || (settings + // eslint-disable-next-line max-len + && settings.portalConfigurationOnlyModeEnabled) + || !allRevisions || allRevisions.length === 0 + || !hasValidHosts(row) } helperText={getVhostHelperText(row.name, selectedVhosts, true, 100)} > {row.vhosts.map( (vhost) => ( - - {api.isWebSocket() - ? vhost.wsHost : vhost.host} + + {getHostValue(vhost, api.isWebSocket())} ), )} @@ -3735,14 +3782,15 @@ export default function Environments() { <> - - {getVhostHelperText(row.name, - selectedVhosts)} - - - )} + title={!hasValidHosts(row) + ? 'No valid hosts available for this environment' : ( + <> + + {getVhostHelperText(row.name, + selectedVhosts)} + + + )} placement='bottom' > {row.vhosts.map( (vhost) => ( - - {api.isWebSocket() - ? vhost.wsHost : vhost.host} + + {getHostValue(vhost, api.isWebSocket())} ), )} From fc4c872d47a3fae4b098d654d7084297333cd88d Mon Sep 17 00:00:00 2001 From: Dineth Date: Wed, 15 Oct 2025 12:39:47 +0530 Subject: [PATCH 2/5] Fix sonarcloud recommendations --- .../Details/AsyncApiConsole/AsyncApiUI.jsx | 4 +- .../components/Apis/Details/Environments.jsx | 27 ++++++++--- .../Details/Environments/Environments.jsx | 45 ++++++++++++------- 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx index 36b918a62dc..e6914da24ac 100644 --- a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx +++ b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx @@ -242,10 +242,10 @@ export default function AsyncApiUI(props) { id="api-endpoint-select" value={endPoint} displayEmpty - disabled={Object.keys(URLs).length === 0 || !Object.values(URLs).some((url) => url)} + disabled={Object.keys(URLs).length === 0 || !Object.values(URLs).some(Boolean)} onChange={handleServerChange} > - {Object.keys(URLs).length === 0 || !Object.values(URLs).some((url) => url) ? ( + {Object.keys(URLs).length === 0 || !Object.values(URLs).some(Boolean) ? ( No servers available diff --git a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx index 679f28f2233..32cc7a7544f 100644 --- a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx +++ b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx @@ -169,7 +169,7 @@ function Environments(props) { aria-label='Copy the Default Version URL to clipboard' size='large' onClick={() => { - navigator.clipboard.writeText(firstEnabledDefaultUrl).then(onCopy('urlCopied')); + navigator.clipboard.writeText(firstEnabledDefaultUrl).then(onCopy); }} > file_copy @@ -276,7 +276,7 @@ function Environments(props) { navigator.clipboard.writeText(selectedEndpoint.URLs.https || selectedEndpoint.URLs.http || selectedEndpoint.URLs.wss - || selectedEndpoint.URLs.ws).then(onCopy('urlCopied')); + || selectedEndpoint.URLs.ws).then(onCopy); }} > file_copy @@ -329,7 +329,7 @@ function Environments(props) { size='large' onClick={() => { navigator.clipboard.writeText(selectedEndpoint.URLs.wss - || selectedEndpoint.URLs.ws).then(onCopy('urlCopied')); + || selectedEndpoint.URLs.ws).then(onCopy); }} > file_copy @@ -406,7 +406,7 @@ function Environments(props) { navigator.clipboard.writeText( advertiseInfo.apiExternalProductionEndpoint, ) - .then(onCopy('urlCopied')); + .then(onCopy); }} > file_copy @@ -459,7 +459,7 @@ function Environments(props) { navigator.clipboard.writeText( advertiseInfo.apiExternalSandboxEndpoint, ) - .then(onCopy('urlCopied')); + .then(onCopy); }} > file_copy @@ -501,6 +501,23 @@ function Environments(props) { Environments.propTypes = { classes: PropTypes.shape({}).isRequired, intl: PropTypes.shape({}).isRequired, + selectedEndpoint: PropTypes.shape({ + environmentName: PropTypes.string, + environmentDisplayName: PropTypes.string, + environmentType: PropTypes.string, + URLs: PropTypes.shape({ + http: PropTypes.string, + https: PropTypes.string, + ws: PropTypes.string, + wss: PropTypes.string, + }).isRequired, + defaultVersionURLs: PropTypes.shape({ + http: PropTypes.string, + https: PropTypes.string, + ws: PropTypes.string, + wss: PropTypes.string, + }), + }).isRequired, }; export default Environments; diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx index d3075a4a289..d769a6e2848 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx @@ -2547,7 +2547,7 @@ export default function Environments() { const gateways = internalGateways.length > 0 ? internalGateways: externalGateways; if (api.isWebSocket() ) { vhost = gateways.find((e) => e.name === env).vhosts.find( - (v) => v.wsHost === selected.vhost || (v.wsHost === null && v.wssHost === selected.vhost), + (v) => v.wsHost === selected.vhost || v.wssHost === selected.vhost, ); if (!hasValidWebSocketPorts(vhost)) { return 'No valid hosts available for this environment'; @@ -2566,8 +2566,10 @@ export default function Environments() { } const gatewayUrls = getGatewayAccessUrl(vhost, api.isWebSocket() ? 'WS' : 'HTTP'); if (shorten) { - const helperText = getGatewayAccessUrl(vhost, api.isWebSocket() ? 'WS' : 'HTTP').secondary; - return helperText.length > maxtLen ? helperText.substring(0, maxtLen) + '...' : helperText; + const wsOrHttp = api.isWebSocket() ? 'WS' : 'HTTP'; + const endpoints = getGatewayAccessUrl(vhost, wsOrHttp); + const preferred = endpoints.secondary || endpoints.primary; // prefer wss/https; fallback to ws/http + return preferred.length > maxtLen ? preferred.substring(0, maxtLen) + '...' : preferred; } return gatewayUrls.combined; } @@ -2998,7 +3000,9 @@ export default function Environments() { const hostValue = getHostValue(vhost, api.isWebSocket()); return ( - + {hostValue} ); @@ -3171,8 +3175,11 @@ export default function Environments() { > {row.vhosts?.map( (vhost) => ( - + {getHostValue( vhost,api.isWebSocket())} @@ -3228,7 +3235,7 @@ export default function Environments() { - {allRevisions && allRevisions.length !== 0 + {allRevisions && allRevisions.length !== 0 && !api.isRevision && (settings && !settings.portalConfigurationOnlyModeEnabled) && ( <> {getVhostHelperText(row.name, selectedVhosts)} - )} + ) : 'No valid hosts available for this environment'} placement='bottom' > {row.vhosts.map( (vhost) => ( - + {getHostValue(vhost, api.isWebSocket())} ), @@ -3782,15 +3791,15 @@ export default function Environments() { <> {getVhostHelperText(row.name, selectedVhosts)} - )} + ) : 'No valid hosts available for this environment'} placement='bottom' > {row.vhosts.map( (vhost) => ( - + {getHostValue(vhost, api.isWebSocket())} ), From c7feddfce77380175b9deba8c9666726aa1884d0 Mon Sep 17 00:00:00 2001 From: Dineth Date: Wed, 15 Oct 2025 14:11:35 +0530 Subject: [PATCH 3/5] Add comment --- .../app/components/Apis/Details/Environments/Environments.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx index d769a6e2848..361fb0475b8 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/Environments.jsx @@ -562,6 +562,7 @@ export default function Environments() { || hasValidWebSocketPorts(vhost)); }; + // this function returns the appropriate host value depending on the api type const getHostValue = (vhost, isWebSocket) => { if (!isWebSocket) { return vhost.host; From 8e3f6bfec88a1af6ee56cb5dc4f7ba882506aa9e Mon Sep 17 00:00:00 2001 From: Dineth Date: Mon, 27 Oct 2025 14:10:35 +0530 Subject: [PATCH 4/5] Clipboard fix --- .../src/app/components/Apis/Details/Environments.jsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx index 32cc7a7544f..e210722a7fd 100644 --- a/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx +++ b/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/Environments.jsx @@ -273,10 +273,7 @@ function Environments(props) { aria-label='Copy the API URL to clipboard' size='large' onClick={() => { - navigator.clipboard.writeText(selectedEndpoint.URLs.https - || selectedEndpoint.URLs.http - || selectedEndpoint.URLs.wss - || selectedEndpoint.URLs.ws).then(onCopy); + navigator.clipboard.writeText(pickFirstEnabledUrl(selectedEndpoint.URLs)).then(onCopy); }} > file_copy @@ -328,8 +325,9 @@ function Environments(props) { aria-label='Copy the API URL to clipboard' size='large' onClick={() => { - navigator.clipboard.writeText(selectedEndpoint.URLs.wss - || selectedEndpoint.URLs.ws).then(onCopy); + navigator.clipboard.writeText(pickFirstEnabledUrl( + selectedEndpoint.URLs, + )).then(onCopy); }} > file_copy From 1f223edfd955ff8bf1a8d2725e7ebde9b8223cda Mon Sep 17 00:00:00 2001 From: Dineth Date: Wed, 29 Oct 2025 10:14:59 +0530 Subject: [PATCH 5/5] Fix issue in api deployment onboarding screen --- .../Environments/DeploymentOnbording.jsx | 79 +++++++++++++------ 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/DeploymentOnbording.jsx b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/DeploymentOnbording.jsx index 50e58485ece..94b5ee116b8 100644 --- a/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/DeploymentOnbording.jsx +++ b/portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Environments/DeploymentOnbording.jsx @@ -172,6 +172,28 @@ export default function DeploymentOnboarding(props) { isLoading: true }); + const wsDisabled = (vhost) => vhost.wsPort === null && vhost.wsHost === null; + const wssDisabled = (vhost) => vhost.wssPort === null && vhost.wssHost === null; + const hasValidWebSocketPorts = (vhost) => { + return !wsDisabled(vhost) || !wssDisabled(vhost); + }; + const hasValidHosts = (environment) => { + if (!environment.vhosts || environment.vhosts.length === 0) { + return false; + } + return environment.vhosts.some((vhost) => !api.isWebSocket() + || hasValidWebSocketPorts(vhost)); + }; + const getHostValue = (vhost, isWebSocket) => { + if (!isWebSocket) { + return vhost.host; + } + if (wsDisabled(vhost) && !wssDisabled(vhost)) { + return vhost.wssHost; + } + return vhost.wsHost; + }; + useEffect(() => { let gatewayType; if (api.apiType === 'APIPRODUCT') { @@ -211,7 +233,7 @@ export default function DeploymentOnboarding(props) { if (e.vhosts && e.vhosts.length > 0) { return { env: e.name, - vhost: api.isWebSocket() ? e.vhosts[0].wsHost : e.vhosts[0].host + vhost: getHostValue(e.vhosts[0], api.isWebSocket()), }; } else { return undefined; @@ -232,7 +254,7 @@ export default function DeploymentOnboarding(props) { if (e.vhosts && e.vhosts.length > 0) { return { env: e.name, - vhost: api.isWebSocket() ? e.vhosts[0].wsHost : e.vhosts[0].host + vhost: getHostValue(e.vhosts[0], api.isWebSocket()), }; } else { return undefined; @@ -434,6 +456,7 @@ export default function DeploymentOnboarding(props) { value={row.name} checked={selectedEnvironment.includes(row.name)} onChange={handleChange} + disabled={!hasValidHosts(row)} color='primary' icon={} checkedIcon= @@ -524,18 +547,21 @@ export default function DeploymentOnboarding(props) { }, }} > - {row.vhosts.map( - (vhost) => ( - - {api.isWebSocket() - ? vhost.wsHost - : vhost.host} + {row.vhosts.filter((vhost + ) => !api.isWebSocket() + || hasValidWebSocketPorts(vhost)) + .map((vhost) => {const + hostValue = getHostValue(vhost, + api.isWebSocket()); + return ( + + {hostValue} - ), - )} + ); + })} @@ -655,7 +681,8 @@ export default function DeploymentOnboarding(props) { value={row.name} checked= {selectedExternalGateway.includes(row.name)} - disabled={isDeployRestricted()} + disabled={isDeployRestricted() + || !hasValidHosts(row)} onChange={handleChange} color='primary' icon={} @@ -718,15 +745,21 @@ export default function DeploymentOnboarding(props) { helperText={getVhostHelperText(row.name, selectedVhostDeploy, true)} > - {row.vhosts?.map( - (vhost) => ( - - {api.isWebSocket() - ? vhost.wsHost : vhost.host} - - ), - )} + {row.vhosts + .filter((vhost) => !api.isWebSocket() + || hasValidWebSocketPorts(vhost)) + .map((vhost) => { + const hostValue = getHostValue(vhost, + api.isWebSocket()); + return ( + + {hostValue} + + ); + })}