Skip to content

Commit 8620531

Browse files
authored
Merge pull request #849 from nimsara66/3407
Add scopes details to tooltip in `CustomPadLock`
2 parents 794368f + 4e3eb5e commit 8620531

File tree

1 file changed

+96
-19
lines changed
  • portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/ApiConsole

1 file changed

+96
-19
lines changed

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

+96-19
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,33 @@
1717
*/
1818

1919
import React, { useMemo } from 'react';
20+
import { styled } from '@mui/material/styles';
2021
import 'swagger-ui-react/swagger-ui.css';
2122
import LockIcon from '@mui/icons-material/Lock';
22-
import IconButton from '@mui/material/IconButton';
23-
import Tooltip from '@mui/material/Tooltip';
24-
import Grid from '@mui/material/Grid';
23+
import {
24+
IconButton, Tooltip, Grid, Table, TableBody, TableCell, TableRow,
25+
} from '@mui/material';
2526
import { FormattedMessage } from 'react-intl';
2627
import LockOpenIcon from '@mui/icons-material/LockOpen';
2728

29+
const StyledTableCell = styled(TableCell)(() => ({
30+
color: 'white',
31+
paddingBottom: '0',
32+
paddingLeft: '0',
33+
paddingTop: '0',
34+
textAlign: 'left',
35+
}));
36+
37+
const StyledScopeCell = styled(TableCell)(() => ({
38+
color: 'white',
39+
padding: '0',
40+
textAlign: 'left',
41+
borderBottom: 'none',
42+
overflow: 'hidden',
43+
textOverflow: 'ellipsis',
44+
whiteSpace: 'nowrap',
45+
}));
46+
2847
/**
2948
*
3049
*
@@ -38,6 +57,27 @@ function isSecurityEnabled(spec, resourcePath) {
3857
return operation['x-auth-type'] && operation['x-auth-type'].toLowerCase() !== 'none';
3958
}
4059

60+
/**
61+
*
62+
*
63+
* @export
64+
* @param {*} spec
65+
* @param {*} resourcePath
66+
* @returns
67+
*/
68+
function getScopesForOperation(spec, resourcePath) {
69+
const operation = resourcePath.reduce((a, v) => a[v], spec);
70+
const security = operation.security || [];
71+
const scopes = [];
72+
73+
security.forEach((auth) => {
74+
Object.values(auth).forEach((scopeList) => {
75+
scopes.push(...scopeList);
76+
});
77+
});
78+
return scopes;
79+
}
80+
4181
/**
4282
*
4383
* Handles the resource level lock icon
@@ -52,6 +92,7 @@ function CustomPadLock(props) {
5292
BaseLayout, oldProps, spec,
5393
} = props;
5494
const securityEnabled = useMemo(() => isSecurityEnabled(spec, oldProps.specPath), []);
95+
const scopes = useMemo(() => getScopesForOperation(spec, oldProps.specPath), []);
5596

5697
return (
5798
<div>
@@ -61,22 +102,58 @@ function CustomPadLock(props) {
61102
</Grid>
62103
<Grid item justifyContent='flex-end' alignItems='right'>
63104
<Tooltip
64-
title={
65-
(securityEnabled)
66-
? (
67-
<FormattedMessage
68-
id={'Apis.Details.Resources.components.Operation.disable.security'
69-
+ '.when.used.in.api.products'}
70-
defaultMessage='Security enabled'
71-
/>
72-
)
73-
: (
74-
<FormattedMessage
75-
id='Apis.Details.Resources.components.enabled.security'
76-
defaultMessage='No security'
77-
/>
78-
)
79-
}
105+
title={(
106+
<Table size='small'>
107+
<TableBody>
108+
<TableRow>
109+
<StyledTableCell>
110+
<FormattedMessage
111+
id='Apis.Details.Resources.components.Operation.security'
112+
defaultMessage='Security'
113+
/>
114+
</StyledTableCell>
115+
<StyledTableCell>
116+
{securityEnabled
117+
? (
118+
<FormattedMessage
119+
id='Apis.Details.Resources.components.Operation.security.enabled'
120+
defaultMessage='Enabled'
121+
/>
122+
)
123+
: (
124+
<FormattedMessage
125+
id='Apis.Details.Resources.components.Operation.security.disabled'
126+
defaultMessage='Disabled'
127+
/>
128+
)}
129+
</StyledTableCell>
130+
</TableRow>
131+
{securityEnabled && (
132+
<TableRow>
133+
<StyledTableCell>
134+
<FormattedMessage
135+
id='Apis.Details.Resources.components.Operation.scopes'
136+
defaultMessage='Scopes'
137+
/>
138+
</StyledTableCell>
139+
<StyledTableCell style={{ maxWidth: 100, paddingRight: 0 }}>
140+
{scopes.length > 0 && (
141+
scopes.map((scope, index) => (
142+
// eslint-disable-next-line react/no-array-index-key
143+
<TableRow key={index}>
144+
<StyledScopeCell style={{ maxWidth: 100 }}>
145+
{scope}
146+
</StyledScopeCell>
147+
</TableRow>
148+
))
149+
)}
150+
</StyledTableCell>
151+
</TableRow>
152+
)}
153+
154+
</TableBody>
155+
</Table>
156+
)}
80157
aria-label={(
81158
<FormattedMessage
82159
id='Apis.Details.Resources.components.Operation.security.operation'

0 commit comments

Comments
 (0)