import React, {Component} from 'react';
import './Services.scss';
import {Button, Col, Container, Modal, Row, Table} from "react-bootstrap";
import {filtersDefinitions, filtersNames} from "../components/filters/FiltersDefinitions";
class Filters extends Component {
constructor(props) {
super(props);
let newState = {};
filtersNames.forEach(elem => newState[`${elem}_active`] = false);
this.state = newState;
}
componentDidMount() {
let newState = {};
filtersNames.forEach(elem => newState[`${elem}_active`] = localStorage.getItem(`filters.${elem}`) === "true");
this.setState(newState);
}
checkboxChangesHandler(filterName, event) {
this.setState({[`${filterName}_active`]: event.target.checked});
localStorage.setItem(`filters.${filterName}`, event.target.checked);
if (typeof window !== "undefined") {
window.dispatchEvent(new Event("quick-filters"));
}
}
generateRows(filtersNames) {
return filtersNames.map(name =>
this.checkboxChangesHandler(name, event)} /> |
{filtersDefinitions[name]} |
);
}
render() {
return (
~/filters
show |
filter |
{this.generateRows(["service_port", "client_address", "min_duration",
"min_bytes", "started_after", "closed_after", "marked"])}
show |
filter |
{this.generateRows(["matched_rules", "client_port", "max_duration",
"max_bytes", "started_before", "closed_before", "hidden"])}
);
}
}
export default Filters;