-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from metrico/jacovinus-feature-tables
Fix: labels and logs styles
- Loading branch information
Showing
16 changed files
with
344 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,73 @@ | ||
import React, { Component } from "react"; | ||
import { connect } from "react-redux"; | ||
|
||
import { DataViewCont, DataViewStyled, Loader } from "./styled"; | ||
|
||
import ClokiChart from "../../plugins/charts"; | ||
import QueryHistory from "../../plugins/queryhistory"; | ||
import LogsRow from "./LogsRow"; | ||
import EmptyView from "./EmptyView"; | ||
|
||
class DataView extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
limit: props.limit || 100, | ||
messages: props.messages || [], | ||
matrixData: props.matrixData || [], | ||
loading: false, | ||
}; | ||
} | ||
|
||
getMatrixForChart = () => { | ||
return this.props.matrixData; | ||
}; | ||
getLimit = () => { | ||
return this.props.limit; | ||
}; | ||
|
||
render() { | ||
return ( | ||
<DataViewStyled> | ||
<DataViewCont> | ||
{this.props.messages.length > 0 && | ||
this.getMatrixForChart().length < 1 | ||
? this.props.messages.map((message, key) => ( | ||
<LogsRow | ||
message={message} | ||
toggleTagsActive={this.toggleTagsActive} | ||
key={key} | ||
/> | ||
)) | ||
: null} | ||
|
||
{this.getMatrixForChart().length > 0 ? ( | ||
<ClokiChart | ||
chartLimit={this.getLimit()} | ||
matrixData={this.getMatrixForChart()} | ||
/> | ||
) : null} | ||
{this.props.messages.length < 1 && | ||
this.getMatrixForChart().length < 1 && | ||
!this.props.loading && <EmptyView />} | ||
<QueryHistory /> | ||
{this.props.loading && <Loader />} | ||
</DataViewCont> | ||
</DataViewStyled> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
messages: state.logs, | ||
start: state.start, | ||
stop: state.stop, | ||
limit: state.limit, | ||
loading: state.loading, | ||
matrixData: state.matrixData, | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps)(DataView); | ||
import React, { Component } from "react"; | ||
import { connect } from "react-redux"; | ||
|
||
import { DataViewCont, DataViewStyled, Loader } from "./styled"; | ||
import ClokiChart from "../../plugins/charts"; | ||
import QueryHistory from "../../plugins/queryhistory"; | ||
import LogsRow from "./LogsRow"; | ||
import EmptyView from "./EmptyView"; | ||
// import Table from "../../plugins/tables/Table"; | ||
|
||
class DataView extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
limit: props.limit || 100, | ||
messages: props.messages || [], | ||
matrixData: props.matrixData || [], | ||
loading: false, | ||
}; | ||
} | ||
|
||
getMatrixForChart = () => { | ||
return this.props.matrixData; | ||
}; | ||
getLimit = () => { | ||
return this.props.limit; | ||
}; | ||
|
||
render() { | ||
return ( | ||
<DataViewStyled> | ||
<DataViewCont> | ||
{/* <Table/> */} | ||
{this.props.messages.length > 0 && | ||
this.getMatrixForChart().length < 1 | ||
? this.props.messages.map((message, key) => ( | ||
<LogsRow | ||
message={message} | ||
toggleTagsActive={this.toggleTagsActive} | ||
key={key} | ||
/> | ||
)) | ||
: null} | ||
|
||
{this.getMatrixForChart().length > 0 ? ( | ||
<ClokiChart | ||
chartLimit={this.getLimit()} | ||
matrixData={this.getMatrixForChart()} | ||
/> | ||
) : null} | ||
{this.props.messages.length < 1 && | ||
this.getMatrixForChart().length < 1 && | ||
!this.props.loading && <EmptyView />} | ||
<QueryHistory /> | ||
{this.props.loading && <Loader />} | ||
</DataViewCont> | ||
</DataViewStyled> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
messages: state.logs, | ||
start: state.start, | ||
stop: state.stop, | ||
limit: state.limit, | ||
loading: state.loading, | ||
matrixData: state.matrixData, | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps)(DataView); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,39 @@ | ||
import { formatDate, getRowColor, toggleActiveStyles } from "./helpers"; | ||
import { LogRow, RowLogContent, RowTimestamp } from "./styled"; | ||
import ValueTags from "./ValueTags"; | ||
import { useSelector, useDispatch } from "react-redux"; | ||
import setLogs from "../../actions/setLogs"; | ||
|
||
export default function LogsRow({ message }) { | ||
const dispatch = useDispatch(); | ||
const messages = useSelector((store) => store.logs); | ||
|
||
function toggleTagsActive(idx) { | ||
let arrCopy = [...messages]; | ||
arrCopy.forEach((entry) => { | ||
if (entry.id === idx) { | ||
entry.showLabels = entry.showLabels ? false : true; | ||
} | ||
}); | ||
dispatch(setLogs(arrCopy)); | ||
} | ||
|
||
return ( | ||
<LogRow | ||
rowColor={getRowColor(message.tags)} | ||
onClick={(e) => { | ||
toggleTagsActive(message.id); | ||
}} | ||
> | ||
<RowTimestamp>{formatDate(message.timestamp)}</RowTimestamp> | ||
<RowLogContent>{message.text}</RowLogContent> | ||
|
||
{message.tags && ( | ||
<div className={toggleActiveStyles(message)}> | ||
<ValueTags tags={message.tags} /> | ||
</div> | ||
)} | ||
</LogRow> | ||
); | ||
} | ||
import { formatDate, getRowColor, toggleActiveStyles } from "./helpers"; | ||
import { LogRow, RowLogContent, RowTimestamp } from "./styled"; | ||
import ValueTags from "./ValueTags"; | ||
import { useSelector, useDispatch } from "react-redux"; | ||
import setLogs from "../../actions/setLogs"; | ||
|
||
export default function LogsRow({ message }) { | ||
const dispatch = useDispatch(); | ||
const messages = useSelector((store) => store.logs); | ||
|
||
function toggleTagsActive(idx) { | ||
let arrCopy = [...messages]; | ||
arrCopy.forEach((entry) => { | ||
if (entry.id === idx) { | ||
entry.showLabels = entry.showLabels ? false : true; | ||
} | ||
}); | ||
dispatch(setLogs(arrCopy)); | ||
} | ||
|
||
return ( | ||
<LogRow | ||
rowColor={getRowColor(message.tags)} | ||
onClick={(e) => { | ||
toggleTagsActive(message.id); | ||
}} | ||
> | ||
<div className="log-ts-row"> | ||
<RowTimestamp>{formatDate(message.timestamp)}</RowTimestamp> | ||
<RowLogContent>{message.text}</RowLogContent> | ||
</div> | ||
{message.tags && ( | ||
<div className={toggleActiveStyles(message)}> | ||
<ValueTags tags={message.tags} /> | ||
</div> | ||
)} | ||
</LogRow> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
export const TAGS_LEVEL = { | ||
critical: ["emerg", "fatal", "alert", "crit", "critical"], | ||
error: ["err", "eror", "error", "warning"], | ||
warning: ["warn", "warning"], | ||
info: ["info", "information", "notice"], | ||
debug: ["dbug", "debug"], | ||
trace: ["trace"], | ||
}; | ||
export const TAGS_LEVEL = { | ||
critical: ["emerg", "fatal", "alert", "crit", "critical"], | ||
error: ["err", "eror", "error"], | ||
warning: ["warn", "warning"], | ||
info: ["info", "information", "notice"], | ||
debug: ["dbug", "debug"], | ||
trace: ["trace"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import { LEVEL_COLORS as lColors } from "../theme/theme"; | ||
import { TAGS_LEVEL as tLevel } from "../consts/consts"; | ||
import * as moment from "moment"; | ||
|
||
export function getRowColor(tags) { | ||
if (tags?.["level"]) { | ||
const level = Object.keys(tLevel).find((level) => | ||
tLevel[level].includes(tags.level.toLowerCase()) | ||
); | ||
return lColors[level]; | ||
} else { | ||
return lColors["unknown"]; | ||
} | ||
} | ||
|
||
export function toggleActiveStyles(idx) { | ||
return idx.showLabels | ||
? "value-tags-container labelsActive" | ||
: "value-tags-container labelsInactive"; | ||
} | ||
|
||
export function formatDate(timestamp) { | ||
return moment(parseInt(timestamp)).format("YYYY-MM-DD HH:mm:ss.SSS UTC"); | ||
} | ||
import { LEVEL_COLORS as lColors } from "../theme/theme"; | ||
import { TAGS_LEVEL as tLevel } from "../consts/consts"; | ||
import * as moment from "moment"; | ||
|
||
export function getRowColor(tags) { | ||
const type = tags?.severity || tags?.level; | ||
if (type) { | ||
const level = Object.keys(tLevel).find((level) => | ||
tLevel[level].includes(type.toLowerCase()) | ||
); | ||
return lColors[level]; | ||
} else { | ||
return lColors["unknown"]; | ||
} | ||
} | ||
|
||
export function toggleActiveStyles(idx) { | ||
return idx.showLabels | ||
? "value-tags-container labelsActive" | ||
: "value-tags-container labelsInactive"; | ||
} | ||
|
||
export function formatDate(timestamp) { | ||
return moment(parseInt(timestamp)).format("YYYY-MM-DD HH:mm:ss.SSS UTC"); | ||
} |
Oops, something went wrong.