List.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import React from 'react';
  2. import { ClusterNameRoute, clusterSchemaNewRelativePath } from 'lib/paths';
  3. import ClusterContext from 'components/contexts/ClusterContext';
  4. import * as C from 'components/common/table/Table/Table.styled';
  5. import TableHeaderCell from 'components/common/table/TableHeaderCell/TableHeaderCell';
  6. import { Button } from 'components/common/Button/Button';
  7. import PageHeading from 'components/common/PageHeading/PageHeading';
  8. import { useAppDispatch, useAppSelector } from 'lib/hooks/redux';
  9. import useAppParams from 'lib/hooks/useAppParams';
  10. import {
  11. selectAllSchemas,
  12. fetchSchemas,
  13. getAreSchemasFulfilled,
  14. SCHEMAS_FETCH_ACTION,
  15. } from 'redux/reducers/schemas/schemasSlice';
  16. import usePagination from 'lib/hooks/usePagination';
  17. import PageLoader from 'components/common/PageLoader/PageLoader';
  18. import Pagination from 'components/common/Pagination/Pagination';
  19. import { resetLoaderById } from 'redux/reducers/loader/loaderSlice';
  20. import { ControlPanelWrapper } from 'components/common/ControlPanel/ControlPanel.styled';
  21. import Search from 'components/common/Search/Search';
  22. import useSearch from 'lib/hooks/useSearch';
  23. import ListItem from './ListItem';
  24. import GlobalSchemaSelector from './GlobalSchemaSelector/GlobalSchemaSelector';
  25. const List: React.FC = () => {
  26. const dispatch = useAppDispatch();
  27. const { isReadOnly } = React.useContext(ClusterContext);
  28. const { clusterName } = useAppParams<ClusterNameRoute>();
  29. const schemas = useAppSelector(selectAllSchemas);
  30. const isFetched = useAppSelector(getAreSchemasFulfilled);
  31. const totalPages = useAppSelector((state) => state.schemas.totalPages);
  32. const [searchText, handleSearchText] = useSearch();
  33. const { page, perPage } = usePagination();
  34. React.useEffect(() => {
  35. dispatch(fetchSchemas({ clusterName, page, perPage, search: searchText }));
  36. return () => {
  37. dispatch(resetLoaderById(SCHEMAS_FETCH_ACTION));
  38. };
  39. }, [clusterName, dispatch, page, perPage, searchText]);
  40. return (
  41. <>
  42. <PageHeading text="Schema Registry">
  43. {!isReadOnly && (
  44. <>
  45. <GlobalSchemaSelector />
  46. <Button
  47. buttonSize="M"
  48. buttonType="primary"
  49. to={clusterSchemaNewRelativePath}
  50. >
  51. <i className="fas fa-plus" /> Create Schema
  52. </Button>
  53. </>
  54. )}
  55. </PageHeading>
  56. <ControlPanelWrapper hasInput>
  57. <Search
  58. placeholder="Search by Schema Name"
  59. value={searchText}
  60. handleSearch={handleSearchText}
  61. />
  62. </ControlPanelWrapper>
  63. {isFetched ? (
  64. <>
  65. <C.Table isFullwidth>
  66. <thead>
  67. <tr>
  68. <TableHeaderCell title="Schema Name" />
  69. <TableHeaderCell title="Version" />
  70. <TableHeaderCell title="Compatibility" />
  71. </tr>
  72. </thead>
  73. <tbody>
  74. {schemas.length === 0 && (
  75. <tr>
  76. <td colSpan={10}>No schemas found</td>
  77. </tr>
  78. )}
  79. {schemas.map((subject) => (
  80. <ListItem
  81. key={[subject.id, subject.subject].join('-')}
  82. subject={subject}
  83. />
  84. ))}
  85. </tbody>
  86. </C.Table>
  87. <Pagination totalPages={totalPages} />
  88. </>
  89. ) : (
  90. <PageLoader />
  91. )}
  92. </>
  93. );
  94. };
  95. export default List;