blob: 944f1d55ccd216e7655d37fc63ef3faed6d43965 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
import React, {Component} from 'react';
import Typed from 'typed.js';
import './Header.scss';
import {filtersDefinitions, filtersNames} from "../components/filters/FiltersDefinitions";
import {Link} from "react-router-dom";
import ButtonField from "../components/fields/ButtonField";
class Header extends Component {
constructor(props) {
super(props);
let newState = {};
filtersNames.forEach(elem => newState[`${elem}_active`] = false);
this.state = newState;
this.fetchStateFromLocalStorage = this.fetchStateFromLocalStorage.bind(this);
}
componentDidMount() {
const options = {
strings: ["caronte$ "],
typeSpeed: 50,
cursorChar: "❚"
};
this.typed = new Typed(this.el, options);
this.fetchStateFromLocalStorage();
if (typeof window !== "undefined") {
window.addEventListener("quick-filters", this.fetchStateFromLocalStorage);
}
}
componentWillUnmount() {
this.typed.destroy();
if (typeof window !== "undefined") {
window.removeEventListener("quick-filters", this.fetchStateFromLocalStorage);
}
}
fetchStateFromLocalStorage() {
let newState = {};
filtersNames.forEach(elem => newState[`${elem}_active`] = localStorage.getItem(`filters.${elem}`) === "true");
this.setState(newState);
}
render() {
let quickFilters = filtersNames.filter(name => this.state[`${name}_active`])
.map(name => <React.Fragment key={name} >{filtersDefinitions[name]}</React.Fragment>)
.slice(0, 5);
return (
<header className="header container-fluid">
<div className="row">
<div className="col-auto">
<h1 className="header-title type-wrap">
<span style={{whiteSpace: 'pre'}} ref={(el) => {
this.el = el;
}}/>
</h1>
</div>
<div className="col-auto">
<div className="filters-bar">
{quickFilters}
</div>
</div>
<div className="col">
<div className="header-buttons">
<ButtonField variant="pink" onClick={this.props.onOpenFilters} name="filters" bordered />
<Link to="/pcaps">
<ButtonField variant="purple" name="pcaps" bordered />
</Link>
<Link to="/rules">
<ButtonField variant="deep-purple" name="rules" bordered />
</Link>
<Link to="/services">
<ButtonField variant="indigo" name="services" bordered />
</Link>
<Link to="/config">
<ButtonField variant="blue" name="config" bordered />
</Link>
</div>
</div>
</div>
</header>
);
}
}
export default Header;
|