ListItem.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import React from 'react';
  2. import cx from 'classnames';
  3. import { NavLink } from 'react-router-dom';
  4. import {
  5. ClusterName,
  6. TopicName,
  7. TopicWithDetailedInfo,
  8. } from 'redux/interfaces';
  9. import DropdownItem from 'components/common/Dropdown/DropdownItem';
  10. import Dropdown from 'components/common/Dropdown/Dropdown';
  11. export interface ListItemProps {
  12. topic: TopicWithDetailedInfo;
  13. deleteTopic: (clusterName: ClusterName, topicName: TopicName) => void;
  14. clusterName: ClusterName;
  15. }
  16. const ListItem: React.FC<ListItemProps> = ({
  17. topic: { name, internal, partitions },
  18. deleteTopic,
  19. clusterName,
  20. }) => {
  21. const outOfSyncReplicas = React.useMemo(() => {
  22. if (partitions === undefined || partitions.length === 0) {
  23. return 0;
  24. }
  25. return partitions.reduce((memo: number, { replicas }) => {
  26. const outOfSync = replicas?.filter(({ inSync }) => !inSync);
  27. return memo + (outOfSync?.length || 0);
  28. }, 0);
  29. }, [partitions]);
  30. const deleteTopicHandler = React.useCallback(() => {
  31. deleteTopic(clusterName, name);
  32. }, [clusterName, name]);
  33. return (
  34. <tr>
  35. <td className="has-text-overflow-ellipsis">
  36. <NavLink
  37. exact
  38. to={`topics/${name}`}
  39. activeClassName="is-active"
  40. className="title is-6"
  41. >
  42. {name}
  43. </NavLink>
  44. </td>
  45. <td>{partitions?.length}</td>
  46. <td>{outOfSyncReplicas}</td>
  47. <td>
  48. <div className={cx('tag', internal ? 'is-light' : 'is-primary')}>
  49. {internal ? 'Internal' : 'External'}
  50. </div>
  51. </td>
  52. <td className="has-text-right">
  53. <Dropdown
  54. label={
  55. <span className="icon">
  56. <i className="fas fa-cog" />
  57. </span>
  58. }
  59. right
  60. >
  61. <DropdownItem onClick={deleteTopicHandler}>
  62. <span className="has-text-danger">Remove Topic</span>
  63. </DropdownItem>
  64. </Dropdown>
  65. </td>
  66. </tr>
  67. );
  68. };
  69. export default ListItem;