forked from weaveworks/weave-gitops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPodDetail.tsx
200 lines (191 loc) · 5.11 KB
/
PodDetail.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import { Tabs } from "@mui/material";
import * as React from "react";
import styled from "styled-components";
import { Container, FluxObject } from "../lib/objects";
import { createYamlCommand } from "../lib/utils";
import DataTable from "./DataTable";
import Flex from "./Flex";
import InfoList from "./InfoList";
import MuiTab from "./MuiTab";
import PageStatus from "./PageStatus";
import Text from "./Text";
import { DialogYamlView } from "./YamlView";
type Props = {
className?: string;
pod: FluxObject;
};
const InfoListUl = styled.ul`
margin: 0;
padding: 0;
list-style: none;
li {
padding: 0;
}
`;
const PodDetailHeader = styled(Text)`
padding: ${(props) => props.theme.spacing.xs} 0;
color: ${(props) => props.theme.colors.neutral30};
`;
export const NoDialogDataTable = styled(DataTable)`
max-width: 100%;
overflow-x: auto;
`;
const ContainerDivider = styled(Flex)`
padding-bottom: ${(props) => props.theme.spacing.small};
margin-bottom: ${(props) => props.theme.spacing.small};
width: 100%;
border-bottom: 3px solid;
border-image-slice: 1;
border-image-source: ${(props) =>
`linear-gradient(to right, ${props.theme.colors.neutral30} 0%, ${props.theme.colors.neutral00} 100%)`};
`;
type ListProps = {
array: any[];
display: (any) => string;
};
const ArrayToList = ({ array, display }: ListProps) => {
return (
<InfoListUl>
{!array || !array.length ? (
<li key={0}>-</li>
) : (
array.map((item, i) => <li key={i}>{display(item)}</li>)
)}
</InfoListUl>
);
};
const Detail = ({ pod }) => {
return (
<Flex wide column>
<InfoList
items={[
["Namespace", pod.namespace],
["Pod IP", pod.podIP],
[
"Pod IPs",
<ArrayToList
key={pod.id}
array={pod.podIPs}
display={(p) => p.ip}
/>,
],
["Priority Class", pod.priorityClass],
["QoS Class", pod.qosClass],
]}
/>
<PodDetailHeader bold size="large">
Tolerations
</PodDetailHeader>
<NoDialogDataTable
hideSearchAndFilters
fields={[
{ label: "Key", value: "key" },
{ label: "Operator", value: "operator" },
{ label: "Value", value: "value" },
{ label: "Effect", value: "effect" },
{ label: "Seconds", value: "tolerationSeconds" },
]}
rows={pod.tolerations}
/>
<PodDetailHeader bold size="large">
Containers
</PodDetailHeader>
{pod.containers.map((container: Container, i: number) => {
return (
<>
<InfoList
key={container.name}
items={[
["Name", container.name],
["Image", container.image],
[
"Ports",
<ArrayToList
key={container.name}
array={container.ports}
display={(port) =>
`${port.name}:${port.containerPort}/${port.protocol}`
}
/>,
],
[
"Env Vars",
<ArrayToList
key={container.name}
array={container.enVar}
display={(v) => v}
/>,
],
[
"Arguments",
<ArrayToList
key={container.name}
array={container.args}
display={(arg) => arg}
/>,
],
]}
/>
{i < pod.containers.length - 1 && <ContainerDivider key={i} />}
</>
);
})}
<PodDetailHeader bold size="large">
Volumes
</PodDetailHeader>
<ArrayToList
array={pod.volumes}
display={({ name, type }) => `${name}: ${type}`}
/>
</Flex>
);
};
function PodDetail({ className, pod }: Props) {
const [tabValue, setTabValue] = React.useState(0);
const tabKeys = ["detail", "yaml"];
const tabs = (value: number) => {
switch (value) {
case 0:
return <Detail pod={pod} />;
case 1:
return (
<DialogYamlView
yaml={pod.yaml}
header={createYamlCommand(pod.type, pod.name, pod.namespace)}
/>
);
}
};
return (
<Flex wide tall column className={className}>
<PageStatus
conditions={pod.conditions}
suspended={pod.suspended}
showAll
/>
<Tabs
value={tabValue}
indicatorColor="primary"
className="horizontal-tabs"
>
{tabKeys.map((key, i) => {
return (
<MuiTab
key={i}
text={key}
active={tabValue === i}
onClick={() => setTabValue(i)}
/>
);
})}
</Tabs>
{tabs(tabValue)}
</Flex>
);
}
export default styled(PodDetail).attrs({ className: PodDetail.name })`
height: 100%;
${NoDialogDataTable} {
margin-bottom: ${(props) => props.theme.spacing.small};
}
`;