Skip to content

Commit 19748c9

Browse files
committed
Fix sonarcloud recommendations
1 parent 93c701b commit 19748c9

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
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: 21 additions & 14 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
}
@@ -3172,8 +3174,11 @@ export default function Environments() {
31723174
>
31733175
{row.vhosts?.map(
31743176
(vhost) => (
3175-
<MenuItem value={getHostValue(
3176-
vhost,api.isWebSocket())}>
3177+
<MenuItem
3178+
key={getHostValue(vhost,
3179+
api.isWebSocket())}
3180+
value={getHostValue(
3181+
vhost,api.isWebSocket())}>
31773182
{getHostValue(
31783183
vhost,api.isWebSocket())}
31793184
</MenuItem>
@@ -3229,7 +3234,7 @@ export default function Environments() {
32293234
</DialogActions>
32303235
</StyledDialog>
32313236
</Grid>
3232-
{allRevisions && allRevisions.length !== 0
3237+
{allRevisions && allRevisions.length !== 0
32333238
&& !api.isRevision && (settings && !settings.portalConfigurationOnlyModeEnabled) && (
32343239
<>
32353240
<Grid
@@ -3557,15 +3562,15 @@ export default function Environments() {
35573562
<>
35583563
<TableCell align='left' className={classes.tableCellVhostSelect}>
35593564
<Tooltip
3560-
title={!hasValidHosts(row)
3561-
? 'No valid hosts available for this environment' : (
3565+
title={hasValidHosts(row)
3566+
? (
35623567
<>
35633568
<Typography color='inherit'>
35643569
{getVhostHelperText(row.name,
35653570
selectedVhosts)}
35663571
</Typography>
35673572
</>
3568-
)}
3573+
) : 'No valid hosts available for this environment'}
35693574
placement='bottom'
35703575
>
35713576
<TextField
@@ -3603,8 +3608,10 @@ export default function Environments() {
36033608
>
36043609
{row.vhosts.map(
36053610
(vhost) => (
3606-
<MenuItem value={getHostValue(
3607-
vhost, api.isWebSocket())}>
3611+
<MenuItem
3612+
key={getHostValue(vhost, api.isWebSocket())}
3613+
value={getHostValue(
3614+
vhost, api.isWebSocket())}>
36083615
{getHostValue(vhost, api.isWebSocket())}
36093616
</MenuItem>
36103617
),
@@ -3783,15 +3790,15 @@ export default function Environments() {
37833790
<>
37843791
<TableCell align='left' className={classes.tableCellVhostSelect}>
37853792
<Tooltip
3786-
title={!hasValidHosts(row)
3787-
? 'No valid hosts available for this environment' : (
3793+
title={hasValidHosts(row)
3794+
? (
37883795
<>
37893796
<Typography color='inherit'>
37903797
{getVhostHelperText(row.name,
37913798
selectedVhosts)}
37923799
</Typography>
37933800
</>
3794-
)}
3801+
) : 'No valid hosts available for this environment'}
37953802
placement='bottom'
37963803
>
37973804
<TextField

0 commit comments

Comments
 (0)