Skip to content

Commit

Permalink
fix(ui): fix live tail of topic
Browse files Browse the repository at this point in the history
close #600
  • Loading branch information
tchiotludo committed Oct 24, 2021
1 parent 3217252 commit 2983e61
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
9 changes: 7 additions & 2 deletions client/src/components/Table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,15 @@ class Table extends Component {
}

render() {
const { noStripes, loading } = this.props;
const { noStripes, loading, rowId } = this.props;
let allItemRows = [];
let data = this.props.data || [];

data.forEach((item, index) => {
if (rowId !== undefined) {
index = rowId(item);
}

if (!item.id) {
item.id = index;
}
Expand Down Expand Up @@ -481,7 +485,8 @@ Table.propTypes = {
handleExtraExpand: PropTypes.func,
handleExtraCollapse: PropTypes.func,
loading: PropTypes.bool,
history: PropTypes.object
history: PropTypes.object,
rowId: PropTypes.func,
};

export default Table;
36 changes: 28 additions & 8 deletions client/src/containers/Tail/Tail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import AceEditor from 'react-ace';
import 'ace-builds/webpack-resolver';
import 'ace-builds/src-noconflict/mode-json';
import 'ace-builds/src-noconflict/theme-merbivore_soft';
import Root from "../../components/Root";
import Root from '../../components/Root';

const STATUS = {
STOPPED: 'STOPPED',
Expand Down Expand Up @@ -77,13 +77,16 @@ class Tail extends Root {
let res = JSON.parse(e.data);
let { data } = self.state;


if (res.records) {
data.push(res.records[0]);
data = data.concat(res.records);
if (data.length > maxRecords) {
data = data.slice(data.length - maxRecords);
}
}
self.setState({ data });

self.setState({ data: data });
self.scrollToBottom();
});

this.eventSource.onerror = e => {
Expand All @@ -99,6 +102,15 @@ class Tail extends Root {
this.startEventSource();
};

scrollToBottom = () => {
const followScroll = (document.body.scrollTop || document.documentElement.scrollTop) + window.innerHeight >=
(document.documentElement.scrollHeight - document.documentElement.clientHeight)

if (followScroll) {
this.messagesEnd.scrollIntoView({ behavior: 'smooth' });
}
}

handleChange = e => {
this.setState({ [e.target.name]: [e.target.value] });
};
Expand Down Expand Up @@ -184,11 +196,12 @@ class Tail extends Root {
data,
showFilters
} = this.state;

return (
<div>
<Header title="Live Tail" history={this.props.history} />
<nav
className="navbar navbar-expand-lg navbar-light
className="navbar navbar-expand-lg navbar-light
bg-light mr-auto khq-data-filter khq-sticky khq-nav"
>
<button
Expand Down Expand Up @@ -363,12 +376,18 @@ class Tail extends Root {
{selectedStatus !== STATUS.STOPPED && (
<Table
history={this.props.history}
rowId={data => {
return data.topic.name + '-' + data.partition + '-' + data.offset;
}}
columns={[
{
id: 'topic',
accessor: 'topic',
colName: 'Topic',
type: 'text'
type: 'text',
cell: obj => {
return obj.topic.name;
}
},
{
id: 'key',
Expand All @@ -385,8 +404,7 @@ class Tail extends Root {
colName: 'Date',
type: 'text',
cell: obj => {
let date = obj.timestamp.split('T')[0];
return <div className="tail-headers">{date}</div>;
return <div className="tail-headers">{obj.timestamp}</div>;
}
},
{
Expand Down Expand Up @@ -448,7 +466,7 @@ class Tail extends Root {
noStripes
data={data}
updateData={data => {
this.setState({ data });
this.setState({ data: data });
}}
noContent={<tr />}
onExpand={obj => {
Expand Down Expand Up @@ -489,6 +507,8 @@ class Tail extends Root {
}}
/>
)}
<div ref={(el) => { this.messagesEnd = el; }}>
</div>
</div>
);
}
Expand Down

0 comments on commit 2983e61

Please sign in to comment.