Skip to content

Commit

Permalink
feat(ui): adds view to delete all consumer group offsets for given to…
Browse files Browse the repository at this point in the history
…pic (tchiotludo#790)

Co-authored-by: Fabian Besner <[email protected]>
  • Loading branch information
IngoStrauch2020 and FabianBesner2020 committed Mar 17, 2022
1 parent f23133f commit 0f78e8a
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,26 @@ class ConsumerGroup extends Component {
</div>
</div>

{roles.group && roles.group['group/offsets/update'] && (
{roles.group && (roles.group['group/offsets/delete'] || roles.group['group/offsets/update']) && (
<aside>
<Link
to={`/ui/${clusterId}/group/${consumerGroupId}/offsets`}
className="btn btn-primary"
>
Update Offsets
</Link>
<li className="aside-button">
{roles.group['group/offsets/delete'] && (
<Link
to={`/ui/${clusterId}/group/${consumerGroupId}/offsetsdelete`}
className="btn btn-secondary mr-2"
>
Delete Offsets
</Link>
)}
{roles.group['group/offsets/update'] && (
<Link
to={`/ui/${clusterId}/group/${consumerGroupId}/offsets`}
className="btn btn-primary"
>
Update Offsets
</Link>
)}
</li>
</aside>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import React from 'react';
import Header from '../../../Header/Header';
import {
uriConsumerGroup, uriDeleteGroupOffsets,
} from '../../../../utils/endpoints';
import 'react-toastify/dist/ReactToastify.css';
import Root from "../../../../components/Root";
import Table from "../../../../components/Table";
import constants from "../../../../utils/constants";
import ConfirmModal from "../../../../components/Modal/ConfirmModal";
import {toast} from "react-toastify";

class ConsumerGroupOffsetDelete extends Root {
state = {
clusterId: '',
consumerGroupId: '',
topicIds: [],
deleteAllOffsetsForTopic: '',
showDeleteModal: false,
deleteMessage: '',
};

componentDidMount() {
const {clusterId, consumerGroupId} = this.props.match.params;

this.setState({clusterId, consumerGroupId}, () => {
this.getTopics();
});
}

async getTopics() {
const { clusterId, consumerGroupId } = this.state;

let data;
data = await this.getApi(uriConsumerGroup(clusterId, consumerGroupId));
data = data.data;

if (data && data.topics) {
this.setState({ topicIds: data.topics.map(topic => ({ topic })) });
} else {
this.setState({ topicIds: [] });
}
}

showDeleteModal = deleteMessage => {
this.setState({ showDeleteModal: true, deleteMessage });
};

closeDeleteModal = () => {
this.setState({ showDeleteModal: false, deleteMessage: '', deleteAllOffsetsForTopic: '' });
};

deleteOffsets = () => {
const { clusterId, consumerGroupId, deleteAllOffsetsForTopic } = this.state;
this.removeApi(uriDeleteGroupOffsets(clusterId, consumerGroupId, deleteAllOffsetsForTopic))
.then(() => {
toast.success(`Offsets for topic '${deleteAllOffsetsForTopic}' and consumer group '${consumerGroupId}' are deleted`);
this.setState({ showDeleteModal: false, deleteMessage: '', deleteAllOffsetsForTopic: '' }, () => {
this.getTopics();
});
})
.catch(() => {
this.setState({ showDeleteModal: false, deleteMessage: '', deleteAllOffsetsForTopic: '' });
});
}

handleOnDelete(topicId) {
this.setState({ deleteAllOffsetsForTopic: topicId }, () => {
this.showDeleteModal(
<React.Fragment>
Do you want to delete all offsets of topic: {<code>{topicId}</code>} ?
</React.Fragment>
);
});
}

render() {
const {consumerGroupId} = this.state;

return (
<div>
<div>
<Header title={`Delete offsets: ${consumerGroupId}`}
history={this.props.history}/>
</div>
<div>
<Table
history={this.props.history}
columns={[
{
id: 'topic',
accessor: 'topic',
colName: 'Topic',
type: 'text',
sortable: true
},
]}
data={this.state.topicIds}
noContent={
<tr>
<td colSpan={3}>
<div className="alert alert-warning mb-0" role="alert">
No offsets found.
</div>
</td>
</tr>
}
onDelete={(row) => {
this.handleOnDelete(row.topic)
}}
actions={
[constants.TABLE_DELETE]
}
/>
</div>
<ConfirmModal
show={this.state.showDeleteModal}
handleCancel={this.closeDeleteModal}
handleConfirm={this.deleteOffsets}
message={this.state.deleteMessage}
/>
</div>
);
}
}

export default ConsumerGroupOffsetDelete;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ConsumerGroupOffsetDelete from './ConsumerGroupOffsetDelete';

export default ConsumerGroupOffsetDelete;
9 changes: 9 additions & 0 deletions client/src/utils/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Schema from '../containers/Schema/SchemaDetail/Schema';
import SchemaList from '../containers/Schema/SchemaList/SchemaList';
import SchemaCreate from '../containers/Schema/SchemaCreate/SchemaCreate';
import ConsumerGroupUpdate from '../containers/ConsumerGroup/ConsumerGroupDetail/ConsumerGroupUpdate';
import ConsumerGroupOffsetDelete from '../containers/ConsumerGroup/ConsumerGroupDetail/ConsumerGroupOffsetDelete';
import AclDetails from '../containers/Acl/AclDetail';
import Login from '../containers/Login';
import Settings from '../containers/Settings/Settings';
Expand Down Expand Up @@ -185,6 +186,14 @@ class Routes extends Root {
<Route exact path="/ui/:clusterId/group" component={ConsumerGroupList} />
)}

{roles && roles.group && roles.group['group/offsets/delete'] && (
<Route
exact
path="/ui/:clusterId/group/:consumerGroupId/offsetsdelete"
component={ConsumerGroupOffsetDelete}
/>
)}

{roles && roles.group && roles.group['group/offsets/update'] && (
<Route
exact
Expand Down
7 changes: 6 additions & 1 deletion client/src/utils/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ export const uriConsumerGroupUpdate = (clusterId, groupId) => {
return `${apiUrl}/${clusterId}/group/${groupId}/offsets`;
};

export const uriDeleteGroupOffsets = (clusterId, groupId, topicName) => {
return `${apiUrl}/${clusterId}/group/${groupId}/topic/${topicName}`;
};

export const uriAclsList = (clusterId, search) => {
let url = `${apiUrl}/${clusterId}/acls`;
return search ? `${url}?search=${search}` : url;
Expand Down Expand Up @@ -343,5 +347,6 @@ export default {
uriAclsByPrincipal,
uriLiveTail,
uriTopicDataSearch,
uriTopicDataDelete
uriTopicDataDelete,
uriDeleteGroupOffsets
};

0 comments on commit 0f78e8a

Please sign in to comment.