Skip to content

Commit b216e44

Browse files
fix(api-mock): Add sorting for consumer groups by group id (#99)
1 parent e52cb04 commit b216e44

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/api-mock/src/handlers/kafka-admin.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ module.exports = {
55
getConsumerGroups: async (c, req, res) => {
66
let consumerGroupList = consumerGroups;
77
let count = consumerGroups !== undefined ? consumerGroups.length : 0;
8+
9+
let order = req.query.order || 'asc';
10+
let orderKey = req.query.orderKey;
11+
12+
if(orderKey=='name') {
13+
order === 'asc' ? consumerGroups.sort(compareGroupId) : consumerGroups.sort((a, b) => compareGroupId(b, a));
14+
}
815

916
const filteredConsumerGroups = () => {
1017
let regexp = new RegExp(`${req.query['group-id-filter'].trim()}`,`i`);
@@ -14,7 +21,7 @@ module.exports = {
1421
consumerGroupList = filteredConsumerGroups();
1522
count = consumerGroupList.length;
1623
}
17-
24+
1825
const filterConsumerGroups = (topicName) => {
1926
return consumerGroupList.filter((consumerGroup) => {
2027
return consumerGroup.consumers.some(
@@ -269,6 +276,12 @@ function compareName(a, b) {
269276
return 0;
270277
}
271278

279+
function compareGroupId(a, b) {
280+
if (a.groupId < b.groupId) return -1;
281+
if (a.groupId > b.groupId) return 1;
282+
return 0;
283+
}
284+
272285
function comparePartitions(a, b) {
273286
if (a.partitions.length < b.partitions.length) return -1;
274287
if (a.partitions.length > b.partitions.length) return 1;

0 commit comments

Comments
 (0)