EditContainer.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { connect } from 'react-redux';
  2. import {
  3. RootState,
  4. ClusterName,
  5. TopicFormData,
  6. TopicName,
  7. Action,
  8. } from 'redux/interfaces';
  9. import { withRouter, RouteComponentProps } from 'react-router-dom';
  10. import {
  11. updateTopic,
  12. fetchTopicConfig,
  13. fetchTopicDetails,
  14. } from 'redux/actions';
  15. import {
  16. getTopicConfigFetched,
  17. getTopicUpdated,
  18. getIsTopicDetailsFetched,
  19. getFullTopic,
  20. } from 'redux/reducers/topics/selectors';
  21. import { clusterTopicPath } from 'lib/paths';
  22. import { ThunkDispatch } from 'redux-thunk';
  23. import Edit from './Edit';
  24. interface RouteProps {
  25. clusterName: ClusterName;
  26. topicName: TopicName;
  27. }
  28. type OwnProps = RouteComponentProps<RouteProps>;
  29. const mapStateToProps = (
  30. state: RootState,
  31. {
  32. match: {
  33. params: { topicName, clusterName },
  34. },
  35. }: OwnProps
  36. ) => ({
  37. clusterName,
  38. topicName,
  39. topic: getFullTopic(state, topicName),
  40. isFetched: getTopicConfigFetched(state),
  41. isTopicDetailsFetched: getIsTopicDetailsFetched(state),
  42. isTopicUpdated: getTopicUpdated(state),
  43. });
  44. const mapDispatchToProps = (
  45. dispatch: ThunkDispatch<RootState, undefined, Action>,
  46. { history }: OwnProps
  47. ) => ({
  48. fetchTopicDetails: (clusterName: ClusterName, topicName: TopicName) =>
  49. dispatch(fetchTopicDetails(clusterName, topicName)),
  50. fetchTopicConfig: (clusterName: ClusterName, topicName: TopicName) =>
  51. dispatch(fetchTopicConfig(clusterName, topicName)),
  52. updateTopic: (clusterName: ClusterName, form: TopicFormData) =>
  53. dispatch(updateTopic(clusterName, form)),
  54. redirectToTopicPath: (clusterName: ClusterName, topicName: TopicName) => {
  55. history.push(clusterTopicPath(clusterName, topicName));
  56. },
  57. });
  58. export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Edit));