1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Adding tolerations table

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-01-21 14:16:05 +03:00
parent 790d833257
commit 140abbe459
4 changed files with 78 additions and 17 deletions

View File

@ -1,7 +1,7 @@
import get from "lodash/get"; import get from "lodash/get";
import { KubeObject } from "./kube-object"; import { KubeObject } from "./kube-object";
interface IToleration { export interface IToleration {
key?: string; key?: string;
operator?: string; operator?: string;
effect?: string; effect?: string;

View File

@ -1,10 +1,11 @@
import "./pod-details-tolerations.scss"; import "./pod-details-tolerations.scss";
import React from "react"; import React from "react";
import { Pod, Deployment, DaemonSet, StatefulSet, ReplicaSet, Job } from "../../api/endpoints";
import { DrawerParamToggler, DrawerItem } from "../drawer"; import { DrawerParamToggler, DrawerItem } from "../drawer";
import { WorkloadKubeObject } from "../../api/workload-kube-object";
import { PodTolerations } from "./pod-tolerations";
interface Props { interface Props {
workload: Pod | Deployment | DaemonSet | StatefulSet | ReplicaSet | Job; workload: WorkloadKubeObject;
} }
export class PodDetailsTolerations extends React.Component<Props> { export class PodDetailsTolerations extends React.Component<Props> {
@ -17,20 +18,7 @@ export class PodDetailsTolerations extends React.Component<Props> {
return ( return (
<DrawerItem name="Tolerations" className="PodDetailsTolerations"> <DrawerItem name="Tolerations" className="PodDetailsTolerations">
<DrawerParamToggler label={tolerations.length}> <DrawerParamToggler label={tolerations.length}>
{ <PodTolerations tolerations={tolerations} />
tolerations.map((toleration, index) => {
const { key, operator, effect, tolerationSeconds } = toleration;
return (
<div className="toleration" key={index}>
<DrawerItem name="Key">{key}</DrawerItem>
{operator && <DrawerItem name="Operator">{operator}</DrawerItem>}
{effect && <DrawerItem name="Effect">{effect}</DrawerItem>}
{!!tolerationSeconds && <DrawerItem name="Effect">{tolerationSeconds}</DrawerItem>}
</div>
);
})
}
</DrawerParamToggler> </DrawerParamToggler>
</DrawerItem> </DrawerItem>
); );

View File

@ -0,0 +1,10 @@
.PodTolerations {
.TableCell {
white-space: normal;
word-break: normal;
&.key {
flex-grow: 4;
}
}
}

View File

@ -0,0 +1,63 @@
import "./pod-tolerations.scss";
import React from "react";
import uniqueId from "lodash/uniqueId";
import { IToleration } from "../../api/workload-kube-object";
import { Table, TableCell, TableHead, TableRow } from "../table";
interface Props {
tolerations: IToleration[];
}
enum sortBy {
Key = "key",
Operator = "operator",
Effect = "effect",
Seconds = "seconds",
}
const sortingCallbacks = {
[sortBy.Key]: (toleration: IToleration) => toleration.key,
[sortBy.Operator]: (toleration: IToleration) => toleration.operator,
[sortBy.Effect]: (toleration: IToleration) => toleration.effect,
[sortBy.Seconds]: (toleration: IToleration) => toleration.tolerationSeconds,
};
const getTableRow = (toleration: IToleration) => {
const { key, operator, effect, tolerationSeconds } = toleration;
return (
<TableRow
key={uniqueId("toleration-")}
sortItem={toleration}
nowrap
>
<TableCell className="key">{key}</TableCell>
<TableCell className="operator">{operator}</TableCell>
<TableCell className="effect">{effect}</TableCell>
<TableCell className="seconds">{tolerationSeconds}</TableCell>
</TableRow>
);
};
export function PodTolerations({ tolerations }: Props) {
return (
<Table
selectable
scrollable={false}
sortable={sortingCallbacks}
sortSyncWithUrl={false}
className="PodTolerations"
>
<TableHead sticky={false}>
<TableCell className="key" sortBy={sortBy.Key}>Key</TableCell>
<TableCell className="operator" sortBy={sortBy.Operator}>Operator</TableCell>
<TableCell className="effect" sortBy={sortBy.Effect}>Effect</TableCell>
<TableCell className="seconds" sortBy={sortBy.Seconds}>Seconds</TableCell>
</TableHead>
{
tolerations.map(getTableRow)
}
</Table>
);
}