17
17
*/
18
18
19
19
import React , { useMemo } from 'react' ;
20
+ import { styled } from '@mui/material/styles' ;
20
21
import 'swagger-ui-react/swagger-ui.css' ;
21
22
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' ;
25
26
import { FormattedMessage } from 'react-intl' ;
26
27
import LockOpenIcon from '@mui/icons-material/LockOpen' ;
27
28
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
+
28
47
/**
29
48
*
30
49
*
@@ -38,6 +57,27 @@ function isSecurityEnabled(spec, resourcePath) {
38
57
return operation [ 'x-auth-type' ] && operation [ 'x-auth-type' ] . toLowerCase ( ) !== 'none' ;
39
58
}
40
59
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
+
41
81
/**
42
82
*
43
83
* Handles the resource level lock icon
@@ -52,6 +92,7 @@ function CustomPadLock(props) {
52
92
BaseLayout, oldProps, spec,
53
93
} = props ;
54
94
const securityEnabled = useMemo ( ( ) => isSecurityEnabled ( spec , oldProps . specPath ) , [ ] ) ;
95
+ const scopes = useMemo ( ( ) => getScopesForOperation ( spec , oldProps . specPath ) , [ ] ) ;
55
96
56
97
return (
57
98
< div >
@@ -61,22 +102,58 @@ function CustomPadLock(props) {
61
102
</ Grid >
62
103
< Grid item justifyContent = 'flex-end' alignItems = 'right' >
63
104
< 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
+ ) }
80
157
aria-label = { (
81
158
< FormattedMessage
82
159
id = 'Apis.Details.Resources.components.Operation.security.operation'
0 commit comments