List.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import React from 'react';
  2. import PageHeading from 'components/common/PageHeading/PageHeading';
  3. import Search from 'components/common/Search/Search';
  4. import { ControlPanelWrapper } from 'components/common/ControlPanel/ControlPanel.styled';
  5. import {
  6. ConsumerGroupDetails,
  7. ConsumerGroupOrdering,
  8. SortOrder,
  9. } from 'generated-sources';
  10. import { useTableState } from 'lib/hooks/useTableState';
  11. import { SmartTable } from 'components/common/SmartTable/SmartTable';
  12. import { TableColumn } from 'components/common/SmartTable/TableColumn';
  13. import {
  14. GroupIDCell,
  15. StatusCell,
  16. } from 'components/ConsumerGroups/List/ConsumerGroupsTableCells';
  17. import usePagination from 'lib/hooks/usePagination';
  18. import useSearch from 'lib/hooks/useSearch';
  19. import { useAppDispatch } from 'lib/hooks/redux';
  20. import useAppParams from 'lib/hooks/useAppParams';
  21. import { ClusterNameRoute } from 'lib/paths';
  22. import { fetchConsumerGroupsPaged } from 'redux/reducers/consumerGroups/consumerGroupsSlice';
  23. import PageLoader from 'components/common/PageLoader/PageLoader';
  24. export interface Props {
  25. consumerGroups: ConsumerGroupDetails[];
  26. orderBy: string | null;
  27. sortOrder: SortOrder;
  28. totalPages: number;
  29. isFetched: boolean;
  30. setConsumerGroupsSortOrderBy(orderBy: string | null): void;
  31. }
  32. const List: React.FC<Props> = ({
  33. consumerGroups,
  34. sortOrder,
  35. orderBy,
  36. totalPages,
  37. isFetched,
  38. setConsumerGroupsSortOrderBy,
  39. }) => {
  40. const { page, perPage } = usePagination();
  41. const [searchText, handleSearchText] = useSearch();
  42. const dispatch = useAppDispatch();
  43. const { clusterName } = useAppParams<ClusterNameRoute>();
  44. React.useEffect(() => {
  45. dispatch(
  46. fetchConsumerGroupsPaged({
  47. clusterName,
  48. orderBy: (orderBy as ConsumerGroupOrdering) || undefined,
  49. sortOrder,
  50. page,
  51. perPage,
  52. search: searchText,
  53. })
  54. );
  55. }, [clusterName, orderBy, searchText, sortOrder, page, perPage, dispatch]);
  56. const tableState = useTableState<ConsumerGroupDetails, string>(
  57. consumerGroups,
  58. {
  59. totalPages,
  60. idSelector: (consumerGroup) => consumerGroup.groupId,
  61. },
  62. {
  63. handleOrderBy: setConsumerGroupsSortOrderBy,
  64. orderBy,
  65. sortOrder,
  66. }
  67. );
  68. if (!isFetched) {
  69. return <PageLoader />;
  70. }
  71. return (
  72. <div>
  73. <PageHeading text="Consumers" />
  74. <ControlPanelWrapper hasInput>
  75. <Search
  76. placeholder="Search by Consumer Group ID"
  77. value={searchText}
  78. handleSearch={handleSearchText}
  79. />
  80. </ControlPanelWrapper>
  81. <SmartTable
  82. tableState={tableState}
  83. isFullwidth
  84. placeholder="No active consumer groups"
  85. hoverable
  86. paginated
  87. >
  88. <TableColumn
  89. title="Consumer Group ID"
  90. cell={GroupIDCell}
  91. orderValue={ConsumerGroupOrdering.NAME}
  92. />
  93. <TableColumn
  94. title="Num Of Members"
  95. field="members"
  96. orderValue={ConsumerGroupOrdering.MEMBERS}
  97. />
  98. <TableColumn title="Num Of Topics" field="topics" />
  99. <TableColumn title="Messages Behind" field="messagesBehind" />
  100. <TableColumn title="Coordinator" field="coordinator.id" />
  101. <TableColumn
  102. title="State"
  103. cell={StatusCell}
  104. orderValue={ConsumerGroupOrdering.STATE}
  105. />
  106. </SmartTable>
  107. </div>
  108. );
  109. };
  110. export default List;