TopicConsumerGroups.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React from 'react';
  2. import { Topic, TopicDetails, ConsumerGroup } from 'generated-sources';
  3. import { ClusterName, TopicName } from 'redux/interfaces';
  4. import { clusterConsumerGroupsPath } from 'lib/paths';
  5. import { Table } from 'components/common/table/Table/Table.styled';
  6. import TableHeaderCell from 'components/common/table/TableHeaderCell/TableHeaderCell';
  7. import TagStyled from 'components/common/Tag/Tag.styled';
  8. import { TableKeyLink } from 'components/common/table/Table/TableKeyLink.styled';
  9. import { Link } from 'react-router-dom';
  10. interface Props extends Topic, TopicDetails {
  11. clusterName: ClusterName;
  12. topicName: TopicName;
  13. consumerGroups: ConsumerGroup[];
  14. fetchTopicConsumerGroups(
  15. clusterName: ClusterName,
  16. topicName: TopicName
  17. ): void;
  18. }
  19. const TopicConsumerGroups: React.FC<Props> = ({
  20. consumerGroups,
  21. fetchTopicConsumerGroups,
  22. clusterName,
  23. topicName,
  24. }) => {
  25. React.useEffect(() => {
  26. fetchTopicConsumerGroups(clusterName, topicName);
  27. }, []);
  28. return (
  29. <div>
  30. <Table isFullwidth>
  31. <thead>
  32. <tr>
  33. <TableHeaderCell title="Consumer Group ID" />
  34. <TableHeaderCell title="Num Of Members" />
  35. <TableHeaderCell title="Messages Behind" />
  36. <TableHeaderCell title="Coordinator" />
  37. <TableHeaderCell title="State" />
  38. </tr>
  39. </thead>
  40. <tbody>
  41. {consumerGroups.map((consumer) => (
  42. <tr key={consumer.groupId}>
  43. <TableKeyLink>
  44. <Link
  45. to={`${clusterConsumerGroupsPath(clusterName)}/${
  46. consumer.groupId
  47. }`}
  48. >
  49. {consumer.groupId}
  50. </Link>
  51. </TableKeyLink>
  52. <td>{consumer.members}</td>
  53. <td>{consumer.messagesBehind}</td>
  54. <td>{consumer.coordinator?.id}</td>
  55. <td>
  56. {consumer.state && (
  57. <TagStyled color="yellow">{`${consumer.state
  58. .charAt(0)
  59. .toUpperCase()}${consumer.state
  60. .slice(1)
  61. .toLowerCase()}`}</TagStyled>
  62. )}
  63. </td>
  64. </tr>
  65. ))}
  66. {consumerGroups.length === 0 && (
  67. <tr>
  68. <td colSpan={10}>No active consumer groups</td>
  69. </tr>
  70. )}
  71. </tbody>
  72. </Table>
  73. </div>
  74. );
  75. };
  76. export default TopicConsumerGroups;