Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
EshaanAgg committed Jun 18, 2024
1 parent 473efcd commit d09d570
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion benchexec/tablegenerator/react-table/build/main.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benchexec/tablegenerator/react-table/build/vendors.min.js

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions benchexec/tablegenerator/react-table/src/components/NavSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@
// SPDX-License-Identifier: Apache-2.0

import { useMemo } from "react";
import { useNavigationType } from "react-router-dom";

// This component is used to sync the navigation URL of POP events
// 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.
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 navType = useNavigationType();
const location = useLocation();
useMemo(() => {
props.updateState();
if (navType === "POP") {
props.updateFiltersFromUrl();
}
props.updateFiltersFromUrl();

// We only want to update the state of the parent component when the navigation type changes
// 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
}, [navType]);
}, [location]);

return null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ export default class Overview extends React.Component {
});

componentDidMount() {
this.updateState();
this.updateFiltersFromUrl();
this.setState({
mounted: true,
});
this.updateState();
}

getFiltersFromUrl = () => {
Expand Down Expand Up @@ -246,7 +247,7 @@ export default class Overview extends React.Component {
clearImmediate(this.lastImmediate);
}
this.lastImmediate = setImmediate(() => {
this.filterUrlSetter(filter);
this.filterUrlSetter(filter, window.history);
this.lastFiltered = filter.filter(
(item) => (item.values && item.values.length > 0) || item.value,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class SelectColumn extends React.Component {
hiddenParams["hidden"] = null;
}

setURLParameter(hiddenParams);
setURLParameter(hiddenParams, window.history);
}

// -------------------------Rendering-------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ const fs = require("fs");
* @returns {void}
*/
const updateURLParams = (params) => {
window.history.pushState(
{},
"Quantile Plot Test",
constructHashURL(window.location.href, params),
);
const { newUrl } = constructHashURL(window.location.href, params);
window.history.pushState({}, "Quantile Plot Test", newUrl);
};

const testDir = "../test_integration/expected/";
Expand Down Expand Up @@ -95,7 +92,9 @@ files
});

describe("Direct Plot should match HTML snapshot", () => {
console.log(window.location.href);
updateURLParams({ plot: plotInstance.plotOptions.direct });
console.log(window.location.href);

it.each(selectionResultInput)(
"with selection of the type %s and %s results",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from "react";
import ScatterPlot from "../components/ScatterPlot.js";
import Overview from "../components/Overview";
import renderer from "react-test-renderer";
import { setURLParameter } from "../utils/utils";
import { constructHashURL } from "../utils/utils";
const fs = require("fs");

const content = fs.readFileSync(
Expand Down Expand Up @@ -170,6 +170,7 @@ function getSelections(xSelection, ySelection) {
}

function setUrlParams(params) {
setURLParameter(params);
const { newUrl } = constructHashURL(window.location.href, params);
window.history.pushState({}, "Quantile Plot Test", newUrl);
plotInstance.refreshUrlState();
}
16 changes: 6 additions & 10 deletions benchexec/tablegenerator/react-table/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,16 @@ export const constructHashURL = (url, params = {}) => {
* It can also be used to remove a parameter from the URL by setting it's value to undefined.
*
* @param {Object} params - The parameters to be set or updated in the URL hash
* @param {Object} [history=null] - The history object to use for updating the URL hash
* @param {Object} [history=undefined] - The history object to update the URL hash without reloading the page
* @returns {void}
*/
const setURLParameter = (params = {}, history = null) => {
const { newUrl, queryString } = constructHashURL(
document.location.href,
params,
);
if (history && history.push) {
history.push(queryString);
const setURLParameter = (params = {}, history = undefined) => {
const { newUrl } = constructHashURL(window.location.href, params);
if (history && history.pushState) {
history.pushState({}, "", newUrl);
return;
}
document.location.assign(newUrl);
// document.location.href = newUrl;
window.location.href = newUrl;
};

const makeUrlFilterDeserializer = (statusValues, categoryValues) => {
Expand Down

0 comments on commit d09d570

Please sign in to comment.