Skip to content

Commit

Permalink
FE: Rename cursor to nextCursor in topic message response (kafbat#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadisfr committed Sep 17, 2024
1 parent 22da860 commit 55fc250
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions api/src/main/java/io/kafbat/ui/emitter/ConsumingStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.kafbat.ui.model.TopicMessageConsumingDTO;
import io.kafbat.ui.model.TopicMessageEventDTO;
import io.kafbat.ui.model.TopicMessageNextPageCursorDTO;
import io.kafbat.ui.model.TopicMessagePageCursorDTO;
import javax.annotation.Nullable;
import reactor.core.publisher.FluxSink;

Expand Down Expand Up @@ -32,9 +32,9 @@ void sendFinishEvent(FluxSink<TopicMessageEventDTO> sink, @Nullable Cursor.Track
sink.next(
new TopicMessageEventDTO()
.type(TopicMessageEventDTO.TypeEnum.DONE)
.cursor(
.nextCursor(
cursor != null
? new TopicMessageNextPageCursorDTO().id(cursor.registerCursor())
? new TopicMessagePageCursorDTO().id(cursor.registerCursor())
: null
)
.consuming(createConsumingStats())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ void cursorIsRegisteredAfterPollingIsDoneAndCanBeUsedForNextPagePolling(PollingM
null, null, pageSize, StringSerde.name(), StringSerde.name())
.doOnNext(evt -> {
if (evt.getType() == TopicMessageEventDTO.TypeEnum.DONE) {
assertThat(evt.getCursor()).isNotNull();
cursorIdCatcher.set(evt.getCursor().getId());
assertThat(evt.getNextCursor()).isNotNull();
cursorIdCatcher.set(evt.getNextCursor().getId());
}
})
.filter(evt -> evt.getType() == TopicMessageEventDTO.TypeEnum.MESSAGE)
Expand All @@ -147,7 +147,7 @@ void cursorIsRegisteredAfterPollingIsDoneAndCanBeUsedForNextPagePolling(PollingM
Flux<String> remainingMsgs = messagesService.loadMessages(cluster, testTopic, cursorIdCatcher.get())
.doOnNext(evt -> {
if (evt.getType() == TopicMessageEventDTO.TypeEnum.DONE) {
assertThat(evt.getCursor()).isNull();
assertThat(evt.getNextCursor()).isNull();
}
})
.filter(evt -> evt.getType() == TopicMessageEventDTO.TypeEnum.MESSAGE)
Expand Down
6 changes: 3 additions & 3 deletions contract/src/main/resources/swagger/kafbat-ui-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2954,8 +2954,8 @@ components:
$ref: "#/components/schemas/TopicMessagePhase"
consuming:
$ref: "#/components/schemas/TopicMessageConsuming"
cursor:
$ref: "#/components/schemas/TopicMessageNextPageCursor"
nextCursor:
$ref: "#/components/schemas/TopicMessagePageCursor"

TopicMessagePhase:
type: object
Expand Down Expand Up @@ -2985,7 +2985,7 @@ components:
filterApplyErrors:
type: integer

TopicMessageNextPageCursor:
TopicMessagePageCursor:
type: object
properties:
id:
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/lib/hooks/api/topicMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export const useTopicMessages = ({
}
const { nextCursor, setNextCursor } = useMessageFiltersStore.getState();


const searchParamPage = getPageValue(searchParams);
if (currentPage.current < searchParamPage && nextCursor) {
requestParams.set(MessagesFilterKeys.cursor, nextCursor);
Expand All @@ -125,11 +124,7 @@ export const useTopicMessages = ({
},
onmessage(event) {
const parsedData: TopicMessageEvent = JSON.parse(event.data);
const { message, consuming, cursor } = parsedData;

if (useMessageFiltersStore.getState().nextCursor !== cursor?.id) {
setNextCursor(cursor?.id || undefined);
}
const { message, consuming } = parsedData;

switch (parsedData.type) {
case TopicMessageEventTypeEnum.MESSAGE:
Expand All @@ -148,6 +143,11 @@ export const useTopicMessages = ({
case TopicMessageEventTypeEnum.CONSUMING:
if (consuming) setConsumptionStats(consuming);
break;
case TopicMessageEventTypeEnum.DONE:
if (nextCursor !== parsedData.nextCursor?.id) {
setNextCursor(parsedData.nextCursor?.id || undefined);
}
break;
default:
}
},
Expand Down

0 comments on commit 55fc250

Please sign in to comment.