Details.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import React from 'react';
  2. import { ClusterName, TopicName } from 'redux/interfaces';
  3. import { Topic, TopicDetails } from 'generated-sources';
  4. import { NavLink, Switch, Route, Link, useHistory } from 'react-router-dom';
  5. import {
  6. clusterTopicSettingsPath,
  7. clusterTopicPath,
  8. clusterTopicMessagesPath,
  9. clusterTopicsPath,
  10. clusterTopicEditPath,
  11. } from 'lib/paths';
  12. import ClusterContext from 'components/contexts/ClusterContext';
  13. import ConfirmationModal from 'components/common/ConfirmationModal/ConfirmationModal';
  14. import OverviewContainer from './Overview/OverviewContainer';
  15. import MessagesContainer from './Messages/MessagesContainer';
  16. import SettingsContainer from './Settings/SettingsContainer';
  17. interface Props extends Topic, TopicDetails {
  18. clusterName: ClusterName;
  19. topicName: TopicName;
  20. deleteTopic: (clusterName: ClusterName, topicName: TopicName) => void;
  21. clearTopicMessages(clusterName: ClusterName, topicName: TopicName): void;
  22. }
  23. const Details: React.FC<Props> = ({
  24. clusterName,
  25. topicName,
  26. deleteTopic,
  27. clearTopicMessages,
  28. }) => {
  29. const history = useHistory();
  30. const { isReadOnly } = React.useContext(ClusterContext);
  31. const [
  32. isDeleteTopicConfirmationVisible,
  33. setDeleteTopicConfirmationVisible,
  34. ] = React.useState(false);
  35. const deleteTopicHandler = React.useCallback(() => {
  36. deleteTopic(clusterName, topicName);
  37. history.push(clusterTopicsPath(clusterName));
  38. }, [clusterName, topicName]);
  39. const clearTopicMessagesHandler = React.useCallback(() => {
  40. clearTopicMessages(clusterName, topicName);
  41. }, [clusterName, topicName]);
  42. return (
  43. <div className="box">
  44. <nav className="navbar" role="navigation">
  45. <div className="navbar-start">
  46. <NavLink
  47. exact
  48. to={clusterTopicPath(clusterName, topicName)}
  49. className="navbar-item is-tab"
  50. activeClassName="is-active is-primary"
  51. >
  52. Overview
  53. </NavLink>
  54. <NavLink
  55. exact
  56. to={clusterTopicMessagesPath(clusterName, topicName)}
  57. className="navbar-item is-tab"
  58. activeClassName="is-active"
  59. >
  60. Messages
  61. </NavLink>
  62. <NavLink
  63. exact
  64. to={clusterTopicSettingsPath(clusterName, topicName)}
  65. className="navbar-item is-tab"
  66. activeClassName="is-active"
  67. >
  68. Settings
  69. </NavLink>
  70. </div>
  71. <div className="navbar-end">
  72. <div className="buttons">
  73. {!isReadOnly && (
  74. <>
  75. <button
  76. type="button"
  77. className="button is-danger"
  78. onClick={clearTopicMessagesHandler}
  79. >
  80. Clear All Messages
  81. </button>
  82. <button
  83. className="button is-danger"
  84. type="button"
  85. onClick={() => setDeleteTopicConfirmationVisible(true)}
  86. >
  87. Delete Topic
  88. </button>
  89. <Link
  90. to={clusterTopicEditPath(clusterName, topicName)}
  91. className="button"
  92. >
  93. Edit settings
  94. </Link>
  95. <ConfirmationModal
  96. isOpen={isDeleteTopicConfirmationVisible}
  97. onCancel={() => setDeleteTopicConfirmationVisible(false)}
  98. onConfirm={deleteTopicHandler}
  99. >
  100. Are you sure want to remove <b>{topicName}</b> topic?
  101. </ConfirmationModal>
  102. </>
  103. )}
  104. </div>
  105. </div>
  106. </nav>
  107. <br />
  108. <Switch>
  109. <Route
  110. exact
  111. path="/ui/clusters/:clusterName/topics/:topicName/messages"
  112. component={MessagesContainer}
  113. />
  114. <Route
  115. exact
  116. path="/ui/clusters/:clusterName/topics/:topicName/settings"
  117. component={SettingsContainer}
  118. />
  119. <Route
  120. exact
  121. path="/ui/clusters/:clusterName/topics/:topicName"
  122. component={OverviewContainer}
  123. />
  124. </Switch>
  125. </div>
  126. );
  127. };
  128. export default Details;