From c5434cccee8661de3082c0c777375eb8e6f76865 Mon Sep 17 00:00:00 2001 From: JJ Date: Thu, 18 Jul 2024 17:38:57 -0700 Subject: remove unnecessary jsx stuff --- .../src/components/filters/AdvancedFilters.jsx | 54 --------- .../filters/BooleanConnectionsFilter.jsx | 69 ----------- .../src/components/filters/ExitSearchFilter.jsx | 57 --------- .../components/filters/RulesConnectionsFilter.jsx | 83 -------------- .../components/filters/StringConnectionsFilter.jsx | 127 --------------------- 5 files changed, 390 deletions(-) delete mode 100644 frontend/src/components/filters/AdvancedFilters.jsx delete mode 100644 frontend/src/components/filters/BooleanConnectionsFilter.jsx delete mode 100644 frontend/src/components/filters/ExitSearchFilter.jsx delete mode 100644 frontend/src/components/filters/RulesConnectionsFilter.jsx delete mode 100644 frontend/src/components/filters/StringConnectionsFilter.jsx (limited to 'frontend/src/components/filters') diff --git a/frontend/src/components/filters/AdvancedFilters.jsx b/frontend/src/components/filters/AdvancedFilters.jsx deleted file mode 100644 index 8598185..0000000 --- a/frontend/src/components/filters/AdvancedFilters.jsx +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of caronte (https://github.com/eciavatta/caronte). - * Copyright (c) 2020 Emiliano Ciavatta. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import React, {Component} from "react"; -import {withRouter} from "react-router-dom"; -import dispatcher from "../../dispatcher"; -import {updateParams} from "../../utils"; -import ButtonField from "../fields/ButtonField"; - -class AdvancedFilters extends Component { - - state = {}; - - componentDidMount() { - this.urlParams = new URLSearchParams(this.props.location.search); - - this.connectionsFiltersCallback = (payload) => { - this.urlParams = updateParams(this.urlParams, payload); - const active = ["client_address", "client_port", "min_duration", "max_duration", "min_bytes", "max_bytes"] - .some((f) => this.urlParams.has(f)); - if (this.state.active !== active) { - this.setState({active}); - } - }; - dispatcher.register("connections_filters", this.connectionsFiltersCallback); - } - - componentWillUnmount() { - dispatcher.unregister(this.connectionsFiltersCallback); - } - - render() { - return ( - - ); - } - -} - -export default withRouter(AdvancedFilters); diff --git a/frontend/src/components/filters/BooleanConnectionsFilter.jsx b/frontend/src/components/filters/BooleanConnectionsFilter.jsx deleted file mode 100644 index 0355167..0000000 --- a/frontend/src/components/filters/BooleanConnectionsFilter.jsx +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of caronte (https://github.com/eciavatta/caronte). - * Copyright (c) 2020 Emiliano Ciavatta. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import React, {Component} from "react"; -import {withRouter} from "react-router-dom"; -import dispatcher from "../../dispatcher"; -import CheckField from "../fields/CheckField"; - -class BooleanConnectionsFilter extends Component { - - state = { - filterActive: "false" - }; - - componentDidMount() { - let params = new URLSearchParams(this.props.location.search); - this.setState({filterActive: this.toBoolean(params.get(this.props.filterName)).toString()}); - - this.connectionsFiltersCallback = (payload) => { - const name = this.props.filterName; - if (name in payload && this.state.filterActive !== payload[name]) { - this.setState({filterActive: payload[name]}); - } - }; - dispatcher.register("connections_filters", this.connectionsFiltersCallback); - } - - componentWillUnmount() { - dispatcher.unregister(this.connectionsFiltersCallback); - } - - toBoolean = (value) => { - return value !== null && value.toLowerCase() === "true"; - }; - - filterChanged = () => { - const newValue = (!this.toBoolean(this.state.filterActive)).toString(); - const urlParams = {}; - urlParams[this.props.filterName] = newValue === "true" ? "true" : null; - dispatcher.dispatch("connections_filters", urlParams); - this.setState({filterActive: newValue}); - }; - - render() { - return ( -
- -
- ); - } - -} - -export default withRouter(BooleanConnectionsFilter); diff --git a/frontend/src/components/filters/ExitSearchFilter.jsx b/frontend/src/components/filters/ExitSearchFilter.jsx deleted file mode 100644 index 0aacfd6..0000000 --- a/frontend/src/components/filters/ExitSearchFilter.jsx +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of caronte (https://github.com/eciavatta/caronte). - * Copyright (c) 2020 Emiliano Ciavatta. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import React, {Component} from "react"; -import {withRouter} from "react-router-dom"; -import dispatcher from "../../dispatcher"; -import CheckField from "../fields/CheckField"; - -class ExitSearchFilter extends Component { - - state = {}; - - componentDidMount() { - let params = new URLSearchParams(this.props.location.search); - this.setState({performedSearch: params.get("performed_search")}); - - this.connectionsFiltersCallback = (payload) => { - if (this.state.performedSearch !== payload["performed_search"]) { - this.setState({performedSearch: payload["performed_search"]}); - } - }; - dispatcher.register("connections_filters", this.connectionsFiltersCallback); - } - - componentWillUnmount() { - dispatcher.unregister(this.connectionsFiltersCallback); - } - - render() { - return ( - <> - {this.state.performedSearch && -
- - dispatcher.dispatch("connections_filters", {"performed_search": null})} small/> -
} - - ); - } - -} - -export default withRouter(ExitSearchFilter); diff --git a/frontend/src/components/filters/RulesConnectionsFilter.jsx b/frontend/src/components/filters/RulesConnectionsFilter.jsx deleted file mode 100644 index 4ae769a..0000000 --- a/frontend/src/components/filters/RulesConnectionsFilter.jsx +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of caronte (https://github.com/eciavatta/caronte). - * Copyright (c) 2020 Emiliano Ciavatta. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import React, {Component} from "react"; -import {withRouter} from "react-router-dom"; -import backend from "../../backend"; -import dispatcher from "../../dispatcher"; -import TagField from "../fields/TagField"; - -import classNames from 'classnames'; -import _ from 'lodash'; - -class RulesConnectionsFilter extends Component { - - state = { - rules: [], - activeRules: [] - }; - - componentDidMount() { - const params = new URLSearchParams(this.props.location.search); - let activeRules = params.getAll("matched_rules") || []; - - backend.get("/api/rules").then((res) => { - let rules = res.json.flatMap((rule) => rule.enabled ? [{id: rule.id, name: rule.name}] : []); - activeRules = rules.filter((rule) => activeRules.some((id) => rule.id === id)); - this.setState({rules, activeRules}); - }); - - this.connectionsFiltersCallback = (payload) => { - if ("matched_rules" in payload && !_.isEqual(payload["matched_rules"].sort(), this.state.activeRules.sort())) { - const newRules = this.state.rules.filter((r) => payload["matched_rules"].includes(r.id)); - this.setState({ - activeRules: newRules.map((r) => { - return {id: r.id, name: r.name}; - }) - }); - } - }; - dispatcher.register("connections_filters", this.connectionsFiltersCallback); - } - - componentWillUnmount() { - dispatcher.unregister(this.connectionsFiltersCallback); - } - - onChange = (activeRules) => { - if (!_.isEqual(activeRules.sort(), this.state.activeRules.sort())) { - this.setState({activeRules}); - dispatcher.dispatch("connections_filters", {"matched_rules": activeRules.map((r) => r.id)}); - } - }; - - render() { - return ( -
-
- -
-
- ); - } - -} - -export default withRouter(RulesConnectionsFilter); diff --git a/frontend/src/components/filters/StringConnectionsFilter.jsx b/frontend/src/components/filters/StringConnectionsFilter.jsx deleted file mode 100644 index c5d7075..0000000 --- a/frontend/src/components/filters/StringConnectionsFilter.jsx +++ /dev/null @@ -1,127 +0,0 @@ -/* - * This file is part of caronte (https://github.com/eciavatta/caronte). - * Copyright (c) 2020 Emiliano Ciavatta. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import React, {Component} from "react"; -import {withRouter} from "react-router-dom"; -import dispatcher from "../../dispatcher"; -import InputField from "../fields/InputField"; - -class StringConnectionsFilter extends Component { - - state = { - fieldValue: "", - filterValue: null, - timeoutHandle: null, - invalidValue: false - }; - - componentDidMount() { - let params = new URLSearchParams(this.props.location.search); - this.updateStateFromFilterValue(params.get(this.props.filterName)); - - this.connectionsFiltersCallback = (payload) => { - const name = this.props.filterName; - if (name in payload && this.state.filterValue !== payload[name]) { - this.updateStateFromFilterValue(payload[name]); - } - }; - dispatcher.register("connections_filters", this.connectionsFiltersCallback); - } - - componentWillUnmount() { - dispatcher.unregister(this.connectionsFiltersCallback); - } - - updateStateFromFilterValue = (filterValue) => { - if (filterValue !== null) { - let fieldValue = filterValue; - if (typeof this.props.decodeFunc === "function") { - fieldValue = this.props.decodeFunc(filterValue); - } - if (typeof this.props.replaceFunc === "function") { - fieldValue = this.props.replaceFunc(fieldValue); - } - if (this.isValueValid(fieldValue)) { - this.setState({fieldValue, filterValue}); - } else { - this.setState({fieldValue, invalidValue: true}); - } - } else { - this.setState({fieldValue: "", filterValue: null}); - } - }; - - isValueValid = (value) => { - return typeof this.props.validateFunc !== "function" || - (typeof this.props.validateFunc === "function" && this.props.validateFunc(value)); - }; - - changeFilterValue = (value) => { - const urlParams = {}; - urlParams[this.props.filterName] = value; - dispatcher.dispatch("connections_filters", urlParams); - }; - - filterChanged = (fieldValue) => { - if (this.state.timeoutHandle) { - clearTimeout(this.state.timeoutHandle); - } - - if (typeof this.props.replaceFunc === "function") { - fieldValue = this.props.replaceFunc(fieldValue); - } - - if (fieldValue === "") { - this.setState({fieldValue: "", filterValue: null, invalidValue: false}); - return this.changeFilterValue(null); - } - - - if (this.isValueValid(fieldValue)) { - let filterValue = fieldValue; - if (filterValue !== "" && typeof this.props.encodeFunc === "function") { - filterValue = this.props.encodeFunc(filterValue); - } - - this.setState({ - fieldValue, - timeoutHandle: setTimeout(() => { - this.setState({filterValue}); - this.changeFilterValue(filterValue); - }, 500), - invalidValue: false - }); - } else { - this.setState({fieldValue, invalidValue: true}); - } - }; - - render() { - let active = this.state.filterValue !== null; - - return ( -
- -
- ); - } - -} - -export default withRouter(StringConnectionsFilter); -- cgit v1.2.3-70-g09d2