Skip to content

Commit 7abad78

Browse files
committed
Fix sonarcloud recommendations
1 parent e0033c7 commit 7abad78

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/AsyncApiConsole/AsyncApiUI.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ export default function AsyncApiUI(props) {
242242
id="api-endpoint-select"
243243
value={endPoint}
244244
displayEmpty
245-
disabled={Object.keys(URLs).length === 0 || !Object.values(URLs).some((url) => url)}
245+
disabled={Object.keys(URLs).length === 0 || !Object.values(URLs).some(Boolean)}
246246
onChange={handleServerChange}
247247
>
248-
{Object.keys(URLs).length === 0 || !Object.values(URLs).some((url) => url) ? (
248+
{Object.keys(URLs).length === 0 || !Object.values(URLs).some(Boolean) ? (
249249
<MenuItem value='' disabled>
250250
<em>No servers available</em>
251251
</MenuItem>

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function Environments(props) {
169169
aria-label='Copy the Default Version URL to clipboard'
170170
size='large'
171171
onClick={() => {
172-
navigator.clipboard.writeText(firstEnabledDefaultUrl).then(onCopy('urlCopied'));
172+
navigator.clipboard.writeText(firstEnabledDefaultUrl).then(onCopy);
173173
}}
174174
>
175175
<Icon color='secondary'>file_copy</Icon>
@@ -276,7 +276,7 @@ function Environments(props) {
276276
navigator.clipboard.writeText(selectedEndpoint.URLs.https
277277
|| selectedEndpoint.URLs.http
278278
|| selectedEndpoint.URLs.wss
279-
|| selectedEndpoint.URLs.ws).then(onCopy('urlCopied'));
279+
|| selectedEndpoint.URLs.ws).then(onCopy);
280280
}}
281281
>
282282
<Icon color='secondary'>file_copy</Icon>
@@ -329,7 +329,7 @@ function Environments(props) {
329329
size='large'
330330
onClick={() => {
331331
navigator.clipboard.writeText(selectedEndpoint.URLs.wss
332-
|| selectedEndpoint.URLs.ws).then(onCopy('urlCopied'));
332+
|| selectedEndpoint.URLs.ws).then(onCopy);
333333
}}
334334
>
335335
<Icon color='secondary'>file_copy</Icon>
@@ -406,7 +406,7 @@ function Environments(props) {
406406
navigator.clipboard.writeText(
407407
advertiseInfo.apiExternalProductionEndpoint,
408408
)
409-
.then(onCopy('urlCopied'));
409+
.then(onCopy);
410410
}}
411411
>
412412
<Icon color='secondary'>file_copy</Icon>
@@ -459,7 +459,7 @@ function Environments(props) {
459459
navigator.clipboard.writeText(
460460
advertiseInfo.apiExternalSandboxEndpoint,
461461
)
462-
.then(onCopy('urlCopied'));
462+
.then(onCopy);
463463
}}
464464
>
465465
<Icon color='secondary'>file_copy</Icon>
@@ -501,6 +501,23 @@ function Environments(props) {
501501
Environments.propTypes = {
502502
classes: PropTypes.shape({}).isRequired,
503503
intl: PropTypes.shape({}).isRequired,
504+
selectedEndpoint: PropTypes.shape({
505+
environmentName: PropTypes.string,
506+
environmentDisplayName: PropTypes.string,
507+
environmentType: PropTypes.string,
508+
URLs: PropTypes.shape({
509+
http: PropTypes.string,
510+
https: PropTypes.string,
511+
ws: PropTypes.string,
512+
wss: PropTypes.string,
513+
}).isRequired,
514+
defaultVersionURLs: PropTypes.shape({
515+
http: PropTypes.string,
516+
https: PropTypes.string,
517+
ws: PropTypes.string,
518+
wss: PropTypes.string,
519+
}),
520+
}).isRequired,
504521
};
505522

506523
export default Environments;

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

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ export default function Environments() {
25482548
const gateways = internalGateways.length > 0 ? internalGateways: externalGateways;
25492549
if (api.isWebSocket() ) {
25502550
vhost = gateways.find((e) => e.name === env).vhosts.find(
2551-
(v) => v.wsHost === selected.vhost || (v.wsHost === null && v.wssHost === selected.vhost),
2551+
(v) => v.wsHost === selected.vhost || v.wssHost === selected.vhost,
25522552
);
25532553
if (!hasValidWebSocketPorts(vhost)) {
25542554
return 'No valid hosts available for this environment';
@@ -2567,8 +2567,10 @@ export default function Environments() {
25672567
}
25682568
const gatewayUrls = getGatewayAccessUrl(vhost, api.isWebSocket() ? 'WS' : 'HTTP');
25692569
if (shorten) {
2570-
const helperText = getGatewayAccessUrl(vhost, api.isWebSocket() ? 'WS' : 'HTTP').secondary;
2571-
return helperText.length > maxtLen ? helperText.substring(0, maxtLen) + '...' : helperText;
2570+
const wsOrHttp = api.isWebSocket() ? 'WS' : 'HTTP';
2571+
const endpoints = getGatewayAccessUrl(vhost, wsOrHttp);
2572+
const preferred = endpoints.secondary || endpoints.primary; // prefer wss/https; fallback to ws/http
2573+
return preferred.length > maxtLen ? preferred.substring(0, maxtLen) + '...' : preferred;
25722574
}
25732575
return gatewayUrls.combined;
25742576
}
@@ -2999,7 +3001,9 @@ export default function Environments() {
29993001
const hostValue = getHostValue(vhost,
30003002
api.isWebSocket());
30013003
return (
3002-
<MenuItem value={hostValue}>
3004+
<MenuItem
3005+
key={hostValue}
3006+
value={hostValue}>
30033007
{hostValue}
30043008
</MenuItem>
30053009
);
@@ -3172,8 +3176,11 @@ export default function Environments() {
31723176
>
31733177
{row.vhosts?.map(
31743178
(vhost) => (
3175-
<MenuItem value={getHostValue(
3176-
vhost,api.isWebSocket())}>
3179+
<MenuItem
3180+
key={getHostValue(vhost,
3181+
api.isWebSocket())}
3182+
value={getHostValue(
3183+
vhost,api.isWebSocket())}>
31773184
{getHostValue(
31783185
vhost,api.isWebSocket())}
31793186
</MenuItem>
@@ -3229,7 +3236,7 @@ export default function Environments() {
32293236
</DialogActions>
32303237
</StyledDialog>
32313238
</Grid>
3232-
{allRevisions && allRevisions.length !== 0
3239+
{allRevisions && allRevisions.length !== 0
32333240
&& !api.isRevision && (settings && !settings.portalConfigurationOnlyModeEnabled) && (
32343241
<>
32353242
<Grid
@@ -3557,15 +3564,15 @@ export default function Environments() {
35573564
<>
35583565
<TableCell align='left' className={classes.tableCellVhostSelect}>
35593566
<Tooltip
3560-
title={!hasValidHosts(row)
3561-
? 'No valid hosts available for this environment' : (
3567+
title={hasValidHosts(row)
3568+
? (
35623569
<>
35633570
<Typography color='inherit'>
35643571
{getVhostHelperText(row.name,
35653572
selectedVhosts)}
35663573
</Typography>
35673574
</>
3568-
)}
3575+
) : 'No valid hosts available for this environment'}
35693576
placement='bottom'
35703577
>
35713578
<TextField
@@ -3603,8 +3610,10 @@ export default function Environments() {
36033610
>
36043611
{row.vhosts.map(
36053612
(vhost) => (
3606-
<MenuItem value={getHostValue(
3607-
vhost, api.isWebSocket())}>
3613+
<MenuItem
3614+
key={getHostValue(vhost, api.isWebSocket())}
3615+
value={getHostValue(
3616+
vhost, api.isWebSocket())}>
36083617
{getHostValue(vhost, api.isWebSocket())}
36093618
</MenuItem>
36103619
),
@@ -3783,15 +3792,15 @@ export default function Environments() {
37833792
<>
37843793
<TableCell align='left' className={classes.tableCellVhostSelect}>
37853794
<Tooltip
3786-
title={!hasValidHosts(row)
3787-
? 'No valid hosts available for this environment' : (
3795+
title={hasValidHosts(row)
3796+
? (
37883797
<>
37893798
<Typography color='inherit'>
37903799
{getVhostHelperText(row.name,
37913800
selectedVhosts)}
37923801
</Typography>
37933802
</>
3794-
)}
3803+
) : 'No valid hosts available for this environment'}
37953804
placement='bottom'
37963805
>
37973806
<TextField
@@ -3825,8 +3834,10 @@ export default function Environments() {
38253834
>
38263835
{row.vhosts.map(
38273836
(vhost) => (
3828-
<MenuItem value={getHostValue(
3829-
vhost, api.isWebSocket())}>
3837+
<MenuItem
3838+
key={getHostValue(vhost, api.isWebSocket())}
3839+
value={getHostValue(
3840+
vhost, api.isWebSocket())}>
38303841
{getHostValue(vhost, api.isWebSocket())}
38313842
</MenuItem>
38323843
),

0 commit comments

Comments
 (0)