|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import { useTranslation } from 'react-i18next'; |
| 18 | +import { matchExpressionSimplifier, matchLabelsSimplifier } from '../../lib/k8s'; |
18 | 19 | import NetworkPolicy from '../../lib/k8s/networkpolicy'; |
19 | | -import LabelListItem from '../common/LabelListItem'; |
| 20 | +import { MatchExpressions } from '../common/Resource/MatchExpressions'; |
20 | 21 | import ResourceListView from '../common/Resource/ResourceListView'; |
21 | 22 |
|
22 | 23 | export function NetworkPolicyList() { |
@@ -52,22 +53,26 @@ export function NetworkPolicyList() { |
52 | 53 | gridTemplate: 'auto', |
53 | 54 | label: t('Pod Selector'), |
54 | 55 | getValue: networkpolicy => { |
55 | | - const podSelector = networkpolicy.jsonData.spec.podSelector; |
56 | | - return podSelector.matchLabels |
57 | | - ? Object.keys(podSelector.matchLabels) |
58 | | - .map(key => `${key}=${podSelector.matchLabels[key]}`) |
59 | | - .join(', ') |
60 | | - : null; |
| 56 | + const podSelector = networkpolicy.jsonData.spec.podSelector || {}; |
| 57 | + const { matchLabels, matchExpressions } = podSelector; |
| 58 | + const labels = matchLabelsSimplifier(matchLabels, true); |
| 59 | + const expressions = matchExpressionSimplifier(matchExpressions); |
| 60 | + const parts = [ |
| 61 | + ...(Array.isArray(labels) ? labels : []), |
| 62 | + ...(Array.isArray(expressions) ? expressions : []), |
| 63 | + ]; |
| 64 | + return parts.join(', '); |
61 | 65 | }, |
62 | 66 | render: networkpolicy => { |
63 | | - const podSelector = networkpolicy.jsonData.spec.podSelector; |
64 | | - return podSelector.matchLabels ? ( |
65 | | - <LabelListItem |
66 | | - labels={Object.keys(podSelector.matchLabels).map( |
67 | | - key => `${key}=${podSelector.matchLabels[key]}` |
68 | | - )} |
69 | | - /> |
70 | | - ) : null; |
| 67 | + const podSelector = networkpolicy.jsonData.spec.podSelector || {}; |
| 68 | + const { matchLabels, matchExpressions } = podSelector; |
| 69 | + if (!matchLabels && !matchExpressions) { |
| 70 | + return null; |
| 71 | + } |
| 72 | + |
| 73 | + return ( |
| 74 | + <MatchExpressions matchLabels={matchLabels} matchExpressions={matchExpressions} /> |
| 75 | + ); |
71 | 76 | }, |
72 | 77 | }, |
73 | 78 | 'age', |
|
0 commit comments