15
15
*/
16
16
17
17
import Box from '@mui/material/Box' ;
18
+ import Tooltip from '@mui/material/Tooltip' ;
18
19
import Typography from '@mui/material/Typography' ;
19
20
import { useTranslation } from 'react-i18next' ;
20
21
import { useParams } from 'react-router' ;
21
- import { matchExpressionSimplifier , matchLabelsSimplifier } from '../../lib/k8s' ;
22
+ import { matchLabelsSimplifier } from '../../lib/k8s' ;
22
23
import AdminNetworkPolicy , {
23
24
AdminNetworkPolicyEgressRule ,
24
25
AdminNetworkPolicyIngressRule ,
25
26
AdminNetworkPolicyPort ,
26
27
} from '../../lib/k8s/adminnetworkpolicy' ;
27
- import { LabelSelector } from '../../lib/k8s/cluster' ;
28
28
import NameValueTable from '../common/NameValueTable' ;
29
29
import { DetailsGrid , MetadataDictGrid } from '../common/Resource' ;
30
30
import { metadataStyles } from '../common/Resource' ;
31
31
import SectionBox from '../common/SectionBox' ;
32
+ import { KubeIcon } from '../resourceMap/kubeIcon/KubeIcon' ;
32
33
33
34
export default function AdminNetworkPolicyDetails ( props : {
34
35
name ?: string ;
@@ -39,33 +40,6 @@ export default function AdminNetworkPolicyDetails(props: {
39
40
const { name = params . name , subject = params . subject , cluster } = props ;
40
41
const { t } = useTranslation ( [ 'glossary' , 'translation' ] ) ;
41
42
42
- function prepareMatchLabelsAndExpressions (
43
- type : 'Pods' | 'Namespaces' ,
44
- matchLabels : LabelSelector [ 'matchLabels' ] ,
45
- matchExpressions : LabelSelector [ 'matchExpressions' ]
46
- ) {
47
- const matchLabelsSimplified = matchLabelsSimplifier ( matchLabels ) || [ ] ;
48
- const matchExpressionsSimplified = matchExpressionSimplifier ( matchExpressions ) || [ ] ;
49
- if ( matchLabels === undefined && matchExpressions === undefined ) {
50
- return < > { type } : All</ > ;
51
- }
52
-
53
- return (
54
- < >
55
- { matchLabelsSimplified . map ( label => (
56
- < Typography sx = { metadataStyles } display = "inline" >
57
- { label }
58
- </ Typography >
59
- ) ) }
60
- { matchExpressionsSimplified . map ( expression => (
61
- < Typography sx = { metadataStyles } display = "inline" >
62
- { expression }
63
- </ Typography >
64
- ) ) }
65
- </ >
66
- ) ;
67
- }
68
-
69
43
function SubjectSelector ( props : { AdminNetworkPolicy : AdminNetworkPolicy } ) {
70
44
const { AdminNetworkPolicy } = props ;
71
45
// this is an exception which should never happen, but we handle it gracefully
@@ -77,18 +51,79 @@ export default function AdminNetworkPolicyDetails(props: {
77
51
}
78
52
79
53
if ( AdminNetworkPolicy . jsonData ?. spec ?. subject ?. pods !== undefined ) {
80
- return prepareMatchLabelsAndExpressions (
81
- 'Pods' ,
82
- AdminNetworkPolicy . jsonData ?. spec ?. subject ?. pods ?. podSelector ?. matchLabels ,
83
- AdminNetworkPolicy . jsonData ?. spec ?. subject ?. pods ?. podSelector ?. matchExpressions
54
+ return (
55
+ < >
56
+ < KubeIcon kind = "Namespace" width = "30px" height = "30px" />
57
+ < Tooltip title = "namespaceSelector" >
58
+ { ( ( ) => {
59
+ const labels = matchLabelsSimplifier (
60
+ AdminNetworkPolicy . jsonData ?. spec ?. subject ?. pods ?. namespaceSelector ?. matchLabels
61
+ ) ;
62
+ return Array . isArray ( labels ) ? (
63
+ < >
64
+ { labels . map ( ( label : string ) => (
65
+ < Typography sx = { metadataStyles } display = "inline" key = { label } >
66
+ { label }
67
+ </ Typography >
68
+ ) ) }
69
+ </ >
70
+ ) : (
71
+ < Typography sx = { metadataStyles } display = "inline" >
72
+ All Namespaces
73
+ </ Typography >
74
+ ) ;
75
+ } ) ( ) }
76
+ </ Tooltip >
77
+ < KubeIcon kind = "Pod" width = "30px" height = "30px" />
78
+ < Tooltip title = "podSelector" >
79
+ { ( ( ) => {
80
+ const labels = matchLabelsSimplifier (
81
+ AdminNetworkPolicy . jsonData ?. spec ?. subject ?. pods ?. podSelector ?. matchLabels
82
+ ) ;
83
+ return Array . isArray ( labels ) ? (
84
+ < >
85
+ { labels . map ( ( label : string ) => (
86
+ < Typography sx = { metadataStyles } display = "inline" key = { label } >
87
+ { label }
88
+ </ Typography >
89
+ ) ) }
90
+ </ >
91
+ ) : (
92
+ < Typography sx = { metadataStyles } display = "inline" >
93
+ All Pods
94
+ </ Typography >
95
+ ) ;
96
+ } ) ( ) }
97
+ </ Tooltip >
98
+ </ >
84
99
) ;
85
100
}
86
101
87
102
if ( AdminNetworkPolicy . jsonData ?. spec ?. subject ?. namespaces !== undefined ) {
88
- return prepareMatchLabelsAndExpressions (
89
- 'Namespaces' ,
90
- AdminNetworkPolicy . jsonData ?. spec ?. subject ?. namespaces ?. podSelector ?. matchLabels ,
91
- AdminNetworkPolicy . jsonData ?. spec ?. subject ?. namespaces ?. podSelector ?. matchExpressions
103
+ return (
104
+ < >
105
+ < Typography sx = { metadataStyles } display = "inline" >
106
+ { ( ( ) => {
107
+ const labels = matchLabelsSimplifier (
108
+ AdminNetworkPolicy . jsonData ?. spec ?. subject ?. namespaces ?. namespaceSelector
109
+ ?. matchLabels
110
+ ) ;
111
+ return Array . isArray ( labels ) ? (
112
+ < >
113
+ { labels . map ( ( label : string ) => (
114
+ < Typography sx = { metadataStyles } display = "inline" key = { label } >
115
+ { label }
116
+ </ Typography >
117
+ ) ) }
118
+ </ >
119
+ ) : (
120
+ < Typography sx = { metadataStyles } display = "inline" >
121
+ All Pods
122
+ </ Typography >
123
+ ) ;
124
+ } ) ( ) }
125
+ </ Typography >
126
+ </ >
92
127
) ;
93
128
}
94
129
}
0 commit comments