Configs.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import React from 'react';
  2. import { CellContext, ColumnDef } from '@tanstack/react-table';
  3. import { ClusterBrokerParam } from 'lib/paths';
  4. import useAppParams from 'lib/hooks/useAppParams';
  5. import {
  6. useBrokerConfig,
  7. useUpdateBrokerConfigByName,
  8. } from 'lib/hooks/api/brokers';
  9. import Table from 'components/common/NewTable';
  10. import { BrokerConfig, ConfigSource } from 'generated-sources';
  11. import Search from 'components/common/Search/Search';
  12. import Tooltip from 'components/common/Tooltip/Tooltip';
  13. import InfoIcon from 'components/common/Icons/InfoIcon';
  14. import InputCell from './InputCell';
  15. import * as S from './Configs.styled';
  16. const tooltipContent = `DYNAMIC_TOPIC_CONFIG = dynamic topic config that is configured for a specific topic
  17. DYNAMIC_BROKER_LOGGER_CONFIG = dynamic broker logger config that is configured for a specific broker
  18. DYNAMIC_BROKER_CONFIG = dynamic broker config that is configured for a specific broker
  19. DYNAMIC_DEFAULT_BROKER_CONFIG = dynamic broker config that is configured as default for all brokers in the cluster
  20. STATIC_BROKER_CONFIG = static broker config provided as broker properties at start up (e.g. server.properties file)
  21. DEFAULT_CONFIG = built-in default configuration for configs that have a default value
  22. UNKNOWN = source unknown e.g. in the ConfigEntry used for alter requests where source is not set`;
  23. const Configs: React.FC = () => {
  24. const [keyword, setKeyword] = React.useState('');
  25. const { clusterName, brokerId } = useAppParams<ClusterBrokerParam>();
  26. const { data = [] } = useBrokerConfig(clusterName, Number(brokerId));
  27. const stateMutation = useUpdateBrokerConfigByName(
  28. clusterName,
  29. Number(brokerId)
  30. );
  31. const getData = () => {
  32. return data
  33. .filter(
  34. (item) =>
  35. item.name.toLocaleLowerCase().indexOf(keyword.toLocaleLowerCase()) >
  36. -1
  37. )
  38. .sort((a, b) => {
  39. if (a.source === b.source) return 0;
  40. return a.source === ConfigSource.DYNAMIC_BROKER_CONFIG ? -1 : 1;
  41. });
  42. };
  43. const dataSource = React.useMemo(() => getData(), [data, keyword]);
  44. const renderCell = (props: CellContext<BrokerConfig, unknown>) => (
  45. <InputCell
  46. {...props}
  47. onUpdate={(name, value) => {
  48. stateMutation.mutateAsync({
  49. name,
  50. brokerConfigItem: {
  51. value,
  52. },
  53. });
  54. }}
  55. />
  56. );
  57. const columns = React.useMemo<ColumnDef<BrokerConfig>[]>(
  58. () => [
  59. { header: 'Key', accessorKey: 'name' },
  60. {
  61. header: 'Value',
  62. accessorKey: 'value',
  63. cell: renderCell,
  64. },
  65. {
  66. // eslint-disable-next-line react/no-unstable-nested-components
  67. header: () => {
  68. return (
  69. <S.Source>
  70. Source
  71. <Tooltip
  72. value={<InfoIcon />}
  73. content={tooltipContent}
  74. placement="top-end"
  75. />
  76. </S.Source>
  77. );
  78. },
  79. accessorKey: 'source',
  80. },
  81. ],
  82. []
  83. );
  84. return (
  85. <>
  86. <S.SearchWrapper>
  87. <Search
  88. onChange={setKeyword}
  89. placeholder="Search by Key"
  90. value={keyword}
  91. />
  92. </S.SearchWrapper>
  93. <Table columns={columns} data={dataSource} />
  94. </>
  95. );
  96. };
  97. export default Configs;