Skip to content

Commit

Permalink
fix(ui): follow default topic configuration during topic creation (tc…
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDangleterre authored Dec 4, 2021
1 parent 3576c6c commit 6e9cc67
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
17 changes: 16 additions & 1 deletion client/src/containers/Topic/TopicCreate/TopicCreate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Joi from 'joi-browser';
import { withRouter } from 'react-router-dom';
import Form from '../../../components/Form/Form';
import Header from '../../Header';
import { uriTopicsCreate } from '../../../utils/endpoints';
import { uriTopicsCreate, uriTopicDefaultConf } from '../../../utils/endpoints';
import { toast } from 'react-toastify';

class TopicCreate extends Form {
Expand All @@ -18,6 +18,21 @@ class TopicCreate extends Form {
errors: {}
};

componentDidMount() {
this.getTopicDefaultConf();
}

async getTopicDefaultConf() {
let { formData } = { ...this.state }
const defaults = await this.getApi(uriTopicDefaultConf());

formData.retention = defaults.data.retention
formData.partition = defaults.data.partition
formData.replication = defaults.data.replication

this.setState({ formData });
}

schema = {
name: Joi.string()
.required()
Expand Down
2 changes: 2 additions & 0 deletions client/src/utils/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const uriTopics = (clusterId, search, show, page) => {
return `${apiUrl}/${clusterId}/topic?search=${search}&show=${show}&page=${page}`;
};

export const uriTopicDefaultConf = () => `${apiUrl}/topic/defaults-configs`;

export const uriTopicsName = (clusterId) => `${apiUrl}/${clusterId}/topic/name`;

export const uriTopicsInfo = (clusterId, topicId) => `${apiUrl}/${clusterId}/topic/${topicId}`;
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/akhq/controllers/TopicController.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,21 @@ public class TopicController extends AbstractController {
private Short replicationFactor;
@Value("${akhq.topic.partition}")
private Integer partitionCount;
@Value("${akhq.topic.retention}")
private Integer retention;
@Value("${akhq.pagination.page-size}")
private Integer pageSize;

@Get ("api/topic/defaults-configs")
@Operation(tags = {"topic"}, summary = "Get default topic configuration")
public Map<String,Integer> getDefaultConf(){
return Map.of(
"replication", replicationFactor.intValue(),
"partition", partitionCount,
"retention", retention
);
}

@Get("api/{cluster}/topic")
@Operation(tags = {"topic"}, summary = "List all topics")
public ResultPagedList<Topic> list(
Expand Down Expand Up @@ -509,4 +521,4 @@ public static class OffsetCopy {
private long offset;
}
}

12 changes: 12 additions & 0 deletions src/test/java/org/akhq/controllers/TopicControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class TopicControllerTest extends AbstractTest {
public static final String BASE_URL = "/api/" + KafkaTestCluster.CLUSTER_ID + "/topic";
public static final String DEFAULTS_CONFIGS_URL = "api/topic/defaults-configs";
public static final String TOPIC_URL = BASE_URL + "/" + KafkaTestCluster.TOPIC_COMPACTED;
public static final String CREATE_TOPIC_NAME = UUID.randomUUID().toString();
public static final String CREATE_TOPIC_URL = BASE_URL + "/" + CREATE_TOPIC_NAME;

@Test
@Order(1)
void defaultsConfigsApi(){
Map<String,Integer> result = this.retrieve(HttpRequest.GET(DEFAULTS_CONFIGS_URL), Map.class);

assertEquals(1, result.get("replication"));
assertEquals(86400000, result.get("retention"));
assertEquals(1, result.get("partition"));
}


@Test
@Order(1)
void listApi() {
Expand Down

0 comments on commit 6e9cc67

Please sign in to comment.