integrated filter for logs

main
alex 2023-10-17 22:53:17 +02:00
parent 639dc4ab8e
commit f53d289a05
3 changed files with 41 additions and 6 deletions

View File

@ -228,8 +228,8 @@
}, },
"card": { "card": {
"checkbox": { "checkbox": {
"autoScroll": "Auto scroll",
"info": "INFO", "info": "INFO",
"warning": "WARNUNG",
"error": "FEHLER" "error": "FEHLER"
} }
}, },

View File

@ -228,8 +228,8 @@
}, },
"card": { "card": {
"checkbox": { "checkbox": {
"autoScroll": "Auto scroll",
"info": "INFO", "info": "INFO",
"warning": "WARNING",
"error": "ERROR" "error": "ERROR"
} }
}, },

View File

@ -14,6 +14,7 @@ export default function LogCard({
// const [checkboxAutoScrollChecked, setCheckboxAutoScrollChecked] = // const [checkboxAutoScrollChecked, setCheckboxAutoScrollChecked] =
// useState(true); // useState(true);
const [checkboxInfoChecked, setCheckboxInfoChecked] = useState(true); const [checkboxInfoChecked, setCheckboxInfoChecked] = useState(true);
const [checkboxWarningChecked, setCheckboxWarningChecked] = useState(true);
const [checkboxErrorChecked, setCheckboxErrorChecked] = useState(true); const [checkboxErrorChecked, setCheckboxErrorChecked] = useState(true);
const virtuosoRef = useRef(); const virtuosoRef = useRef();
@ -146,6 +147,16 @@ export default function LogCard({
</Col> </Col>
*/ */
const filteredLogs = logs.filter((log) => {
const logType = log.charAt(0);
return (
(checkboxInfoChecked && logType === "I") ||
(checkboxWarningChecked && logType === "W") ||
(checkboxErrorChecked && logType === "E")
);
});
return ( return (
<Card <Card
title={ title={
@ -165,6 +176,14 @@ export default function LogCard({
{t("logCard.card.checkbox.info")} {t("logCard.card.checkbox.info")}
</Checkbox> </Checkbox>
</Col> </Col>
<Col>
<Checkbox
checked={checkboxWarningChecked}
onChange={(e) => setCheckboxWarningChecked(e.target.checked)}
>
{t("logCard.card.checkbox.warning")}
</Checkbox>
</Col>
<Col> <Col>
<Checkbox <Checkbox
disabled={customResult !== undefined} disabled={customResult !== undefined}
@ -202,10 +221,26 @@ export default function LogCard({
<Virtuoso <Virtuoso
ref={virtuosoRef} ref={virtuosoRef}
initialTopMostItemIndex={logs.length - 1} initialTopMostItemIndex={logs.length - 1}
data={logs} data={filteredLogs}
itemContent={(_, log) => ( itemContent={(_, log) => {
<div style={{ padding: "1px" }}>{log}</div> const logType = log.charAt(0);
)} let style = {};
let color = "";
if (checkboxInfoChecked && logType === "I") {
color = "#44bd32";
} else if (checkboxWarningChecked && logType === "W") {
color = "#e67e22";
} else if (checkboxErrorChecked && logType === "E") {
color = "#e74c3c";
} else {
color = "#2980b9"; // no match
}
style = { padding: "1px", color };
return <span style={style}>{log}</span>;
}}
followOutput={true} followOutput={true}
/> />
</div> </div>