Skip to content

Commit

Permalink
Merge pull request #39 from tzachshabtay/pagination
Browse files Browse the repository at this point in the history
added pagination to message query
  • Loading branch information
tzachshabtay authored Oct 23, 2020
2 parents 31306c3 + 801930a commit f0d68df
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/client/kafka/messages/single_topic_input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,33 @@ export class SingleTopicInput extends React.Component<Props, State> {
this.setState({ loadingMessages: true })
this.props.onDataFetchStarted()
const topic = this.props.topic
const response = await fetch(`/api/messages/${topic}/${this.state.partition}?limit=${this.state.limit}&offset=${this.state.offset}&search=${this.props.search}&timeout=${timeout}`)
const data = await response.json()
this.props.onDataFetched(data)
let cursor = this.state.offset
const end = cursor + this.state.limit
let out: any = null
let limit = this.state.limit
if (limit > 1000) {
limit = 1000
}
while (cursor < end) {
const response = await fetch(`/api/messages/${topic}/${this.state.partition}?limit=${limit}&offset=${cursor}&search=${this.props.search}&timeout=${timeout}`)
cursor += limit
const data = await response.json()
if (!out) {
out = data
} else if (data.messages) {
out.messages = [...out.messages, ...data.messages]
}
if (data.error) {
out.error = data.error
}
if (data.hasTimeout) {
out.hasTimeout = data.hasTimeout
}
this.props.onDataFetched(out)
if (out.error || out.hasTimeout) {
break
}
}
this.setState({loadingMessages: false})
}

Expand Down

0 comments on commit f0d68df

Please sign in to comment.