Settings.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React from 'react';
  2. import { ClusterId, TopicName, TopicConfig } from 'redux/interfaces';
  3. interface Props {
  4. clusterId: ClusterId;
  5. topicName: TopicName;
  6. config?: TopicConfig[];
  7. isFetched: boolean;
  8. fetchTopicConfig: (clusterId: ClusterId, topicName: TopicName) => void;
  9. }
  10. const ConfigListItem: React.FC<TopicConfig> = ({
  11. name,
  12. value,
  13. defaultValue,
  14. }) => {
  15. const hasCustomValue = value !== defaultValue;
  16. return (
  17. <tr>
  18. <td className={hasCustomValue ? 'has-text-weight-bold' : ''}>
  19. {name}
  20. </td>
  21. <td className={hasCustomValue ? 'has-text-weight-bold' : ''}>
  22. {value}
  23. </td>
  24. <td
  25. className="has-text-grey"
  26. title="Default Value"
  27. >
  28. {hasCustomValue && defaultValue}
  29. </td>
  30. </tr>
  31. )
  32. }
  33. const Sertings: React.FC<Props> = ({
  34. clusterId,
  35. topicName,
  36. isFetched,
  37. fetchTopicConfig,
  38. config,
  39. }) => {
  40. React.useEffect(
  41. () => { fetchTopicConfig(clusterId, topicName); },
  42. [fetchTopicConfig, clusterId, topicName],
  43. );
  44. if (!isFetched || !config) {
  45. return (null);
  46. }
  47. return (
  48. <div className="box">
  49. <table className="table is-striped is-fullwidth">
  50. <thead>
  51. <tr>
  52. <th>Key</th>
  53. <th>Value</th>
  54. <th>Default Value</th>
  55. </tr>
  56. </thead>
  57. <tbody>
  58. {config.map((item, index) => <ConfigListItem key={`config-list-item-key-${index}`} {...item} />)}
  59. </tbody>
  60. </table>
  61. </div>
  62. );
  63. }
  64. export default Sertings;