ListItem.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React from 'react';
  2. import cx from 'classnames';
  3. import { NavLink } from 'react-router-dom';
  4. import { TopicWithDetailedInfo } from 'redux/interfaces';
  5. interface ListItemProps {
  6. topic: TopicWithDetailedInfo;
  7. }
  8. const ListItem: React.FC<ListItemProps> = ({
  9. topic: { name, internal, partitions },
  10. }) => {
  11. const outOfSyncReplicas = React.useMemo(() => {
  12. if (partitions === undefined || partitions.length === 0) {
  13. return 0;
  14. }
  15. return partitions.reduce((memo: number, { replicas }) => {
  16. const outOfSync = replicas?.filter(({ inSync }) => !inSync);
  17. return memo + (outOfSync?.length || 0);
  18. }, 0);
  19. }, [partitions]);
  20. return (
  21. <tr>
  22. <td>
  23. <NavLink
  24. exact
  25. to={`topics/${name}`}
  26. activeClassName="is-active"
  27. className="title is-6"
  28. >
  29. {name}
  30. </NavLink>
  31. </td>
  32. <td>{partitions?.length}</td>
  33. <td>{outOfSyncReplicas}</td>
  34. <td>
  35. <div
  36. className={cx('tag is-small', internal ? 'is-light' : 'is-success')}
  37. >
  38. {internal ? 'Internal' : 'External'}
  39. </div>
  40. </td>
  41. </tr>
  42. );
  43. };
  44. export default ListItem;