|
| 1 | +import React from 'react'; |
| 2 | +import Joi from 'joi-browser'; |
| 3 | +import { withRouter } from 'react-router-dom'; |
| 4 | +import Form from '../../../../components/Form/Form'; |
| 5 | +import Header from '../../../Header'; |
| 6 | +import { uriTopicIncreasePartition } from '../../../../utils/endpoints'; |
| 7 | +import { toast } from 'react-toastify'; |
| 8 | + |
| 9 | +class TopicIncreasePartition extends Form { |
| 10 | + state = { |
| 11 | + formData: { |
| 12 | + partition: 1 |
| 13 | + }, |
| 14 | + selectedCluster: this.props.match.params.clusterId, |
| 15 | + selectedTopic: this.props.match.params.topicId, |
| 16 | + errors: {} |
| 17 | + }; |
| 18 | + |
| 19 | + componentDidMount() { |
| 20 | + this.getTopicsPartitions(); |
| 21 | + } |
| 22 | + |
| 23 | + async getTopicsPartitions() { |
| 24 | + const { selectedCluster, selectedTopic } = this.state; |
| 25 | + |
| 26 | + let partitions = await this.getApi(uriTopicIncreasePartition(selectedCluster, selectedTopic)); |
| 27 | + let form = {}; |
| 28 | + form.partition = partitions.data.length; |
| 29 | + this.setState({ formData: form }); |
| 30 | + } |
| 31 | + |
| 32 | + schema = { |
| 33 | + partition: Joi.number().min(1).label('Partition').required() |
| 34 | + }; |
| 35 | + |
| 36 | + async doSubmit() { |
| 37 | + const { formData, selectedCluster, selectedTopic } = this.state; |
| 38 | + const partitionData = { |
| 39 | + partition: formData.partition |
| 40 | + }; |
| 41 | + |
| 42 | + this.postApi(uriTopicIncreasePartition(selectedCluster, selectedTopic), partitionData) |
| 43 | + .then(() => { |
| 44 | + this.props.history.push({ |
| 45 | + pathname: `/ui/${selectedCluster}/topic` |
| 46 | + }); |
| 47 | + toast.success('Topic partition updated'); |
| 48 | + }) |
| 49 | + .catch(error => toast.error(error.data.message)); |
| 50 | + } |
| 51 | + render() { |
| 52 | + return ( |
| 53 | + <div> |
| 54 | + <form |
| 55 | + encType="multipart/form-data" |
| 56 | + className="khq-form khq-form-config" |
| 57 | + onSubmit={() => this.doSubmit()} |
| 58 | + > |
| 59 | + <Header title="Increase topic partition" history={this.props.history} /> |
| 60 | + {this.renderInput('partition', 'Partition', 'Partition', 'number')} |
| 61 | + {this.renderButton( |
| 62 | + 'Update', |
| 63 | + () => { |
| 64 | + this.doSubmit(); |
| 65 | + }, |
| 66 | + undefined, |
| 67 | + 'button' |
| 68 | + )} |
| 69 | + </form> |
| 70 | + </div> |
| 71 | + ); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +export default withRouter(TopicIncreasePartition); |
0 commit comments