Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor the setHash function #1006

Merged
merged 14 commits into from
Mar 5, 2024
2 changes: 1 addition & 1 deletion benchexec/tablegenerator/react-table/build/main.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export default class Overview extends React.Component {
clearImmediate(this.lastImmediate);
}
this.lastImmediate = setImmediate(() => {
this.filterUrlSetter(filter, { history: this.routerRef.current.history });
this.filterUrlSetter(filter, this.routerRef.current.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 @@ -21,8 +21,8 @@ import {
import {
getRunSetName,
EXTENDED_DISCRETE_COLOR_RANGE,
setParam,
getHashSearch,
setURLParameter,
getURLParameters,
getFirstVisibles,
} from "../utils/utils";
import { renderSetting } from "../utils/plot";
Expand Down Expand Up @@ -61,7 +61,7 @@ export default class QuantilePlot extends React.Component {
}

setPlotData() {
const queryProps = getHashSearch();
const queryProps = getURLParameters();

let { selection, plot, scaling, results } = {
...this.defaultValues,
Expand Down Expand Up @@ -110,7 +110,7 @@ export default class QuantilePlot extends React.Component {
they differ, then the initial selection was a hidden column/runset and therefore another column/runset was selected
to be shown. In this case, update the URL parameter to correctly define the selection that is actually being shown now. */
if (initialSelection && selection && initialSelection !== selection) {
setParam({ selection });
setURLParameter({ selection });
}

return {
Expand Down Expand Up @@ -519,7 +519,9 @@ export default class QuantilePlot extends React.Component {
className="setting-select"
name="setting-Selection"
value={this.state.selection}
onChange={(ev) => setParam({ selection: ev.target.value })}
onChange={(ev) =>
setURLParameter({ selection: ev.target.value })
}
>
<optgroup label="Runsets">
{this.props.tools.map((tool, i) => {
Expand All @@ -544,21 +546,21 @@ export default class QuantilePlot extends React.Component {
{renderSetting(
"Plot",
this.state.plot,
(ev) => setParam({ plot: ev.target.value }),
(ev) => setURLParameter({ plot: ev.target.value }),
this.plotOptions,
)}
</div>
<div className="settings-subcontainer">
{renderSetting(
"Scaling",
this.state.scaling,
(ev) => setParam({ scaling: ev.target.value }),
(ev) => setURLParameter({ scaling: ev.target.value }),
this.scalingOptions,
)}
{renderSetting(
"Results",
this.state.results,
(ev) => setParam({ results: ev.target.value }),
(ev) => setURLParameter({ results: ev.target.value }),
this.resultsOptions,
resultsTooltip,
this.state.isResultSelectionDisabled,
Expand Down
29 changes: 10 additions & 19 deletions benchexec/tablegenerator/react-table/src/components/ReactTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import {
emptyStateValue,
isNil,
hasSameEntries,
setHashSearch,
getHashSearch,
setURLParameter,
getURLParameters,
getHiddenColIds,
decodeFilter,
} from "../utils/utils";
Expand All @@ -50,7 +50,7 @@ const pageSizes = [50, 100, 250, 500, 1000, 2500];
const initialPageSize = 250;

const getSortingSettingsFromURL = () => {
const urlParams = getHashSearch();
const urlParams = getURLParameters();
let settings = urlParams.sort
? urlParams.sort.split(";").map((sortingEntry) => {
const sortingParams = sortingEntry.split(",");
Expand Down Expand Up @@ -567,9 +567,9 @@ const Table = (props) => {
defaultColumn,
initialState: {
sortBy: getSortingSettingsFromURL(),
pageIndex: parseInt(getHashSearch().page) - 1 || 0,
pageIndex: parseInt(getURLParameters().page) - 1 || 0,
hiddenColumns: getHiddenColIds(columns),
pageSize: parseInt(getHashSearch().pageSize) || initialPageSize,
pageSize: parseInt(getURLParameters().pageSize) || initialPageSize,
},
},
useFilters,
Expand All @@ -589,29 +589,20 @@ const Table = (props) => {
)
.join(";");
const value = sort.length ? sort : undefined;
const prevParams = getHashSearch();
if (prevParams["sort"] !== value) {
setHashSearch({ sort: value }, { keepOthers: true });
}
setURLParameter({ sort: value });
Comment on lines 591 to +592
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good that we now document the feature of parameter deletion via undefined values, because here we can see that it was actually used already!

}, [sortBy]);

// Update the URL page size param when the table page size setting changed
useEffect(() => {
const value = pageSize !== initialPageSize ? pageSize : undefined;
const prevParams = getHashSearch();
if (prevParams["pageSize"] !== value) {
setHashSearch({ pageSize: value }, { keepOthers: true });
}
setURLParameter({ pageSize: value });
}, [pageSize]);

// Update the URL page param when the table page changed
useEffect(() => {
const value =
pageIndex && pageIndex !== 0 ? Number(pageIndex) + 1 : undefined;
const prevParams = getHashSearch();
if (prevParams["page"] !== value) {
setHashSearch({ page: value }, { keepOthers: true });
}
setURLParameter({ page: value });
}, [pageIndex]);

// Store the column resizing values so they can be applied again in case the table rerenders
Expand Down Expand Up @@ -675,9 +666,9 @@ const Table = (props) => {
// Update table relevant parameters after URL change
useEffect(() => {
return history.listen((location) => {
setPageSize(getHashSearch().pageSize || initialPageSize);
setPageSize(getURLParameters().pageSize || initialPageSize);
setSortBy(getSortingSettingsFromURL());
gotoPage(getHashSearch().page - 1 || 0);
gotoPage(getURLParameters().page - 1 || 0);
});
}, [history, gotoPage, setPageSize, setSortBy]);

Expand Down
20 changes: 10 additions & 10 deletions benchexec/tablegenerator/react-table/src/components/ScatterPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
} from "react-vis";
import {
getRunSetName,
setParam,
getHashSearch,
setURLParameter,
getURLParameters,
isNil,
getFirstVisibles,
} from "../utils/utils";
Expand Down Expand Up @@ -98,7 +98,7 @@ export default class ScatterPlot extends React.Component {
let { results, scaling, toolX, toolY, columnX, columnY, line, regression } =
{
...this.defaultValues,
...getHashSearch(),
...getURLParameters(),
};

let dataX, dataY, areAllColsHidden;
Expand Down Expand Up @@ -221,7 +221,7 @@ export default class ScatterPlot extends React.Component {
const areSelectionsNumerical = this.checkForNumericalSelections();
if (isRegressionEnabled) {
if (this.lineCount === 0 || !areSelectionsNumerical) {
setParam({ regression: this.regressionOptions.none });
setURLParameter({ regression: this.regressionOptions.none });
} else {
const regressionDataArray = array.map((data) => [
parseFloat(data.x),
Expand Down Expand Up @@ -333,21 +333,21 @@ export default class ScatterPlot extends React.Component {
{renderSetting(
"Scaling",
this.state.scaling,
(ev) => setParam({ scaling: ev.target.value }),
(ev) => setURLParameter({ scaling: ev.target.value }),
this.scalingOptions,
)}
{renderSetting(
"Results",
this.state.results,
(ev) => setParam({ results: ev.target.value }),
(ev) => setURLParameter({ results: ev.target.value }),
this.resultsOptions,
"In addition to which results are selected here, any filters will still be applied.",
)}
<div className="settings-subcontainer">
{renderOptgroupsSetting(
"Aux. Lines",
this.state.line,
(ev) => setParam({ line: ev.target.value }),
(ev) => setURLParameter({ line: ev.target.value }),
this.lineOptgroupOptions,
"Adds the two auxiliary lines f(x) = cx and f(x) = x/c to the plot, with c being the chosen factor in the dropdown.",
)}
Expand All @@ -359,7 +359,7 @@ export default class ScatterPlot extends React.Component {
this.state.regression,
(ev) => {
if (this.checkForNumericalSelections()) {
setParam({ regression: ev.target.value });
setURLParameter({ regression: ev.target.value });
} else {
alert(
"Regressions are only available for numerical selections.",
Expand Down Expand Up @@ -494,12 +494,12 @@ export default class ScatterPlot extends React.Component {
this.array = [];
let [tool, column] = ev.target.value.split("-");
column = column.replace("___", "-");
setParam({ [`tool${axis}`]: tool, [`column${axis}`]: column });
setURLParameter({ [`tool${axis}`]: tool, [`column${axis}`]: column });
};

swapAxes = () => {
this.array = [];
setParam({
setURLParameter({
toolX: this.state.toolY,
toolY: this.state.toolX,
columnX: this.state.columnY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from "react";
import ReactModal from "react-modal";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faClose } from "@fortawesome/free-solid-svg-icons";
import { getRunSetName, setHashSearch } from "../utils/utils";
import { getRunSetName, setURLParameter } from "../utils/utils";

export default class SelectColumn extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -67,10 +67,7 @@ export default class SelectColumn extends React.Component {
hiddenParams["hidden"] = null;
}

setHashSearch(hiddenParams, {
keepOthers: true,
history: this.props.history,
});
setURLParameter(hiddenParams, this.props.history);
}

// -------------------------Rendering-------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from "react";
import QuantilePlot from "../components/QuantilePlot.js";
import Overview from "../components/Overview";
import renderer from "react-test-renderer";
import { setParam } from "../utils/utils";
import { setURLParameter } from "../utils/utils";
const fs = require("fs");

const testDir = "../test_integration/expected/";
Expand Down Expand Up @@ -65,25 +65,25 @@ files
);

describe("Quantile Plot should match HTML snapshot", () => {
setParam({ plot: plotInstance.plotOptions.quantile });
setURLParameter({ plot: plotInstance.plotOptions.quantile });

it.each(selectionResultInput)(
"with selection of the type %s and %s results",
(selection, results) => {
setParam({ selection: selection.value, results });
setURLParameter({ selection: selection.value, results });
plotInstance.refreshUrlState();
expect(plot).toMatchSnapshot();
},
);
});

describe("Direct Plot should match HTML snapshot", () => {
setParam({ plot: plotInstance.plotOptions.direct });
setURLParameter({ plot: plotInstance.plotOptions.direct });

it.each(selectionResultInput)(
"with selection of the type %s and %s results",
(selection, results) => {
setParam({ selection: selection.value, results });
setURLParameter({ selection: selection.value, results });
plotInstance.refreshUrlState();
expect(plot).toMatchSnapshot();
},
Expand All @@ -93,15 +93,15 @@ files
// Score based plot isn't available if the data doesn't support a scoring scheme
if (plotInstance.plotOptions.scoreBased) {
describe("Score-based Quantile Plot should match HTML snapshot (if it exists)", () => {
setParam({ plot: plotInstance.plotOptions.scoreBased });
setURLParameter({ plot: plotInstance.plotOptions.scoreBased });

// Only test with columns as runsets can't be selected for score-based plots
it.each(
selectionOptions.filter(
(selection) => selection.toString() !== "runset",
),
)("with selection of the type %s", (selection) => {
setParam({ selection: selection.value });
setURLParameter({ selection: selection.value });
plotInstance.refreshUrlState();
expect(plot).toMatchSnapshot();
});
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 { setParam } from "../utils/utils";
import { setURLParameter } from "../utils/utils";
const fs = require("fs");

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

function setUrlParams(params) {
setParam(params);
setURLParameter(params);
plotInstance.refreshUrlState();
}
Loading
Loading