TopicsTableCells.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import React from 'react';
  2. import { TopicWithDetailedInfo } from 'redux/interfaces';
  3. import { TableCellProps } from 'components/common/SmartTable/TableColumn';
  4. import { Tag } from 'components/common/Tag/Tag.styled';
  5. import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';
  6. import * as S from './List.styled';
  7. export const TitleCell: React.FC<
  8. TableCellProps<TopicWithDetailedInfo, string>
  9. > = ({ dataItem: { internal, name } }) => {
  10. return (
  11. <>
  12. {internal && <Tag color="gray">IN</Tag>}
  13. <S.Link to={name} $isInternal={internal}>
  14. {name}
  15. </S.Link>
  16. </>
  17. );
  18. };
  19. export const TopicSizeCell: React.FC<
  20. TableCellProps<TopicWithDetailedInfo, string>
  21. > = ({ dataItem: { segmentSize } }) => {
  22. return <BytesFormatted value={segmentSize} />;
  23. };
  24. export const OutOfSyncReplicasCell: React.FC<
  25. TableCellProps<TopicWithDetailedInfo, string>
  26. > = ({ dataItem: { partitions } }) => {
  27. const data = React.useMemo(() => {
  28. if (partitions === undefined || partitions.length === 0) {
  29. return 0;
  30. }
  31. return partitions.reduce((memo, { replicas }) => {
  32. const outOfSync = replicas?.filter(({ inSync }) => !inSync);
  33. return memo + (outOfSync?.length || 0);
  34. }, 0);
  35. }, [partitions]);
  36. return <span>{data}</span>;
  37. };
  38. export const MessagesCell: React.FC<
  39. TableCellProps<TopicWithDetailedInfo, string>
  40. > = ({ dataItem: { partitions } }) => {
  41. const data = React.useMemo(() => {
  42. if (partitions === undefined || partitions.length === 0) {
  43. return 0;
  44. }
  45. return partitions.reduce((memo, { offsetMax, offsetMin }) => {
  46. return memo + (offsetMax - offsetMin);
  47. }, 0);
  48. }, [partitions]);
  49. return <span>{data}</span>;
  50. };