Skip to content

Commit

Permalink
cockpit-components-logs-panel: Fix typo and add keys
Browse files Browse the repository at this point in the history
Typo in React callback fixed.
React array element keys added.

A TODO for ongoing refactoring is added.

Closes #9343
  • Loading branch information
mareklibra authored and martinpitt committed Jul 24, 2018
1 parent 947be45 commit 1b0e8bd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/lib/cockpit-components-logs-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const _ = cockpit.gettext;
class JournalOutput {
constructor() {
this.logs = [ ];
this.reboot_key = 0;
}

render_line(ident, prio, message, count, time, entry) {
Expand All @@ -45,7 +46,7 @@ class JournalOutput {
}

return (
<div className="cockpit-logline" role="row">
<div className="cockpit-logline" role="row" key={entry["__MONOTONIC_TIMESTAMP"]}>
<div className="cockpit-log-warning" role="cell">
{ warning
? <i className="fa fa-exclamation-triangle" />
Expand All @@ -71,12 +72,12 @@ class JournalOutput {
}

render_day_header(day) {
return <div className="panel-heading">{day}</div>;
return <div className="panel-heading" key={day}>{day}</div>;
}

render_reboot_separator() {
return (
<div className="cockpit-logline" role="row">
<div className="cockpit-logline" role="row" key={"reboot-" + this.reboot_key++}>
<div className="cockpit-log-warning" role="cell" />
<span className="cockpit-log-message cockpit-logmsg-reboot" role="cell">{_("Reboot")}</span>
</div>
Expand Down Expand Up @@ -118,10 +119,13 @@ export class LogsPanel extends React.Component {
});
}

componentDillUnmount() {
componentWillUnmount() {
this.journalctl.stop();
}

// TODO: refactor, the state object can't store neither functions nor React components
// Better approach: store just data to the component's state and render rows directly in the render() method
// Do not use helper functions (the "render_*" above) to generate elements but make components from them (start with CapitalLetter)
render() {
return (
<div className="panel panel-default cockpit-log-panel" role="table">
Expand Down

0 comments on commit 1b0e8bd

Please sign in to comment.