EventCard.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import React, { useState } from "react";
  2. import styled from "styled-components";
  3. import Loading from "components/Loading";
  4. import { KubeEvent } from "shared/types";
  5. type CardProps = {
  6. event: any;
  7. selectEvent?: (event: any) => void;
  8. overrideName?: string;
  9. };
  10. export const getReadableDate = (s: string) => {
  11. let ts = new Date(s);
  12. let date = ts.toLocaleDateString();
  13. let time = ts.toLocaleTimeString([], {
  14. hour: "numeric",
  15. minute: "2-digit",
  16. });
  17. return `${time} ${date}`;
  18. };
  19. // Rename to Event Card
  20. const EventCard: React.FunctionComponent<CardProps> = ({
  21. event,
  22. selectEvent,
  23. overrideName,
  24. }) => {
  25. const [showTooltip, setShowTooltip] = useState(false);
  26. return (
  27. <>
  28. <StyledCard>
  29. <ContentContainer>
  30. <Icon
  31. status={event.event_type.toLowerCase() as any}
  32. className="material-icons-outlined"
  33. >
  34. {event.event_type === "critical" ? "report_problem" : "info"}
  35. </Icon>
  36. <EventInformation>
  37. <EventName>
  38. <Helper>{event.resource_type}:</Helper>
  39. {event.name}
  40. </EventName>
  41. <EventReason>
  42. <Helper>Last message seen:</Helper>
  43. {event.last_message}
  44. </EventReason>
  45. </EventInformation>
  46. </ContentContainer>
  47. <ActionContainer hasOneChild={event.event_type === "normal"}>
  48. {event.sub_events?.length && (
  49. <HistoryButton
  50. onClick={() => selectEvent(event)}
  51. onMouseEnter={() => setShowTooltip(true)}
  52. onMouseLeave={() => setShowTooltip(false)}
  53. >
  54. <span className="material-icons-outlined">manage_search</span>
  55. {showTooltip && <Tooltip>Open logs</Tooltip>}
  56. </HistoryButton>
  57. )}
  58. <TimestampContainer>
  59. <TimestampIcon className="material-icons-outlined">
  60. access_time
  61. </TimestampIcon>
  62. <span>{getReadableDate(event.timestamp)}</span>
  63. </TimestampContainer>
  64. </ActionContainer>
  65. </StyledCard>
  66. </>
  67. );
  68. };
  69. export default EventCard;
  70. // const StyledCard = styled.div`
  71. // background: #26282f;
  72. // min-height: 100px;
  73. // width: 100%;
  74. // display: flex;
  75. // align-items: center;
  76. // border: 1px solid #26282f;
  77. // box-shadow: 0 4px 15px 0px #00000055;
  78. // border-radius: 8px;
  79. // padding: 14px;
  80. // animation: fadeIn 0.5s;
  81. // @keyframes fadeIn {
  82. // from {
  83. // opacity: 0;
  84. // }
  85. // to {
  86. // opacity: 1;
  87. // }
  88. // }
  89. // `;
  90. const StyledCard = styled.div`
  91. display: flex;
  92. align-items: center;
  93. justify-content: space-between;
  94. border: 1px solid #ffffff44;
  95. background: #ffffff08;
  96. margin-bottom: 10px;
  97. border-radius: 10px;
  98. padding: 20px 14px 14px 14px;
  99. overflow: hidden;
  100. height: 95px;
  101. cursor: pointer;
  102. :hover {
  103. background: #ffffff11;
  104. border: 1px solid #ffffff66;
  105. }
  106. animation: fadeIn 0.5s;
  107. @keyframes fadeIn {
  108. from {
  109. opacity: 0;
  110. }
  111. to {
  112. opacity: 1;
  113. }
  114. }
  115. `;
  116. const ContentContainer = styled.div`
  117. display: flex;
  118. height: 100%;
  119. width: 100%;
  120. align-items: center;
  121. `;
  122. const Icon = styled.span`
  123. font-size: 35px;
  124. margin-right: 14px;
  125. color: ${({ status }: { status: "critical" | "normal" }) =>
  126. status === "critical" ? "red" : "green"};
  127. `;
  128. const EventInformation = styled.div`
  129. display: flex;
  130. flex-direction: column;
  131. justify-content: space-around;
  132. height: 100%;
  133. `;
  134. const EventName = styled.div`
  135. font-size: 14px;
  136. font-family: "Work Sans", sans-serif;
  137. font-weight: 500;
  138. color: #ffffff;
  139. `;
  140. const Helper = styled.span`
  141. font-size: 14px;
  142. text-transform: capitalize;
  143. color: #ffffff44;
  144. margin-right: 5px;
  145. `;
  146. const EventReason = styled.div`
  147. font-size: 16px;
  148. font-family: "Work Sans", sans-serif;
  149. color: #ffffff;
  150. margin-top: 8px;
  151. `;
  152. const ActionContainer = styled.div`
  153. width: max-content;
  154. display: flex;
  155. align-items: center;
  156. white-space: nowrap;
  157. height: 100%;
  158. flex-direction: column;
  159. justify-content: ${(props: { hasOneChild: boolean }) => {
  160. return props.hasOneChild ? "flex-end" : "space-between";
  161. }};
  162. `;
  163. const HistoryButton = styled.button`
  164. position: relative;
  165. border: none;
  166. background: none;
  167. color: white;
  168. padding: 5px;
  169. display: flex;
  170. justify-content: center;
  171. align-items: center;
  172. border-radius: 50%;
  173. color: #ffffff44;
  174. :hover {
  175. background: #32343a;
  176. cursor: pointer;
  177. }
  178. `;
  179. const Tooltip = styled.div`
  180. position: absolute;
  181. left: 0px;
  182. word-wrap: break-word;
  183. top: 38px;
  184. min-height: 18px;
  185. padding: 5px 7px;
  186. background: #272731;
  187. z-index: 999;
  188. display: flex;
  189. flex-direction: column;
  190. justify-content: center;
  191. flex: 1;
  192. color: white;
  193. text-transform: none;
  194. font-size: 12px;
  195. font-family: "Work Sans", sans-serif;
  196. outline: 1px solid #ffffff55;
  197. opacity: 0;
  198. animation: faded-in 0.2s 0.15s;
  199. animation-fill-mode: forwards;
  200. @keyframes faded-in {
  201. from {
  202. opacity: 0;
  203. }
  204. to {
  205. opacity: 1;
  206. }
  207. }
  208. `;
  209. const TimestampContainer = styled.div`
  210. display: flex;
  211. white-space: nowrap;
  212. align-items: center;
  213. justify-self: flex-end;
  214. min-width: 130px;
  215. justify-content: space-between;
  216. `;
  217. const TimestampIcon = styled.span`
  218. margin-right: 5px;
  219. `;