From 1b099909c679cc981686e8e468ae300f0beb6544 Mon Sep 17 00:00:00 2001 From: EshaanAgg <96648934+EshaanAgg@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:13:03 +0530 Subject: [PATCH] review --- .../src/components/FilterBox/FilterCard.js | 1 + .../components/FilterBox/FilterContainer.js | 16 +++++++-- .../react-table/src/components/NavSync.js | 35 ------------------- .../react-table/src/components/Overview.js | 18 ++-------- .../react-table/src/utils/utils.js | 31 ++++++---------- 5 files changed, 28 insertions(+), 73 deletions(-) delete mode 100644 benchexec/tablegenerator/react-table/src/components/NavSync.js diff --git a/benchexec/tablegenerator/react-table/src/components/FilterBox/FilterCard.js b/benchexec/tablegenerator/react-table/src/components/FilterBox/FilterCard.js index a7696df1e..fcbfce152 100644 --- a/benchexec/tablegenerator/react-table/src/components/FilterBox/FilterCard.js +++ b/benchexec/tablegenerator/react-table/src/components/FilterBox/FilterCard.js @@ -90,6 +90,7 @@ export default class FilterCard extends React.PureComponent { if (!this.props.filter) { return; } + if ( !prevProps.filter || prevProps.filter.values !== this.props.filter.values diff --git a/benchexec/tablegenerator/react-table/src/components/FilterBox/FilterContainer.js b/benchexec/tablegenerator/react-table/src/components/FilterBox/FilterContainer.js index cec0e70d5..f79276c84 100644 --- a/benchexec/tablegenerator/react-table/src/components/FilterBox/FilterContainer.js +++ b/benchexec/tablegenerator/react-table/src/components/FilterBox/FilterContainer.js @@ -22,7 +22,12 @@ export default class FilterContainer extends React.PureComponent { }; } this.props.resetFilterHook(() => this.resetAllFilters()); - this.state = { filters, toolName, addingFilter: false, numCards: 0 }; + this.state = { + filters, + toolName, + addingFilter: false, + numCards: 0, + }; } getActiveFilters() { @@ -42,6 +47,7 @@ export default class FilterContainer extends React.PureComponent { addFilter(idx) { const { filters: newFilterState, numCards } = this.state; + const newFilter = { filtering: true, numCards, touched: 0 }; if (newFilterState[idx].type === "status") { newFilter.values = [ @@ -80,12 +86,16 @@ export default class FilterContainer extends React.PureComponent { const newFilterState = this.state.filters; newFilterState[idx].filtering = false; newFilterState[idx].values = []; - this.setState({ filters: [...newFilterState] }); + this.setState({ + filters: [...newFilterState], + }); this.props.updateFilters({ title, values: [] }, idx); } - componentDidUpdate({ currentFilters: prevFilters }) { + componentDidUpdate(prevProps, prevState) { + const prevFilters = prevProps.currentFilters; const { currentFilters } = this.props; + if (!equals(prevFilters, currentFilters)) { // update set filters let { filters } = this.state; diff --git a/benchexec/tablegenerator/react-table/src/components/NavSync.js b/benchexec/tablegenerator/react-table/src/components/NavSync.js deleted file mode 100644 index 9e3e03273..000000000 --- a/benchexec/tablegenerator/react-table/src/components/NavSync.js +++ /dev/null @@ -1,35 +0,0 @@ -// This file is part of BenchExec, a framework for reliable benchmarking: -// https://github.com/sosy-lab/benchexec -// -// SPDX-FileCopyrightText: 2019-2020 Dirk Beyer -// -// SPDX-License-Identifier: Apache-2.0 - -import { useMemo } from "react"; -import { useLocation } from "react-router-dom"; - -/* - * A functional component to sync the filters display from the URL - * This component does not render anything, and is a workaround to use a hook in the parent class component. - * This logic should be moved to the parent class component in the future after the same is converted to a functional component. - * - * @param {Object} props - The props object - * @param {Function} props.updateState - The function to update the state of the parent component - * @param {Function} props.updateFiltersFromUrl - The function to update the filters from the URL - */ -const NavSync = (props) => { - const location = useLocation(); - - useMemo(() => { - props.updateState(); - props.updateFiltersFromUrl(); - - // We only want to update the state of the parent component when the window location changes - // and not when the other props change due to rerendering of the parent component - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [location]); - - return null; -}; - -export default NavSync; diff --git a/benchexec/tablegenerator/react-table/src/components/Overview.js b/benchexec/tablegenerator/react-table/src/components/Overview.js index 42e650237..9558a64b4 100644 --- a/benchexec/tablegenerator/react-table/src/components/Overview.js +++ b/benchexec/tablegenerator/react-table/src/components/Overview.js @@ -14,7 +14,6 @@ import SelectColumn from "./SelectColumn.js"; import ScatterPlot from "./ScatterPlot.js"; import QuantilePlot from "./QuantilePlot.js"; import FilterBox from "./FilterBox/FilterBox.js"; -import NavSync from "./NavSync.js"; import LinkOverlay from "./LinkOverlay.js"; import classNames from "classnames"; import FilterInfoButton from "./FilterInfoButton.js"; @@ -104,7 +103,6 @@ export default class Overview extends React.Component { active: getActiveTab(), quantilePreSelection: tools[0].columns[1], hiddenCols: createHiddenColsFromURL(tools), - mounted: false, }; // Collect all status and category values for filter drop-down this.statusValues = this.findAllValuesOfColumn( @@ -157,8 +155,8 @@ export default class Overview extends React.Component { } } - addTypeToFilter = (filters) => - filters + addTypeToFilter = (filters) => { + return filters .filter((filter) => filter.id !== "id") .forEach((filter) => { const filterSplitArray = filter.id.split("_"); @@ -168,6 +166,7 @@ export default class Overview extends React.Component { ].type; filter.type = type; }); + }; componentDidMount() { this.updateFiltersFromUrl(); @@ -175,11 +174,6 @@ export default class Overview extends React.Component { mounted: true, }); this.updateState(); - - // window.history.onpushstate = () => { - // this.updateState(); - // this.updateFiltersFromUrl(); - // }; } getFiltersFromUrl = () => { @@ -375,12 +369,6 @@ export default class Overview extends React.Component {
{/* Component to sync the navigation state. Does not render anything. */} - {this.state.mounted && ( - - )}