import "./events.scss"; import React from "react"; import { observer } from "mobx-react"; import { MainLayout } from "../layout/main-layout"; import { eventStore } from "./event.store"; import { KubeObjectListLayout, KubeObjectListLayoutProps } from "../kube-object"; import { Trans } from "@lingui/macro"; import { KubeEvent } from "../../api/endpoints/events.api"; import { Tooltip, TooltipContent } from "../tooltip"; import { Link } from "react-router-dom"; import { cssNames, IClassName, stopPropagation } from "../../utils"; import { Icon } from "../icon"; import { getDetailsUrl } from "../../navigation"; import { lookupApiLink } from "../../api/kube-api"; enum sortBy { namespace = "namespace", object = "object", type = "type", count = "count", age = "age", } interface Props extends Partial { className?: IClassName; compact?: boolean; compactLimit?: number; } const defaultProps: Partial = { compactLimit: 10, }; @observer export class Events extends React.Component { static defaultProps = defaultProps as object; render() { const { compact, compactLimit, className, ...layoutProps } = this.props; const events = ( event.getNs(), [sortBy.type]: (event: KubeEvent) => event.involvedObject.kind, [sortBy.object]: (event: KubeEvent) => event.involvedObject.name, [sortBy.count]: (event: KubeEvent) => event.count, [sortBy.age]: (event: KubeEvent) => event.getAge(false), }} searchFilters={[ (event: KubeEvent) => event.getSearchFields(), (event: KubeEvent) => event.message, (event: KubeEvent) => event.getSource(), (event: KubeEvent) => event.involvedObject.name, ]} renderHeaderTitle={Events} customizeHeader={({ title, info }) => ( compact ? title : ({ info: ( <> {info} Limited to {eventStore.limit}} /> ) }) )} renderTableHeader={[ { title: Message, className: "message" }, { title: Namespace, className: "namespace", sortBy: sortBy.namespace }, { title: Type, className: "type", sortBy: sortBy.type }, { title: Involved Object, className: "object", sortBy: sortBy.object }, { title: Source, className: "source" }, { title: Count, className: "count", sortBy: sortBy.count }, { title: Age, className: "age", sortBy: sortBy.age }, ]} renderTableContents={(event: KubeEvent) => { const { involvedObject, type, message } = event; const { kind, name } = involvedObject; const tooltipId = `message-${event.getId()}`; const isWarning = type === "Warning"; const detailsUrl = getDetailsUrl(lookupApiLink(involvedObject, event)); return [ { className: { warning: isWarning }, title: ( <> {message} {message} ) }, event.getNs(), kind, {name}, event.getSource(), event.count, event.getAge(), ] }} virtual={!compact} filterItems={[ items => compact ? items.slice(0, compactLimit) : items, ]} /> ) if (compact) { return events; } return ( {events} ) } }