Details.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import React from 'react';
  2. import { ClusterName } from 'redux/interfaces';
  3. import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb';
  4. import { clusterConsumerGroupsPath } from 'lib/paths';
  5. import { ConsumerGroupID } from 'redux/interfaces/consumerGroup';
  6. import {
  7. ConsumerGroup,
  8. ConsumerGroupDetails,
  9. ConsumerGroupTopicPartition,
  10. } from 'generated-sources';
  11. import PageLoader from 'components/common/PageLoader/PageLoader';
  12. import ConfirmationModal from 'components/common/ConfirmationModal/ConfirmationModal';
  13. import { useHistory } from 'react-router';
  14. import ListItem from './ListItem';
  15. export interface Props extends ConsumerGroup, ConsumerGroupDetails {
  16. clusterName: ClusterName;
  17. consumers?: ConsumerGroupTopicPartition[];
  18. isFetched: boolean;
  19. isDeleted: boolean;
  20. fetchConsumerGroupDetails: (
  21. clusterName: ClusterName,
  22. consumerGroupID: ConsumerGroupID
  23. ) => void;
  24. deleteConsumerGroup: (clusterName: string, id: ConsumerGroupID) => void;
  25. }
  26. const Details: React.FC<Props> = ({
  27. clusterName,
  28. groupId,
  29. consumers,
  30. isFetched,
  31. isDeleted,
  32. fetchConsumerGroupDetails,
  33. deleteConsumerGroup,
  34. }) => {
  35. React.useEffect(() => {
  36. fetchConsumerGroupDetails(clusterName, groupId);
  37. }, [fetchConsumerGroupDetails, clusterName, groupId]);
  38. const items = consumers || [];
  39. const [isConfirmationModelVisible, setIsConfirmationModelVisible] =
  40. React.useState<boolean>(false);
  41. const history = useHistory();
  42. const onDelete = () => {
  43. setIsConfirmationModelVisible(false);
  44. deleteConsumerGroup(clusterName, groupId);
  45. };
  46. React.useEffect(() => {
  47. if (isDeleted) {
  48. history.push(clusterConsumerGroupsPath(clusterName));
  49. }
  50. }, [isDeleted]);
  51. return (
  52. <div className="section">
  53. <div className="level">
  54. <div className="level-item level-left">
  55. <Breadcrumb
  56. links={[
  57. {
  58. href: clusterConsumerGroupsPath(clusterName),
  59. label: 'All Consumer Groups',
  60. },
  61. ]}
  62. >
  63. {groupId}
  64. </Breadcrumb>
  65. </div>
  66. </div>
  67. {isFetched ? (
  68. <div className="box">
  69. <div className="level">
  70. <div className="level-item level-right buttons">
  71. <button
  72. type="button"
  73. className="button is-danger"
  74. onClick={() => setIsConfirmationModelVisible(true)}
  75. >
  76. Delete consumer group
  77. </button>
  78. </div>
  79. </div>
  80. <table className="table is-striped is-fullwidth">
  81. <thead>
  82. <tr>
  83. <th>Consumer ID</th>
  84. <th>Host</th>
  85. <th>Topic</th>
  86. <th>Partition</th>
  87. <th>Messages behind</th>
  88. <th>Current offset</th>
  89. <th>End offset</th>
  90. </tr>
  91. </thead>
  92. <tbody>
  93. {items.map((consumer) => (
  94. <ListItem
  95. key={consumer.consumerId}
  96. clusterName={clusterName}
  97. consumer={consumer}
  98. />
  99. ))}
  100. </tbody>
  101. </table>
  102. </div>
  103. ) : (
  104. <PageLoader />
  105. )}
  106. <ConfirmationModal
  107. isOpen={isConfirmationModelVisible}
  108. onCancel={() => setIsConfirmationModelVisible(false)}
  109. onConfirm={onDelete}
  110. >
  111. Are you sure you want to delete this consumer group?
  112. </ConfirmationModal>
  113. </div>
  114. );
  115. };
  116. export default Details;